added control view
This commit is contained in:
		@@ -8,5 +8,7 @@ from views.home import *
 | 
				
			|||||||
from views.temp_css import *
 | 
					from views.temp_css import *
 | 
				
			||||||
# noinspection PyUnresolvedReferences
 | 
					# noinspection PyUnresolvedReferences
 | 
				
			||||||
from views.player import *
 | 
					from views.player import *
 | 
				
			||||||
 | 
					# noinspection PyUnresolvedReferences
 | 
				
			||||||
 | 
					from views.control import *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
api.add_route("/static", static=True)
 | 
					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("p1", 1)
 | 
				
			||||||
    wiz_game.the_game.add_player("p2", 2)
 | 
					    wiz_game.the_game.add_player("p2", 2)
 | 
				
			||||||
    wiz_game.the_game.add_player("p3", 3)
 | 
					    wiz_game.the_game.add_player("p3", 3)
 | 
				
			||||||
    wiz_game.the_game.add_player("p4", 4)
 | 
					    #wiz_game.the_game.add_player("p4", 4)
 | 
				
			||||||
    wiz_game.the_game.deal_cards(4)
 | 
					    wiz_game.the_game.deal_cards(12)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    api.run(port=19203, address="127.0.0.1")
 | 
					    api.run(port=19203, address="127.0.0.1")
 | 
				
			||||||
    exit(0)
 | 
					    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>
 | 
					                Play a nice game of cards?<br>
 | 
				
			||||||
                <br>
 | 
					                <br>
 | 
				
			||||||
                <strong>Player {{player}} view</strong>
 | 
					                <strong>Player {{player}} view</strong>
 | 
				
			||||||
            <table style="width:100%">
 | 
					            <ul>
 | 
				
			||||||
                <tr>
 | 
					 | 
				
			||||||
                {% for card in cards %}
 | 
					                {% for card in cards %}
 | 
				
			||||||
                    <li>
 | 
					                    <li>
 | 
				
			||||||
                        <strong>>card {{loop.index}} is: {{card}} </strong><br>
 | 
					                        <strong>>card {{loop.index}} is: {{card}} </strong><br>
 | 
				
			||||||
                    </li>
 | 
					                    </li>
 | 
				
			||||||
                {% endfor %}
 | 
					                {% endfor %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                <li>
 | 
				
			||||||
 | 
					                    <strong>Trump Card: {{trump_card}}</strong><br>
 | 
				
			||||||
 | 
					                    <strong>Trump Color: {{trump_color}}</strong><br>
 | 
				
			||||||
 | 
					                </li>
 | 
				
			||||||
<!--
 | 
					<!--
 | 
				
			||||||
                <li>
 | 
					                <li>
 | 
				
			||||||
                    <strong>Movie by IMDB code</strong><br>
 | 
					                    <strong>Movie by IMDB code</strong><br>
 | 
				
			||||||
@@ -34,7 +37,7 @@
 | 
				
			|||||||
                    <a href="/api/movie/genre/sci-fi">GET /api/movie/genre/{genre}</a>
 | 
					                    <a href="/api/movie/genre/sci-fi">GET /api/movie/genre/{genre}</a>
 | 
				
			||||||
                </li>
 | 
					                </li>
 | 
				
			||||||
-->
 | 
					-->
 | 
				
			||||||
            </table>
 | 
					            </ul>
 | 
				
			||||||
            </p>
 | 
					            </p>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <p class="disclaimer">
 | 
					            <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}")
 | 
					@api.route("/player/{player}")
 | 
				
			||||||
def index(req, resp, player: str):
 | 
					def index(req, resp, player: str):
 | 
				
			||||||
    p = int(player)
 | 
					    p = int(player)
 | 
				
			||||||
    print(p)
 | 
					    tcard = the_game.trump_card
 | 
				
			||||||
    print(the_game.players)
 | 
					    tcolor = the_game.get_trump_color()
 | 
				
			||||||
    resp.content = api.template('home/player.html', player=player, cards=the_game.players[p].cards)
 | 
					    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):
 | 
					    def __init__(self):
 | 
				
			||||||
        self.players = []
 | 
					        self.players = []
 | 
				
			||||||
        self.card_deck = []
 | 
					        self.card_deck = []
 | 
				
			||||||
        self.trump_color = None
 | 
					        self.trump_card = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def create_deck(self):
 | 
					    def create_deck(self):
 | 
				
			||||||
        for color in ["b", "r", "g", "y"]:
 | 
					        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))
 | 
					                self.card_deck.append(Card(color, val))
 | 
				
			||||||
        for _ in range(1,5):
 | 
					        for _ in range(1, 5):
 | 
				
			||||||
            self.card_deck.append(Card(None, 'Z'))
 | 
					            self.card_deck.append(Card(None, 'Z'))
 | 
				
			||||||
        for _ in range(1,5):
 | 
					        for _ in range(1, 5):
 | 
				
			||||||
            self.card_deck.append(Card(None, 'N'))
 | 
					            self.card_deck.append(Card(None, 'N'))
 | 
				
			||||||
        print("carddeck:")
 | 
					        print("carddeck:")
 | 
				
			||||||
        print(self.card_deck)
 | 
					        print(self.card_deck)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def set_trump_color(self, card: Card):
 | 
					    def get_trump_color(self):
 | 
				
			||||||
        if card.color:
 | 
					        card = self.trump_card
 | 
				
			||||||
            self.trump_color = card.color
 | 
					        if card:
 | 
				
			||||||
        elif card.value == 'Z':
 | 
					            if card.color:
 | 
				
			||||||
            self.trump_color = 'choose'
 | 
					                return card.color
 | 
				
			||||||
 | 
					            elif card.value == 'Z':
 | 
				
			||||||
 | 
					                return 'choose'
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                return None
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            self.trump_color = None
 | 
					            return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def deal_cards(self, cards_per_player):
 | 
					    def deal_cards(self, cards_per_player):
 | 
				
			||||||
        random.shuffle(self.card_deck)
 | 
					        random.shuffle(self.card_deck)
 | 
				
			||||||
        cs = list(chunks(self.card_deck, cards_per_player))
 | 
					        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.set_cards(cs[idx])
 | 
				
			||||||
            p.show_cards()
 | 
					            p.show_cards()
 | 
				
			||||||
        if len(cs) > len(self.players):
 | 
					        if len(cs) > len(self.players):
 | 
				
			||||||
            cc = cs[len(self.players)]
 | 
					            cc = cs[len(self.players)]
 | 
				
			||||||
            c = cc[0]
 | 
					            c = cc[0]
 | 
				
			||||||
            print("trump card: {}".format(c))
 | 
					            #self.set_trump_color(c)
 | 
				
			||||||
            self.set_trump_color(c)
 | 
					            self.trump_card = c
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            self.trump_color = None
 | 
					            #self.trump_color = None
 | 
				
			||||||
        print("trump color: {}".format(self.trump_color))
 | 
					            self.trump_card = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def add_player(self, name: str, player_id):
 | 
					    def add_player(self, name: str, player_id):
 | 
				
			||||||
        if len(self.players) < 6:
 | 
					        if len(self.players) < 6:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user