def __init__(self, host, port): self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.sock.setblocking(False) self.sock.bind((str(host), int(port))) self.sock.listen(1) print 'Listening on %s' % ('%s:%s' % self.sock.getsockname()) self.game = gameplay.game() print 'Game created with id %s' % self.game.id self.acceptingConnections = True
def game_loop(): global mode, marker app = game(mode, marker) st = 5 cs = (display_width - (4 * st)) / 3 def update(a): if app.playing: if mode == 1: app.update(a[0], a[1]) else: app.ai_update(a[0], a[1]) def print_grid(): # creating spaces in lines to be buttons val = app.grid for i in range(3): for j in range(3): func.button(val[j][i], (st * (i + 1) + cs * i) * 2, (st * (j + 1) + cs * j) * 2, cs, cs, white, white, white, 80, update, (j, i)) # vertical pygame.draw.line(gameDisplay, (0, 0, 0), (cs + st, 0), (cs + st, cs * 3 + st * 3), st) pygame.draw.line(gameDisplay, (0, 0, 0), (cs * 2 + st * 3, 0), (cs * 2 + st * 3, cs * 3 + st * 3), st) # horizontal pygame.draw.line(gameDisplay, (0, 0, 0), (0, cs + st), (cs * 3 + st * 3, cs + st), st) pygame.draw.line(gameDisplay, (0, 0, 0), (0, cs * 2 + st * 3), (cs * 3 + st * 3, cs * 2 + st * 3), st) def get_status(): msg = app.stat func.message_display(msg, ((display_height - 200) / 2), 315, 30) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() gameDisplay.fill(white) print_grid() get_status() pygame.display.update() clock.tick(60)
def main(currgame): nowPlaying=arguments() commandCode=0 row, col, flag = None, None, None while commandCode!=40: commandCode, row, col, flag, height, width, mines = currgame.getCommand() if commandCode==0: if nowPlaying==True: res=currgame.playMove(row, col, flag) if res==0: currgame.printBoard() continue if res==-1: print "You Lost..." currgame.showOpenBoard() continue if res==1: print "You Won!" currgame.showOpenBoard() continue else: print "No games started yet." continue if commandCode==11: newgame=game() currgame=newgame if currgame.setNew(height, width, mines)==False: print "Invalid board specifications" nowPlaying=False continue currgame.printBoard() nowPlaying=True if commandCode==20: nowPlaying=False if commandCode==30: print commandsList if commandCode==-1: continue return 0
continue else: print "No games started yet." continue if commandCode==11: newgame=game() currgame=newgame if currgame.setNew(height, width, mines)==False: print "Invalid board specifications" nowPlaying=False continue currgame.printBoard() nowPlaying=True if commandCode==20: nowPlaying=False if commandCode==30: print commandsList if commandCode==-1: continue return 0 currgame=game() main(currgame) sys.exit(0)
import gameplay if __name__ == '__main__': gameplay.game()
def main(): model = pickle.load(open('gamemodel.mdl', 'rb')) game(model)
def createNewGame(self): """ Create a new instance of the Clue-Less game class. """ self.game = gameplay.game() print 'Game created with id %s' % self.game.id