Exemple #1
0
 def reset_players(result):
     """Resets Players to Lobby"""
     Players().collection.update_one(
         {"player_id": int(result["player_yellow"])},
         {'$set': {'status': 'IN_LOBBY'}})
     Players().collection.update_one(
         {"player_id": int(result["player_red"])},
         {'$set': {'status': 'IN_LOBBY'}})
Exemple #2
0
 def player_status_chk(player_id):
     """ Checks player Status to add to game """
     player_result = Players().get_one_player_id(float(player_id))
     if isinstance(player_result, dict):
         player_status = player_result['status']
         if player_status == "LOBBY":
             return player_id
         return {
             "message": f"Player {player_id} is not eligible to join"
         }, 400
     return {
         "message": f"Player {player_id} could not be found!"
     }, 400
Exemple #3
0
 def update_game_player(self, game_id, color, player_id):
     """ Assign Player Color with Player ID """
     game_result = self.collection.find_one({'game_id': int(game_id)},
                                            {'_id': 0})
     gstat = self.game_status_chk(color, game_id, game_result)
     pstat = self.player_status_chk(player_id)
     if pstat == player_id and gstat == game_id:
         self.collection.update_one({'game_id': int(game_id)},
                                    {'$set': {color: player_id}})
         Players().collection.update_one({'player_id': float(player_id)},
                                         {'$set': {"status": "IN_GAME"}}
                                         )
         gstat_changer = self.game_status_changer(game_id)
         return {
             'message':
                 f'Player {color} added [id={player_id}] {gstat_changer}'
         }, 200
     return {
         'game': f"{pstat}   {gstat}"
     }, 400
Exemple #4
0
 def put(self, username, password):
     ''' updates a player username and password ''' #do this separately?
     return Players().update_many(username, password, request.json)
Exemple #5
0
 def delete(self, username):
     ''' deletes a player by username '''
     return Players().delete_one(username)
Exemple #6
0
 def put(self, username):
     ''' updates a player's username via old username'''
     return Players().update_one(username, request.json)
Exemple #7
0
 def get(self, username):
     ''' gets a player by username '''
     return Players().get_one(username)
Exemple #8
0
 def post(self, display_name='displayName'):
     ''' adds a new player '''
     print(f'request={request.get_json()}')
     return Players().create_one(display_name, request.get_json())
Exemple #9
0
 def get(self, username):
     """gets state for username"""
     return Players().get_user_state(username)
Exemple #10
0
 def delete(self, display_name):
     ''' deletes a player by display name '''
     return Players().delete_one(display_name)
Exemple #11
0
 def post(self):
     """ Adds a new Player """
     return Players().create_one(request.get_json())
Exemple #12
0
 def put(self, player_id):
     """ Updates Player by player_id """
     return Players().update_one_by_id(player_id, request.json)
Exemple #13
0
 def get(self, player_id):
     """ Returns Player by Id number"""
     return Players().get_one_player_id(player_id)
Exemple #14
0
 def get(self):
     """ Returns List of Players """
     args = GET_PARSER.parse_args()
     return Players().get_all(args["status"])
Exemple #15
0
 def put(self, display_name):
     ''' updates a player by display name '''
     return Players().update_one(display_name, request.json)
Exemple #16
0
 def get(self, username):
     return Players().get_history(username)
Exemple #17
0
 def put(self, username):
     """ Updates a player with username """
     return Players().update_one(username, request.json)
Exemple #18
0
 def get(self):
     """ Returns list of Players """
     args = GET_PARSER.parse_args()
     print(f'args={args}')
     return Players().get_all(args['level'], args['state'])
Exemple #19
0
 def get(self, display_name):
     ''' get a player by display name'''
     return Players().get_one(display_name)
Exemple #20
0
 def get(self, username):
     """ Returns a player with username """
     return Players().get_one(username)
Exemple #21
0
 def get(self):
     ''' returns a list of all players '''
     args = GET_PARSER.parse_args()
     print(f'args={args}')
     return Players().get_all(args['state'])
Exemple #22
0
 def delete(self, username):
     """ Deletes a player with username """
     return Players().delete_one(username)
Exemple #23
0
 def post(self):
     ''' adds a new player '''
     print(f'request={request.get_json()}')
     return Players().create_one(request.get_json()) 
Exemple #24
0
 def put(self, username):
     """updates state of player"""
     return Players().update_one_state(username, request.json)
Exemple #25
0
 def get(self):
     ''' returns a list of all players '''
     return Players().get_all()