def stats(self, name): # Get player ID, return if not found pid = cPlayerHandler.getPID(self, name) if pid == -1: print "No such player found." return pData = cPlayerHandler.getData(self, pid) printf( "The player %s has played %i games, of which they have won %i and lost %i. They have quit %i times.\n", pData[0], pData[1], pData[2], pData[3], pData[4], )
def newGame(self): pid1, pid2 = 0, 0 while 1: mode = raw_input("Enter 1 for singleplayer, 2 for multiplayer: ") try: mode = int(mode) except ValueError: print "Please, enter 1 or 2" continue if mode == 1: pid1 = 0 while 1: pName = raw_input("Enter your name: ") if pName != "" and pName.lower() != "cpu": break else: print "Try again" pid2 = cPlayerHandler.getPID(self, pName) if pid2 == -1: print "No such player found. Creating.." pid2 = cPlayerHandler.addPlayer(self, pName) break elif mode == 2: while 1: p1name = raw_input("Player 1, enter your name: ") if p1name != "" and p1name.lower() != "cpu": break else: print "Try again" pid1 = cPlayerHandler.getPID(self, p1name) if pid1 == -1: print "No such player found. Creating.." pid1 = cPlayerHandler.addPlayer(self, p1name) while 1: p2name = raw_input("Player 2, enter your name: ") if p2name != "" and p2name.lower() != "cpu": break else: print "Try again" pid2 = cPlayerHandler.getPID(self, p2name) if pid2 == -1: print "No such player found. Creating.." pid2 = cPlayerHandler.addPlayer(self, p2name) break print "Please, enter 1 or 2" # If mode wasn't 1 or 2, loop again. sleep(0.5) # Why sleep? Because why not? status = cGame.__init__(self, pid1, pid2) # Start new game if status == -1 or status == 2: print "Game ended to a draw" elif status == 0 or status == 1: printf("%s won the game\n", cGame.getNames(self)[status])