| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- from flask import Flask, abort, render_template, request, session
- 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(name):
- try:
- name = request.args["playerName"]
- hand_size = request.args["handSize"]
- match_count = request.args["matchCount"]
- turn_count = request.args["turnCount"]
- except KeyError as e:
- return abort(400)
- game_id = None
- while game_id := randomword(4):
- for game in app.games:
- if game_id != game.id:
- 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
- @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)
|