|
@@ -1,4 +1,12 @@
|
|
|
-from flask import Flask, abort, render_template, request, session
|
|
|
|
|
|
|
+from flask import (
|
|
|
|
|
+ Flask,
|
|
|
|
|
+ abort,
|
|
|
|
|
+ redirect,
|
|
|
|
|
+ render_template,
|
|
|
|
|
+ request,
|
|
|
|
|
+ session,
|
|
|
|
|
+ url_for,
|
|
|
|
|
+)
|
|
|
|
|
|
|
|
from game import Game, randomword
|
|
from game import Game, randomword
|
|
|
|
|
|
|
@@ -13,26 +21,27 @@ def home():
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/newgame")
|
|
@app.route("/newgame")
|
|
|
-def new_game(name):
|
|
|
|
|
|
|
+def new_game():
|
|
|
try:
|
|
try:
|
|
|
name = request.args["playerName"]
|
|
name = request.args["playerName"]
|
|
|
hand_size = request.args["handSize"]
|
|
hand_size = request.args["handSize"]
|
|
|
match_count = request.args["matchCount"]
|
|
match_count = request.args["matchCount"]
|
|
|
turn_count = request.args["turnCount"]
|
|
turn_count = request.args["turnCount"]
|
|
|
- except KeyError as e:
|
|
|
|
|
|
|
+ except (KeyError, TypeError) as e:
|
|
|
return abort(400)
|
|
return abort(400)
|
|
|
|
|
|
|
|
game_id = None
|
|
game_id = None
|
|
|
while game_id := randomword(4):
|
|
while game_id := randomword(4):
|
|
|
- for game in app.games:
|
|
|
|
|
- if game_id != game.id:
|
|
|
|
|
- break
|
|
|
|
|
|
|
+ if game_id not in [game.id for game in app.games]:
|
|
|
|
|
+ break
|
|
|
|
|
|
|
|
game = Game(name, hand_size, match_count, turn_count, game_id)
|
|
game = Game(name, hand_size, match_count, turn_count, game_id)
|
|
|
app.games.append(game)
|
|
app.games.append(game)
|
|
|
session["game_id"] = game.id
|
|
session["game_id"] = game.id
|
|
|
session["player_id"] = game.player1.id
|
|
session["player_id"] = game.player1.id
|
|
|
|
|
|
|
|
|
|
+ return redirect(url_for("game", game_id=game.id))
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@app.route("/game/<game_id>")
|
|
@app.route("/game/<game_id>")
|
|
|
def game(game_id):
|
|
def game(game_id):
|