implemented 'table'

This commit is contained in:
Stefan Rupp 2020-04-06 22:42:31 +02:00
parent 4fa38fabef
commit 989b9bdbf9
4 changed files with 60 additions and 9 deletions

View File

@ -26,6 +26,7 @@
<a href="/control/deal/5">deal 5</a>
<a href="/control/deal/10">deal 10</a>
<a href="/control/deal/12">deal 12</a>
<a href="/control/deal/14">deal 14</a>
<a href="/control/deal/20">deal 20</a>
</li>
</ul>

View File

@ -7,18 +7,23 @@
<p class="lead">
Play a nice game of cards?<br>
<br>
<strong>Player {{player}} view</strong>
<strong>Player {{player}} view</strong><br>
<strong> Table </strong><br>
{{played_cards}}
<br>
<strong> Your cards: </strong>
<ul>
{% for card in cards %}
<li>
<strong>>card {{loop.index}} is: {{card}} </strong><br>
</li>
{% endfor %}
<li>
<strong>Trump Card: {{trump_card}}</strong><br>
<strong>Trump Color: {{trump_color}}</strong><br>
</li>
{% for card in cards %}
<li>
<strong>>card {{loop.index}} is: {{card}} </strong><br>
<a href="/player/{{player}}/play/{{loop.index0}}">play card {{loop.index}}&lt;{{card}}&gt;</a>
</li>
{% endfor %}
<!--
<li>
<strong>Movie by IMDB code</strong><br>

View File

@ -8,4 +8,20 @@ def index(req, resp, player: str):
p = int(player)
tcard = the_game.trump_card
tcolor = the_game.get_trump_color()
resp.content = api.template('home/player.html', player=player, cards=the_game.players[p].cards, trump_card=tcard, trump_color=tcolor)
table = the_game.table
resp.content = api.template('home/player.html', player=player, cards=the_game.players[p].cards,
trump_card=tcard, trump_color=tcolor, played_cards=table.played_cards)
@api.route("/player/{player}/play/{card}")
def play(req, resp, player: str, card: str):
p = int(player)
pl = the_game.players[p]
c = pl.play_card(int(card))
the_game.table.play_card(p, c)
tcard = the_game.trump_card
tcolor = the_game.get_trump_color()
table = the_game.table
resp.content = api.template('home/player.html', player=player, cards=the_game.players[p].cards,
trump_card=tcard, trump_color=tcolor, played_cards=table.played_cards)

View File

@ -22,11 +22,24 @@ class Card:
return str(self)
class Table:
def __init__(self):
self.played_cards = {0: None, 1: None, 2: None, 3: None, 4: None, 5: None}
self.num_players = 0
self.trump_card = None
def clear_table(self):
self.played_cards = {0: None, 1: None, 2: None, 3: None, 4: None, 5: None}
def play_card(self, player: int, card: Card):
self.played_cards[player] = card
class Player:
def __init__(self, name, player_id):
self.name = name
self.id = player_id
self.cards = []
#self.played_card = None
def set_cards(self, cards):
self.cards = sorted(cards, key=attrgetter('color', 'value'))
@ -34,12 +47,25 @@ class Player:
def show_cards(self):
print(self.cards)
def play_card(self, card_idx):
c = self.cards[card_idx]
self.cards.remove(c)
return c
#def play_card(self, card: Card):
# self.cards.remove(card)
# self.played_card = card
#def reset_played_card(self):
# self.played_card = None
class WizGame:
def __init__(self):
self.players = []
self.card_deck = []
self.trump_card = None
self.table = Table()
def create_deck(self):
for color in ["b", "r", "g", "y"]:
@ -83,6 +109,9 @@ class WizGame:
if len(self.players) < 6:
self.players.append((Player(name, player_id)))
def start_game(self):
self.table.num_players = len(self.players)
the_game = WizGame()