def guessVal(username, gameName, level, guess, score, message): toPrint = "" gameInputs = gameInputs1() if level < len(gameInputs): if str(guess) == str(gameInputs[level]): toPrint += ">>>The guess was correct!" if level != 0: level += 1 else: toPrint += "\n<br>>>>Now you've completed the Tutorial round! Go back Home to get started playing." if level >= len(gameInputs): toPrint += "\n<br>>>>Congratulations! You won the game!" import EC_ProcessFile games = EC_ProcessFile.makeGameDict() if username in games and gameName in games[username]: games[username][gameName][ "score"] = games[username][gameName]["score"] + score EC_ProcessFile.writeGameDict(games) else: if score > (level + 1) * 25: score -= 25 #GUESSING PENALTY toPrint += ">>>Sorry, that guess was incorrect." toPrint = "<text style=color:#4CE8DD class=code>" + toPrint + "</text>" toPrint += "\n<br>" + message[ len("\n<br><text style=color:#4CE8DD class=code>") + 1:-len("</text>")] updateHTML(username, gameName, level, score, toPrint)
def saveGame(username, gameName, score, level): games = EC_ProcessFile.makeGameDict() proceed = True if username in games: if gameName in games[username]: proceed = True if not proceed: return "Username &/or save slot not recognized. Game could not be saved." games[username][gameName]["score"] = score games[username][gameName]["level"] = level if EC_ProcessFile.writeGameDict(games): return "Successfully saved progress!" else: return "Unable to save progress due to an error with the program."
def selectSlot(username,slotName): #return dictionary at the thing import EC_ProcessFile games = EC_ProcessFile.makeGameDict() if username not in games: games[username]={} if slotName in games[username]: return games[username][slotName] else: if slotName.split()==[]: return "No all-whitespace slot names allowed." for i in games[username].keys(): if i.split()==slotName.split(): return "There is already a slot with a very similar or identical name." games[username][slotName]={"username":username,"gameName":slotName,"level":0,"score":0.0} EC_ProcessFile.writeGameDict(games) return "Slot made!"
def updateHTML(mode,value,username): html="" try: f = open("slotPage.html","rU") html = f.read() f.close() import EC_ProcessFile games = EC_ProcessFile.makeGameDict() #print games[username] dropdown="<select name = slot>\n" for i in games.get(username,{}).keys(): if "gameName" in games[username][i]: dropdown+='''<br><option>%s</option>\n'''%(games[username][i]["gameName"]) dropdown+="</select>" html = html.replace("<!--SLOT SELECT-->","%s<!--SLOT SELECT-->"%(dropdown)) html =html.replace("<!--INPUT USERNAME-->","<input type = hidden name = username value =%s><!--INPUT USERNAME-->"%(username)) if mode.upper()=="REDIRECT": html=html.replace("<!--REDIRECT-->", ('<!--REDIRECT--><META http-equiv="refresh" '+ 'content="0;URL=EC_OpenSite.py?'+ 'username=%s&gameName=%s&level=%d">')%(value["username"],value["gameName"],value["level"])) else: if value!="": value='''<div class = error> <text class=signIn> %s </text> </div>'''%(value) else: value = "<text class=signIn>%s</text>"%(value) html=html.replace("<!--MESSAGE-->","%s<!--MESSAGE-->"%(value)) except: html= "<html><body>ERROR</body></html>" print html
def openHome(username): #print "Content-type: text/html" html = "" try: f = open("homePage.html", "rU") html = f.read() f.close() #print "hi" import EC_ProcessFile html = html.replace("<!--USERNAME-->", "<!--USERNAME-->%s" % (username)) html = html.replace( "<!--INPUT USERNAME-->", '<!--INPUT USERNAME--><input type=hidden name=username value="%s">' % (username)) #print "hi2" d = EC_ProcessFile.makeGameDict().get(username, {}) maxScore = 0.0 for i in d: if d[i]["score"] > maxScore: maxScore = d[i]["score"] html = html.replace("<!--TOTAL SCORE-->", "<!--TOTAL SCORE-->%.1f" % (maxScore)) except: html = "<html><body>ERROR</body></html>" print html
def signUp(username, password): import EC_ProcessFile users = EC_ProcessFile.makeUserDict() toReturn = "" if "," in username or "," in password: updateHTML(False, "No commas allowed in username or password.") return if username.split() == []: updateHTML(False, "Username cannot be made of only whitespace.") return for i in users: if users[i].get("username", "").lower().split() == username.lower().split(): updateHTML(False, "There's already a similar or identical username.") return EC_ProcessFile.addToUserFile(username, password) updateHTML(False, "Account created!")
def signIn(username, password): import EC_ProcessFile users = EC_ProcessFile.makeUserDict() for i in users: if users[i].get("username", "") == username and users[i].get( "password", "") == password: redirectHome(username) return updateHTML(True, "Username &/or password incorrect.")
def updateHTML(username, gameName, level, score, message): html = "" try: f = open("levelPage.html", "rU") html = f.read() f.close() import EC_ProcessFile html = html.replace("<!--GAMENAME-->", "<!--GAMENAME-->%s" % (gameName)) html = html.replace("<!--LEVEL-->", "<!--LEVEL-->%d" % (level)) html = html.replace("<!--SCORE-->", "<!--SCORE-->%.1f" % (float(score))) html = html.replace("<!--MESSAGE-->", "%s<!--MESSAGE-->" % (message)) html = html.replace("<!--USERNAME-->", "<!--USERNAME-->%s" % (username)) html = html.replace( "<!--INPUT GAMENAME-->", '<!--INPUT GAMENAME--><input type=hidden name=gameName value="%s">' % (gameName)) html = html.replace( "<!--INPUT LEVEL-->", "<!--INPUT LEVEL--><input type =hidden name = level value = %d>" % (level)) html = html.replace( "<!--INPUT SCORE-->", '<!--INPUT SCORE--><input type =hidden name = score value = %.1f>' % (float(score))) html = html.replace( "<!--INPUT USERNAME-->", '<!--INPUT USERNAME--><input type=hidden name=username value="%s">' % (username)) if level < len(gameInputs1()) and level < len(allLevels1()): html = html.replace( "<!--FUNCTION CODE-->", "%s<!--FUNCTION CODE-->" % (str( mainHelper(gameInputs1()[level], True, allLevels1()[level])))) html = html.replace( "<!--INPUT MESSAGE-->", ('<input type = hidden name = message value = "%s">' % (message)) ) #+html[html.find("<!--START MESSAGE-->")+len("<!--START MESSAGE-->"):html.find("<!--MESSAGE-->")]) #+ "<!--INPUT MESSAGE-->")) html = html.replace( "<!--TOTAL SCORE-->", "<!--TOTAL SCORE-->%.1f" % (float(EC_ProcessFile.makeGameDict().get(username, {}).get( gameName, {}).get("score", 0)))) except: print "" print html