def update_db_play_aCard(self, userId, cardId): update_rows( **{ "table_name": "gameStatus", "columns": { "starter": self.get_nextPlayer(userId), f'player{self.reversePlayerMappings[userId]}': cardId, }, "filters": { "roomId": self.roomId, } }) cards = self.cards.get(userId) cards.remove(cardId) if not cards: cards = None else: cards = [str(card) for card in cards] cards = ",".join(cards) update_rows( **{ "table_name": "roomStatus", "columns": { "cards": cards, }, "filters": { "roomId": self.roomId, "userId": userId, } })
def give_PlayerAPoint(self, userId): cursor = select_query( **{ "columns": ["points"], "filters": { "roomId": self.roomId, "userId": userId, }, "table_name": "roomStatus", }) point = cursor.fetchone() if not point: point = 0 else: point = point[0] try: point = int(point) except: point = 0 point += 1 update_rows( **{ "table_name": "roomStatus", "columns": { "points": point, }, "filters": { "userId": userId, "roomId": self.roomId, } })
def add_playersToGame(self, playerChosen): #team-mate as 3 update_rows( **{ "table_name": "roomStatus", "columns": { "roomUserId": 3, }, "filters": { "userId": playerChosen, "roomId": self.roomId, } }) players = self.players players.remove(playerChosen) players.remove(self.host) for i, userId in enumerate(players): update_rows( **{ "table_name": "roomStatus", "columns": { "roomUserId": 2 * i + 2, }, "filters": { "userId": userId, "roomId": self.roomId, } })
def update_teamScore(self, teamName, updatedScore): update_rows( **{ "table_name": "roomInfo", "columns": { teamName: updatedScore, }, "filters": { "roomId": self.roomId, } })
def update_gameSelector(self, userId): update_rows( **{ "table_name": "gameStatus", "columns": { "starter": userId, }, "filters": { "roomId": self.roomId, } })
def update_firstPlayer(self, userId): update_rows( **{ "table_name": "roomInfo", "columns": { "starter": userId, }, "filters": { "roomId": self.roomId, } })
def set_gameRoundEnded(self): update_rows( **{ "table_name": "roomInfo", "columns": { "roomState": "E", }, "filters": { "roomId": self.roomId, } })
def reset_PlayerPoint(self, userId): update_rows( **{ "table_name": "roomStatus", "columns": { "points": 0, }, "filters": { "userId": userId, "roomId": self.roomId, } })
def clear_gameType(self): """ clear gameType""" update_rows( **{ "table_name": "roomInfo", "columns": { "gameType": None, }, "filters": { "roomId": self.roomId, } })
def set_gameType(self, gameType): update_rows( **{ "table_name": "roomInfo", "columns": { "gameType": gameType, }, "filters": { "roomId": self.roomId, } }) self.gameType = gameType
def drop_game(self): update_rows( **{ "table_name": "roomInfo", "columns": { "roomState": "C", "gameType": None, }, "filters": { "roomId": self.roomId, } }) self.update_gameSelector(self.get_previousPlayer(self.currentPlayer)) self.update_firstPlayer(self.get_previousPlayer(self.currentPlayer))
def clear_db_play_aCard(self, userId): """round is finished and winner is added, and other columns are cleared""" update_rows( **{ "table_name": "gameStatus", "columns": { "starter": userId, "player1": None, "player2": None, "player3": None, "player4": None, }, "filters": { "roomId": self.roomId, } })
def distribute_cards(self): card = Card() card.shuffle_allCards() cardsForPlayers = card.distribute_cards() for i, cards in enumerate(cardsForPlayers): cards = [str(card) for card in cards] update_rows( **{ "table_name": "roomStatus", "columns": { "cards": ",".join(cards), }, "filters": { "roomUserId": i + 1, "roomId": self.roomId, } })
def send_otp(user_info): current_app.logger.info(f'sending OTP to {user_info["emailId"]}') otp = generate_otp() body = f"""access code: {otp} """ title = "verify account" state, message = send_text_email(user_info["emailId"], title, body) if state: if not update_rows( **{ "table_name": "tempUsers", "userId": user_info["userId"], "columns": { "otp": otp, }, "filters": { "emailId": user_info["emailId"], } }): raise Exception("failed to store OTP") else: raise Exception("failed to send OTP through email")