while 1: # enqueue the player events received by the client handlers poll() # apply events onto game state for event, handler in event_queue: if event == 'quit': if handler in gameclients.keys(): gamename = gameclients[handler] #if a player remove returns true, game is empty, end it if games[gamename].remove_player(clients[handler]): #remove button from game lobby.remove_game(gamename) del games[gamename] else: #update other's boards to reflect missing player msg = {'type':'update', 'board':{'players':games[gamename].getasdict('players')}, 'state':games[gamename]._started} broadcastGame(gamename, msg, handler) #delete game from game clients del gameclients[handler] if handler in lobbyclients: lobbyclients.remove(handler) del clients[handler] elif event == 'join':
def gameInit(): pygame.init() global TURN TURN = 0 global GAMECLOCK GAMECLOCK = pygame.time.Clock() global FRAMERATE FRAMERATE = 40 """ Program State overview: 0 = loading 1 = main screen 2 = game 3 = game lobby 4 = online game """ global PROG_STATE PROG_STATE = 0 global VIEWPORT VIEWPORT = FixedViewport(900, 600) global LOBBY LOBBY = Lobby(900,600) global GAMEBOARD GAMEBOARD = Board(VIEWPORT.width, VIEWPORT.height, 4, 4, 5) value1 = LOBBY.add_game() value2 = LOBBY.add_game() value3 = LOBBY.add_game() value4 = LOBBY.add_game() value5 = LOBBY.add_game() value6 = LOBBY.add_game() value7 = LOBBY.add_game() value8 = LOBBY.add_game() value9 = LOBBY.add_game() value10 = LOBBY.add_game() LOBBY.remove_game(value1) value11 = LOBBY.add_game() # value12 = LOBBY.add_game() # player_one = Player("Katie", (255,0,0)) # GAMEBOARD.add_player(player_one) # player_two = Player("Justin", (0,255,0)) # GAMEBOARD.add_player(player_two) # player_three = Player("Chris", (0,0,255)) # GAMEBOARD.add_player(player_three) #player_four = Player("Sufana", (100,100,100)) #GAMEBOARD.add_player(player_four) #player_five = Player("Shibani", (200,200,200)) #GAMEBOARD.add_player(player_five) global GAME_STATE GAME_STATE = 1;