예제 #1
0
 def get(self):
     ingame = GameModel.check_if_in_game(current_identity.username)
     if ingame != None:
         return {
             "board": ingame.boardTiles,
             "active": ingame.gameopen,
             "player1": ingame.player1,
             "player2": ingame.player2,
             "status": ingame.gameStatus
         }
     return GameModel.find_game(current_identity.username)
예제 #2
0
 def get(self):
     ingame = GameModel.check_if_in_game(current_identity.username)
     if ingame == None:
         ingame = GameModel(current_identity.username, "solo", "CPU")
         return ingame.create_game(current_identity.username, False)
     return {
         "board": ingame.boardTiles,
         "active": ingame.gameopen,
         "player1": ingame.player1,
         "player2": ingame.player2,
         "status": ingame.gameStatus
     }
예제 #3
0
 def put(self):
     data = PlayerMove.parser.parse_args()
     ingame = GameModel.check_if_in_game(current_identity.username)
     user = UserModel.find_by_username(ingame.player1)
     user2 = UserModel.find_by_username(ingame.player2)
     if ingame.make_move(data['move'], current_identity.username):
         game = ingame.check_game_status()
         if game["open"] == True:
             if ingame.pvp == False:
                 if ingame.cpu_move():
                     game = ingame.check_game_status()
                     if game["open"] == False:
                         if game["status"] == current_identity.username:
                             user.save_win()
                         elif game["status"] == "Tie":
                             user.save_tie()
                         else:
                             user.save_lose()
         else:
             if game["status"] == current_identity.username:
                 user.save_win()
                 if ingame.pvp == True:
                     user2.save_lose()
             elif game["status"] == "Tie":
                 user.save_tie()
                 if ingame.pvp == True:
                     user2.save_tie()
             else:
                 user.save_lose()
                 if ingame.pvp == True:
                     user2.save_win()
     ingame = GameModel.check_if_in_game(current_identity.username)
     return {
         "board": ingame.boardTiles,
         "status": ingame.gameStatus,
         "active": ingame.gameopen,
         "player1": ingame.player1,
         "player2": ingame.player2
     }
예제 #4
0
 def get(self):
     ingame = GameModel.check_if_in_game(current_identity.username)
     user = UserModel.find_by_username(current_identity.username)
     if ingame != None:
         return {
             "message": "User in Game",
             "status": ingame.gameStatus,
             "active": ingame.gameopen,
             "board": ingame.boardTiles,
             "record": user.userRecord(),
             "player1": ingame.player1,
             "player2": ingame.player2
         }
     return {"message": "Not in Game"}
예제 #5
0
 def delete(self):
     info = GameModel.check_if_in_game(current_identity.username)
     if info != None:
         GameModel.leave_game(current_identity.username)
         return {'message': "You have left the game"}
     return {"message": "Not in game"}