def post(self): user = users.get_current_user() access_link = users.create_logout_url("/") id = int(self.request.get("id")) game = Games.get_by_id(id) template_values = { "user": user.nickname(), "access_link": access_link, "msg": "You can't modify a game added by other user." } game.code = self.request.get("code") game.name = self.request.get("name") game.type = self.request.get("type") game.platform = self.request.get("platform") if game and user.email() == game.user_email or user.email() == "*****@*****.**": game_mgt.update(game) jinja = jinja2.get_jinja2(app=self.app) self.response.write(jinja.render_template("confirm.html", **template_values)) else: jinja = jinja2.get_jinja2(app=self.app) self.response.write(jinja.render_template("error.html", **template_values))
def player_interact_roll(game_id: str, player_id: str): """ Given player tried to roll the dice """ try: game = Game(**games.get(where('uuid') == game_id)) game.roll(player_id) except Exception as err: return {"error": str(err)}, 404 games.update(game.dict(), where('uuid') == game_id) return {}
def delete_player(game_id, player_id): """ Delete a player from a game! """ try: game = Game(**games.get(where('uuid') == game_id)) except Exception as err: return {"error": str(err)}, 404 game.remove_player(player_id) games.update(game.dict(), where('uuid') == game_id) return {}
def player_interact_end_turn(game_id: str, player_id: str): """ Given player ends their turn """ try: game = Game(**games.get(where('uuid') == game_id)) game.advance_turn() except Exception as err: print(err) return {"error": str(err)}, 404 games.update(game.dict(), where('uuid') == game_id) return {}
def player_interact_make_choice(game_id: str, player_id: str, choice_idx: int): """ Given player makes a choice from given list """ try: game = Game(**games.get(where('uuid') == game_id)) game.make_choice(player_id, choice_idx) except Exception as err: print(err) return {"error": str(err)}, 404 games.update(game.dict(), where('uuid') == game_id) return {}
def start_game(game_id): """ Start game! """ try: game = Game(**games.get(where('uuid') == game_id)) except Exception as err: return {"error": err}, 404 status, error = game.start() if status is False: return {"error": error}, 400 games.update(game.dict(), where('uuid') == game_id) return {}
def new_player(game_id, name: str): """ Make a new player in a game! """ try: game = Game(**games.get(where('uuid') == game_id)) except Exception as err: return {"error": err}, 404 if len(game.players) >= MAX_PLAYER_COUNT: return {"error": "The game is full"}, 404 player = game.new_player(name) games.update(game.dict(), where('uuid') == game_id) return player.dict()
def post(self): user = users.get_current_user() access_link = users.create_logout_url("/") template_values = {"user": user.nickname(), "access_link": access_link} game = game_mgt.create_empty_game() game.code = self.request.get("code") game.name = self.request.get("name") game.user_email = user.email() game.type = self.request.get("type") game.platform = self.request.get("platform") if game: game_mgt.update(game) jinja = jinja2.get_jinja2(app=self.app) self.response.write( jinja.render_template("confirm.html", **template_values)) else: jinja = jinja2.get_jinja2(app=self.app) self.response.write( jinja.render_template("error.html", **template_values))