cowiz20/views/control.py

59 lines
2.3 KiB
Python
Raw Permalink Normal View History

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-04-13 16:14:36 +02:00
current_round = the_game.current_round
hand_finished = the_game.is_hand_finished()
trick_finished = the_game.is_trick_finished()
2020-04-12 15:27:05 +02:00
2020-04-13 16:14:36 +02:00
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
)
2020-04-05 23:27:33 +02:00
2020-04-13 16:14:36 +02:00
@api.route("/control/next_hand/")
2020-04-19 17:14:25 +02:00
async def start_next_hand(req, resp):
2020-04-13 16:14:36 +02:00
the_game.next_hand()
2020-04-19 17:14:25 +02:00
for ws in the_game.websockets:
try:
await ws.send_text("reload")
except Exception as e:
print("ws: got {}".format(e))
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-04-19 17:14:25 +02:00
for ws in the_game.websockets:
try:
await ws.send_text("reload")
except Exception as e:
print("ws: got {}".format(e))
2020-04-13 16:14:36 +02:00
api.redirect(resp, '/control/', status_code=303)
2020-04-05 23:27:33 +02:00
2020-04-19 17:14:25 +02:00
#@api.route("/control/deal/{cards}")
#def deal(req, resp, cards):
# the_game.deal_cards(int(cards))
# api.redirect(resp, '/control/', status_code=303)