2020-04-05 23:27:33 +02:00
|
|
|
from app_instance import api
|
|
|
|
|
|
|
|
from wiz_game import the_game
|
|
|
|
|
|
|
|
|
|
|
|
@api.route("/control/")
|
|
|
|
def index(req, resp):
|
2020-10-11 18:10:05 +02:00
|
|
|
round_finished = the_game.is_round_finished()
|
2020-04-13 16:14:36 +02:00
|
|
|
trick_finished = the_game.is_trick_finished()
|
2020-04-12 15:27:05 +02:00
|
|
|
|
2020-10-11 18:10:05 +02:00
|
|
|
if round_finished:
|
2020-04-13 16:14:36 +02:00
|
|
|
trick_winner, highest_card = the_game.get_trick_winner()
|
|
|
|
winner = trick_winner.name
|
|
|
|
resp.content = api.template('home/control.html', deck=the_game.card_deck,
|
|
|
|
trump_card=the_game.trump_card, trump_color=the_game.get_trump_color(),
|
2020-10-11 18:10:05 +02:00
|
|
|
round_finished=True, trick_finished=False, trick_winner=winner,
|
2020-04-13 16:14:36 +02:00
|
|
|
highest_card=highest_card
|
|
|
|
)
|
|
|
|
elif trick_finished:
|
|
|
|
trick_winner, highest_card = the_game.get_trick_winner()
|
|
|
|
winner = trick_winner.name
|
|
|
|
resp.content = api.template('home/control.html', deck=the_game.card_deck,
|
|
|
|
trump_card=the_game.trump_card, trump_color=the_game.get_trump_color(),
|
|
|
|
round_finished=False, trick_finished=True, trick_winner=winner,
|
|
|
|
highest_card=highest_card
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
resp.content = api.template('home/control.html', deck=the_game.card_deck,
|
|
|
|
trump_card=the_game.trump_card, trump_color=the_game.get_trump_color(),
|
|
|
|
round_finished=False, trick_finished=False
|
|
|
|
)
|
2020-04-05 23:27:33 +02:00
|
|
|
|
2020-10-11 18:10:05 +02:00
|
|
|
@api.route("/control/next_round/")
|
|
|
|
async def start_next_round(req, resp):
|
|
|
|
the_game.next_round()
|
2020-05-21 19:54:39 +02:00
|
|
|
await the_game.send_page_reload()
|
2020-04-13 16:14:36 +02:00
|
|
|
api.redirect(resp, '/control/', status_code=303)
|
|
|
|
|
2020-04-19 17:14:25 +02:00
|
|
|
|
2020-04-13 16:14:36 +02:00
|
|
|
@api.route("/control/next_trick/")
|
2020-04-19 17:14:25 +02:00
|
|
|
async def start_next_trick(req, resp):
|
2020-04-13 16:14:36 +02:00
|
|
|
the_game.next_trick()
|
2020-05-21 19:54:39 +02:00
|
|
|
await the_game.send_page_reload()
|
2020-04-13 16:14:36 +02:00
|
|
|
api.redirect(resp, '/control/', status_code=303)
|
2020-04-05 23:27:33 +02:00
|
|
|
|
2020-05-21 18:49:52 +02:00
|
|
|
|
|
|
|
@api.route("/control/undo_last/")
|
|
|
|
async def undo_last(req, resp):
|
2020-10-11 18:10:05 +02:00
|
|
|
round_finished = the_game.is_round_finished()
|
2020-05-21 18:49:52 +02:00
|
|
|
if the_game.played_cards:
|
2020-10-11 18:10:05 +02:00
|
|
|
if not round_finished:
|
2020-05-21 18:49:52 +02:00
|
|
|
p, c = the_game.played_cards.pop()
|
|
|
|
the_game.active_player -= 1
|
|
|
|
p.add_card(c)
|
2020-05-21 19:54:39 +02:00
|
|
|
await the_game.send_page_reload()
|
2020-05-21 18:49:52 +02:00
|
|
|
else:
|
|
|
|
if the_game.num_tricks_played > 0:
|
|
|
|
the_game.num_tricks_played -= 1;
|
|
|
|
the_game.played_cards = the_game.last_trick;
|
|
|
|
the_game.active_player = len(the_game.players) - 1
|
|
|
|
player, _ = the_game.get_trick_winner()
|
|
|
|
player.tricks_taken -= 1
|
|
|
|
the_game.players_ordered = [p for p, _ in the_game.played_cards]
|
|
|
|
p, c = the_game.played_cards.pop()
|
|
|
|
p.add_card(c)
|
2020-05-21 19:54:39 +02:00
|
|
|
await the_game.send_page_reload()
|
2020-05-21 18:49:52 +02:00
|
|
|
|
|
|
|
api.redirect(resp, '/control/', status_code=303)
|
2020-05-21 19:54:39 +02:00
|
|
|
|