| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- from flask import (
- Flask,
- abort,
- redirect,
- render_template,
- request,
- session,
- url_for,
- )
- from game import Game, randomword
- app = Flask(__name__)
- app.secret_key = "somebullshit"
- app.games = []
- @app.route("/")
- def home():
- return render_template("home.html")
- @app.route("/newgame")
- def new_game():
- try:
- name = request.args["playerName"]
- hand_size = request.args["handSize"]
- match_count = request.args["matchCount"]
- turn_count = request.args["turnCount"]
- except (KeyError, TypeError) as e:
- return abort(400)
- game_id = None
- while game_id := randomword(4):
- if game_id not in [game.id for game in app.games]:
- break
- game = Game(name, hand_size, match_count, turn_count, game_id)
- app.games.append(game)
- session["game_id"] = game.id
- session["player_id"] = game.player1.id
- return redirect(url_for("game", game_id=game.id))
- @app.route("/game/<game_id>")
- def game(game_id):
- return render_template("game.html", game_id=game_id)
- if __name__ == "__main__":
- app.run(debug=True)
|