implemented 'table'
This commit is contained in:
parent
4fa38fabef
commit
989b9bdbf9
@ -26,6 +26,7 @@
|
|||||||
<a href="/control/deal/5">deal 5</a>
|
<a href="/control/deal/5">deal 5</a>
|
||||||
<a href="/control/deal/10">deal 10</a>
|
<a href="/control/deal/10">deal 10</a>
|
||||||
<a href="/control/deal/12">deal 12</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>
|
<a href="/control/deal/20">deal 20</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -7,18 +7,23 @@
|
|||||||
<p class="lead">
|
<p class="lead">
|
||||||
Play a nice game of cards?<br>
|
Play a nice game of cards?<br>
|
||||||
<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>
|
<ul>
|
||||||
{% for card in cards %}
|
|
||||||
<li>
|
|
||||||
<strong>>card {{loop.index}} is: {{card}} </strong><br>
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<strong>Trump Card: {{trump_card}}</strong><br>
|
<strong>Trump Card: {{trump_card}}</strong><br>
|
||||||
<strong>Trump Color: {{trump_color}}</strong><br>
|
<strong>Trump Color: {{trump_color}}</strong><br>
|
||||||
</li>
|
</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}}<{{card}}></a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
<!--
|
<!--
|
||||||
<li>
|
<li>
|
||||||
<strong>Movie by IMDB code</strong><br>
|
<strong>Movie by IMDB code</strong><br>
|
||||||
|
@ -8,4 +8,20 @@ def index(req, resp, player: str):
|
|||||||
p = int(player)
|
p = int(player)
|
||||||
tcard = the_game.trump_card
|
tcard = the_game.trump_card
|
||||||
tcolor = the_game.get_trump_color()
|
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)
|
||||||
|
|
||||||
|
29
wiz_game.py
29
wiz_game.py
@ -22,11 +22,24 @@ class Card:
|
|||||||
return str(self)
|
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:
|
class Player:
|
||||||
def __init__(self, name, player_id):
|
def __init__(self, name, player_id):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.id = player_id
|
self.id = player_id
|
||||||
self.cards = []
|
self.cards = []
|
||||||
|
#self.played_card = None
|
||||||
|
|
||||||
def set_cards(self, cards):
|
def set_cards(self, cards):
|
||||||
self.cards = sorted(cards, key=attrgetter('color', 'value'))
|
self.cards = sorted(cards, key=attrgetter('color', 'value'))
|
||||||
@ -34,12 +47,25 @@ class Player:
|
|||||||
def show_cards(self):
|
def show_cards(self):
|
||||||
print(self.cards)
|
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:
|
class WizGame:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.players = []
|
self.players = []
|
||||||
self.card_deck = []
|
self.card_deck = []
|
||||||
self.trump_card = None
|
self.trump_card = None
|
||||||
|
self.table = Table()
|
||||||
|
|
||||||
def create_deck(self):
|
def create_deck(self):
|
||||||
for color in ["b", "r", "g", "y"]:
|
for color in ["b", "r", "g", "y"]:
|
||||||
@ -83,6 +109,9 @@ class WizGame:
|
|||||||
if len(self.players) < 6:
|
if len(self.players) < 6:
|
||||||
self.players.append((Player(name, player_id)))
|
self.players.append((Player(name, player_id)))
|
||||||
|
|
||||||
|
def start_game(self):
|
||||||
|
self.table.num_players = len(self.players)
|
||||||
|
|
||||||
|
|
||||||
the_game = WizGame()
|
the_game = WizGame()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user