|
@@ -52,12 +52,16 @@ def create_game():
|
|
|
if not isinstance(gen_method, str):
|
|
|
abort(400)
|
|
|
|
|
|
+ rule_set = js.get("ruleSet", "NORMAL")
|
|
|
+ if not isinstance(rule_set, str):
|
|
|
+ abort(400)
|
|
|
+
|
|
|
src = sources.get((gen_method, only_america), None)
|
|
|
if src is None:
|
|
|
abort(400)
|
|
|
|
|
|
coords = src.get_points(n=rounds)
|
|
|
- new_game = db.Game.create(timer, rounds, only_america, gen_method, coords)
|
|
|
+ new_game = db.Game.create(timer, rounds, only_america, gen_method, rule_set, coords)
|
|
|
|
|
|
return jsonify({"gameId": new_game.game_id})
|
|
|
|
|
@@ -70,6 +74,7 @@ def game_config(game_id):
|
|
|
"rounds": g.rounds,
|
|
|
"onlyAmerica": g.only_america,
|
|
|
"generationMethod": g.gen_method,
|
|
|
+ "ruleSet": g.rule_set,
|
|
|
})
|
|
|
|
|
|
|
|
@@ -160,15 +165,22 @@ def current_round(game_id):
|
|
|
"lat": lookup.latitude,
|
|
|
"lng": lookup.longitude,
|
|
|
}
|
|
|
+ if g.rule_set == "TIMEBANK":
|
|
|
+ timer = player.get_last_round_time_remaining()
|
|
|
+ if timer is None:
|
|
|
+ timer = g.timer * g.rounds
|
|
|
+ else:
|
|
|
+ timer = g.timer
|
|
|
return jsonify({
|
|
|
"currentRound": cur_rnd,
|
|
|
"coord": coord,
|
|
|
- "timer": g.timer,
|
|
|
+ "timer": int(timer),
|
|
|
})
|
|
|
|
|
|
|
|
|
@game.route("/<game_id>/guesses/<int:round_num>", methods=["POST"])
|
|
|
def make_guess(game_id, round_num):
|
|
|
+ g = require_game(game_id)
|
|
|
player = require_player(game_id)
|
|
|
if round_num != player.get_current_round():
|
|
|
abort(409)
|
|
@@ -180,6 +192,8 @@ def make_guess(game_id, round_num):
|
|
|
timed_out = js.get("timeout", False)
|
|
|
if timed_out:
|
|
|
player.add_timeout(round_num)
|
|
|
+ if g.rule_set == "TIMEBANK":
|
|
|
+ player.timeout_remaining_rounds()
|
|
|
db.session.commit()
|
|
|
return jsonify({
|
|
|
"score": 0,
|
|
@@ -200,6 +214,10 @@ def make_guess(game_id, round_num):
|
|
|
|
|
|
guess_score, distance = lib.score((target.latitude, target.longitude), (lat, lng))
|
|
|
player.add_guess(round_num, lat, lng, guess_score, remaining)
|
|
|
+
|
|
|
+ if remaining <= 0 and g.rule_set == "TIMEBANK":
|
|
|
+ player.timeout_remaining_rounds()
|
|
|
+
|
|
|
return jsonify({
|
|
|
"score": guess_score,
|
|
|
"totalScore": player.get_total_score(),
|