added control view
This commit is contained in:
parent
914e9a1f3d
commit
129e676335
@ -8,5 +8,7 @@ from views.home import *
|
||||
from views.temp_css import *
|
||||
# noinspection PyUnresolvedReferences
|
||||
from views.player import *
|
||||
# noinspection PyUnresolvedReferences
|
||||
from views.control import *
|
||||
|
||||
api.add_route("/static", static=True)
|
||||
|
@ -16,8 +16,8 @@ def main():
|
||||
wiz_game.the_game.add_player("p1", 1)
|
||||
wiz_game.the_game.add_player("p2", 2)
|
||||
wiz_game.the_game.add_player("p3", 3)
|
||||
wiz_game.the_game.add_player("p4", 4)
|
||||
wiz_game.the_game.deal_cards(4)
|
||||
#wiz_game.the_game.add_player("p4", 4)
|
||||
wiz_game.the_game.deal_cards(12)
|
||||
|
||||
api.run(port=19203, address="127.0.0.1")
|
||||
exit(0)
|
||||
|
44
templates/home/control.html
Normal file
44
templates/home/control.html
Normal file
@ -0,0 +1,44 @@
|
||||
{% extends "/shared/_layout.html" %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="content">
|
||||
<h1><span class="font-semi-bold">Gambling Foo</span> <span class="smaller">A RESTful gaming service</span></h1>
|
||||
<p class="lead">
|
||||
Play a nice game of cards?<br>
|
||||
<br>
|
||||
<strong>Control view</strong>
|
||||
<br>
|
||||
|
|
||||
{% for card in deck %}
|
||||
<strong>>{{loop.index}}: {{card}} </strong> |
|
||||
{% endfor %}
|
||||
|
||||
<li>
|
||||
<strong>Trump Card: {{trump_card}}</strong><br>
|
||||
<strong>Trump Color: {{trump_color}}</strong><br>
|
||||
</li>
|
||||
<ul>
|
||||
<li>
|
||||
<strong>Deal cards</strong><br>
|
||||
<a href="/control/deal/1">deal 1</a>
|
||||
<a href="/control/deal/2">deal 2</a>
|
||||
<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/20">deal 20</a>
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<p class="disclaimer">
|
||||
Spam Bacon Sausage + Spam
|
||||
Spam Spam Spam Spam Spam
|
||||
Spam Baked Beans Spam
|
||||
Spam Spam + Spam
|
||||
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
@ -8,14 +8,17 @@
|
||||
Play a nice game of cards?<br>
|
||||
<br>
|
||||
<strong>Player {{player}} view</strong>
|
||||
<table style="width:100%">
|
||||
<tr>
|
||||
<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>
|
||||
<!--
|
||||
<li>
|
||||
<strong>Movie by IMDB code</strong><br>
|
||||
@ -34,7 +37,7 @@
|
||||
<a href="/api/movie/genre/sci-fi">GET /api/movie/genre/{genre}</a>
|
||||
</li>
|
||||
-->
|
||||
</table>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<p class="disclaimer">
|
||||
|
17
views/control.py
Normal file
17
views/control.py
Normal file
@ -0,0 +1,17 @@
|
||||
from app_instance import api
|
||||
|
||||
from wiz_game import the_game
|
||||
|
||||
|
||||
@api.route("/control/")
|
||||
def index(req, resp):
|
||||
print(req.params)
|
||||
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())
|
||||
|
||||
|
||||
@api.route("/control/deal/{cards}")
|
||||
def deal(req, resp, cards):
|
||||
the_game.deal_cards(int(cards))
|
||||
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())
|
@ -6,6 +6,6 @@ from wiz_game import the_game
|
||||
@api.route("/player/{player}")
|
||||
def index(req, resp, player: str):
|
||||
p = int(player)
|
||||
print(p)
|
||||
print(the_game.players)
|
||||
resp.content = api.template('home/player.html', player=player, cards=the_game.players[p].cards)
|
||||
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)
|
||||
|
34
wiz_game.py
34
wiz_game.py
@ -38,41 +38,45 @@ class WizGame:
|
||||
def __init__(self):
|
||||
self.players = []
|
||||
self.card_deck = []
|
||||
self.trump_color = None
|
||||
self.trump_card = None
|
||||
|
||||
def create_deck(self):
|
||||
for color in ["b", "r", "g", "y"]:
|
||||
for val in range(1,14):
|
||||
for val in range(1, 14):
|
||||
self.card_deck.append(Card(color, val))
|
||||
for _ in range(1,5):
|
||||
for _ in range(1, 5):
|
||||
self.card_deck.append(Card(None, 'Z'))
|
||||
for _ in range(1,5):
|
||||
for _ in range(1, 5):
|
||||
self.card_deck.append(Card(None, 'N'))
|
||||
print("carddeck:")
|
||||
print(self.card_deck)
|
||||
|
||||
def set_trump_color(self, card: Card):
|
||||
if card.color:
|
||||
self.trump_color = card.color
|
||||
elif card.value == 'Z':
|
||||
self.trump_color = 'choose'
|
||||
def get_trump_color(self):
|
||||
card = self.trump_card
|
||||
if card:
|
||||
if card.color:
|
||||
return card.color
|
||||
elif card.value == 'Z':
|
||||
return 'choose'
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
self.trump_color = None
|
||||
return None
|
||||
|
||||
def deal_cards(self, cards_per_player):
|
||||
random.shuffle(self.card_deck)
|
||||
cs = list(chunks(self.card_deck, cards_per_player))
|
||||
for idx,p in enumerate(self.players):
|
||||
for idx, p in enumerate(self.players):
|
||||
p.set_cards(cs[idx])
|
||||
p.show_cards()
|
||||
if len(cs) > len(self.players):
|
||||
cc = cs[len(self.players)]
|
||||
c = cc[0]
|
||||
print("trump card: {}".format(c))
|
||||
self.set_trump_color(c)
|
||||
#self.set_trump_color(c)
|
||||
self.trump_card = c
|
||||
else:
|
||||
self.trump_color = None
|
||||
print("trump color: {}".format(self.trump_color))
|
||||
#self.trump_color = None
|
||||
self.trump_card = None
|
||||
|
||||
def add_player(self, name: str, player_id):
|
||||
if len(self.players) < 6:
|
||||
|
Loading…
Reference in New Issue
Block a user