def to_form(self, message): """Returns a GameForm representation of the Game""" from utils import get_player_by_game # get players player1 = get_player_by_game(self.player_names[0], self) player2 = get_player_by_game(self.player_names[1], self) form = GameForm() form.started_on = self.started_on form.urlsafe_key = self.key.urlsafe() form.player1 = player1.name form.player1_hand = str(player1.hand) form.player1_matches = player1.num_matches form.player2 = player2.name form.player2_hand = str(player2.hand) form.player2_matches = player2.num_matches form.game_over = self.game_over form.matches_to_win = self.matches_to_win if not self.game_over: form.turn = self.turn else: form.winner = self.winner form.message = message return form
def to_form(self, game, message=""): """Returns a GameForm representation of the Game""" form = GameForm(urlsafe_key=game.key.urlsafe(), board = str(game.board), next_move=game.next_move.get().name, game_over=game.game_over, message=message, history=str(game.history), first_user_score=game.first_user_score, second_user_score=game.second_user_score, unmatched_pairs=game.unmatched_pairs) if game.winner: form.winner = game.winner.get().name return form
def to_form(self): """Returns a GameForm representation of the Game""" form = GameForm(urlsafe_key = self.key.urlsafe(), board = str(self.board), boardSize = self.boardSize, player_x = self.player_x.get().name, player_o = self.player_o.get().name, nextMove = self.nextMove.get().name, game_over = self.game_over ) if self.winner: # send winner to Game form and get winner's name form.winner = self.winner.get().name if self.draw: form.draw = self.draw return form