last trick is now visible

This commit is contained in:
Stefan Rupp 2020-04-25 22:00:23 +02:00
parent 72e968274b
commit dc87897b77
3 changed files with 36 additions and 1 deletions

View File

@ -15,6 +15,22 @@
{% endfor %}
||
<br>
<sub>
<strong>Tricks:</strong>
{% for player,_ in last_trick %}
||
{{player.name}}: {{player.tricks_taken}}
{% endfor %}
||
<br>
<strong>Last Trick:</strong>
{% for player,card in last_trick %}
||
{{player.name}}: {{card}}
{% endfor %}
||
</sub>
<br>
<strong> Your cards: </strong>
<ul>
<li>

View File

@ -26,7 +26,7 @@ def show(req, resp, player: str):
choose_trump_color = False
resp.content = api.template('home/player.html', player=p, playerActive=isActive, choose_trump_player=prev_player,
cards=the_game.players[p].cards, choose_trump_color=choose_trump_color,
trump_card=tcard, trump_color=tcolor, played_cards=the_game.played_cards)
trump_card=tcard, trump_color=tcolor, played_cards=the_game.played_cards, last_trick=the_game.last_trick)
@api.route("/player/{player}/play/{card}")
@ -34,6 +34,17 @@ async def play(req, resp, player: str, card: str):
p = int(player)
c = int(card)
the_game.play_card(p, c)
if the_game.is_hand_finished():
print("hand finished")
trick_winner, highest_card = the_game.get_trick_winner()
trick_winner.take_trick()
#the_game.next_hand()
elif the_game.is_trick_finished():
print("trick finished")
trick_winner, highest_card = the_game.get_trick_winner()
trick_winner.take_trick()
the_game.next_trick()
url = '/player/'+player
for ws in the_game.websockets:
try:

View File

@ -58,15 +58,20 @@ class Player:
self.name = name
self.id = player_id
self.cards = []
self.tricks_taken = 0
def set_cards(self, cards):
self.cards = sorted(cards, key=attrgetter('color', 'value'))
self.tricks_taken = 0
def play_card(self, card_idx):
c = self.cards[card_idx]
self.cards.remove(c)
return c
def take_trick(self):
self.tricks_taken += 1
class WizGame:
def __init__(self, player_names: list):
@ -81,6 +86,7 @@ class WizGame:
self.num_tricks_played = 0
self.played_cards = list()
self.players_ordered = self.players
self.last_trick = None
self.websockets = []
def start_game(self):
@ -91,6 +97,7 @@ class WizGame:
self.deal_cards(1)
self.played_cards = list()
self.players_ordered = self.players
self.last_trick = [('-', '-')]*len(self.players)
self.websockets = []
def create_deck(self):
@ -167,6 +174,7 @@ class WizGame:
return False
def next_trick(self):
self.last_trick = self.played_cards.copy()
win = self.get_trick_winner()
winner = win[0]
starter = winner.id