54 lines
2.1 KiB
Python
54 lines
2.1 KiB
Python
from app_instance import api
|
|
|
|
from wiz_game import the_game
|
|
|
|
|
|
@api.route("/control/")
|
|
def index(req, resp):
|
|
hand_finished = the_game.is_hand_finished()
|
|
trick_finished = the_game.is_trick_finished()
|
|
|
|
if hand_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(),
|
|
hand_finished=True, trick_finished=False, trick_winner=winner,
|
|
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
|
|
)
|
|
|
|
@api.route("/control/next_hand/")
|
|
async def start_next_hand(req, resp):
|
|
the_game.next_hand()
|
|
for ws in the_game.websockets:
|
|
try:
|
|
await ws.send_text("reload")
|
|
except Exception as e:
|
|
pass
|
|
api.redirect(resp, '/control/', status_code=303)
|
|
|
|
|
|
@api.route("/control/next_trick/")
|
|
async def start_next_trick(req, resp):
|
|
the_game.next_trick()
|
|
for ws in the_game.websockets:
|
|
try:
|
|
await ws.send_text("reload")
|
|
except Exception as e:
|
|
pass
|
|
api.redirect(resp, '/control/', status_code=303)
|
|
|