From a119ce6852cd452cc5615b02aa208431b5802676 Mon Sep 17 00:00:00 2001 From: Alberto Xamin Date: Fri, 20 Nov 2020 22:38:55 +0100 Subject: [PATCH] pick and play end turn --- backend/__init__.py | 21 +++++++++++++ backend/players.py | 24 +++++++++----- backend/roles.py | 4 +++ frontend/src/App.vue | 9 +++++- frontend/src/components/Card.vue | 11 ++++--- frontend/src/components/Deck.vue | 20 +++++++++--- frontend/src/components/Lobby.vue | 7 +++-- frontend/src/components/Player.vue | 50 +++++++++++++++++++++++++----- 8 files changed, 118 insertions(+), 28 deletions(-) diff --git a/backend/__init__.py b/backend/__init__.py index 5fd5bbe..3bebecc 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -1,3 +1,4 @@ +import json import eventlet import socketio @@ -70,5 +71,25 @@ def set_character(sid, name): ses = sio.get_session(sid) ses.set_character(name) +@sio.event +def refresh(sid): + ses = sio.get_session(sid) + ses.notify_self() + +@sio.event +def draw(sid): + ses = sio.get_session(sid) + ses.draw() + +@sio.event +def end_turn(sid): + ses = sio.get_session(sid) + ses.end_turn() + +@sio.event +def play_card(sid, data): + ses = sio.get_session(sid) + ses.play_card(data['index'], data['against']) + if __name__ == '__main__': eventlet.wsgi.server(eventlet.listen(('', 5001)), app) diff --git a/backend/players.py b/backend/players.py index d613bef..a16f830 100644 --- a/backend/players.py +++ b/backend/players.py @@ -77,7 +77,7 @@ class Player: self.is_my_turn = True self.is_waiting_for_action = True self.has_played_bang = False - if any([isinstance(c) == cards.Dinamite or isinstance(c) == cards.Prigione for c in self.equipment]): + if any([isinstance(c, cards.Dinamite) or isinstance(c, cards.Prigione) for c in self.equipment]): self.pending_action = PendingAction.PICK else: self.pending_action = PendingAction.DRAW @@ -97,7 +97,7 @@ class Player: def pick(self): pickable_cards = 1 + self.character.pick_mod for i in range(len(self.equipment)): - if isinstance(self.equipment[i]) == cards.Dinamite: + if isinstance(self.equipment[i], cards.Dinamite): while pickable_cards > 0: pickable_cards -= 1 picked: cards.Card = self.game.deck.pick_and_scrap() @@ -108,10 +108,10 @@ class Player: print(f'{self.name} Boom, -3 hp') else: self.game.next_player().equipment.append(self.equipment.pop(i)) - if any([isinstance(c) == cards.Dinamite or isinstance(c) == cards.Prigione for c in self.equipment]): + if any([isinstance(c, cards.Dinamite) or isinstance(c, cards.Prigione) for c in self.equipment]): return for i in range(len(self.equipment)): - if isinstance(self.equipment[i]) == cards.Prigione: + if isinstance(self.equipment[i], cards.Prigione): while pickable_cards > 0: pickable_cards -= 1 picked: cards.Card = self.game.deck.pick_and_scrap() @@ -128,16 +128,16 @@ class Player: playable_cards = [] for i in range(len(self.hand)): card = self.hand[i] - if isinstance(card) == cards.Bang and self.has_played_bang and not any([isinstance(c) == cards.Volcanic for c in self.equipment]): + if isinstance(card, cards.Bang) and self.has_played_bang and not any([isinstance(c, cards.Volcanic) for c in self.equipment]): continue - elif isinstance(card) == cards.Birra and self.lives >= self.max_lives: + elif isinstance(card, cards.Birra) and self.lives >= self.max_lives: continue else: playable_cards.append(i) return playable_cards def get_public_description(self): - s = f"{self.name} {'Sheriff ⭐️' if isinstance(self.role) == roles.Sheriff else ''} ({self.lives}/{self.max_lives} ⁍) {len(self.hand)} Cards in hand, " + s = f"{self.name} {'Sheriff ⭐️' if isinstance(self.role, roles.Sheriff) else ''} ({self.lives}/{self.max_lives} ⁍) {len(self.hand)} Cards in hand, " s += f"equipment {[str(c) for c in self.equipment]}" return s @@ -149,17 +149,22 @@ class Player: print(self.name, 'is playing ', card, ' against:', againts) if card.is_equipment and card.name not in [c.name for c in self.equipment]: if card.is_weapon: + has_weapon = False for i in range(len(self.equipment)): if self.equipment[i].is_weapon: self.game.deck.scrap(self.equipment[i]) self.equipment[i] = card + has_weapon = True break + if not has_weapon: + self.equipment.append(card) else: self.equipment.append(card) else: - if isinstance(card) == cards.Bang and self.has_played_bang and not any([isinstance(c) == cards.Volcanic for c in self.equipment]): + if isinstance(card, cards.Bang) and self.has_played_bang and not any([isinstance(c, cards.Volcanic) for c in self.equipment]): print('you retard') self.game.deck.scrap(card) + self.notify_self() def get_sight(self): aim = 0 @@ -176,7 +181,10 @@ class Player: return self.character.visibility_mod + covers def end_turn(self, forced=False): + if not self.is_my_turn: return if len(self.hand) > self.max_lives and not forced: print(f"I {self.name} have to many cards in my hand and I can't end the turn") else: + self.pending_action = PendingAction.WAIT + self.notify_self() self.game.next_turn() diff --git a/backend/roles.py b/backend/roles.py index 8ec70ba..846937a 100644 --- a/backend/roles.py +++ b/backend/roles.py @@ -15,6 +15,7 @@ class Sheriff(Role): def __init__(self): super().__init__("Sceriffo", "Elimina tutti i Fuorilegge e il Rinnegato!", health_mod=+1) self.max_players = 1 + self.icon = '⭐️' def on_player_death(self, alive_players: list): if not any([isinstance(p.role) == Outlaw or isinstance(p.role) == Renegade for p in alive_players]): @@ -26,6 +27,7 @@ class Vice(Role): def __init__(self): super().__init__("Vice", "Proteggi lo Sceriffo! Elimina tutti i Fuorilegge e il Rinnegato!") self.max_players = 2 + self.icon = '🎖' def on_player_death(self, alive_players: list): if not any([isinstance(p.role) == Outlaw or isinstance(p.role) == Renegade for p in alive_players]): @@ -36,6 +38,7 @@ class Outlaw(Role): def __init__(self): super().__init__("Fuorilegge", "Elimina lo Sceriffo!") self.max_players = 3 + self.icon = '🐺' def on_player_death(self, alive_players: list): if not any([isinstance(p.role) == Sheriff for p in alive_players]): @@ -46,6 +49,7 @@ class Renegade(Role): def __init__(self): super().__init__("Rinnegato", "Rimani l'ultimo personaggio in gioco!") self.max_players = 1 + self.icon = '🦅' def on_player_death(self, alive_players: list): if len(alive_players) == 1 and isinstance(alive_players[0]) == Renegade: diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 57d5e17..c3b81d6 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -73,7 +73,7 @@ export default { setTimeout(function(){ this.username =(1+Math.random() * 100 % 100).toFixed(2).toString(); this.setUsername(); - }.bind(this), 200) + }.bind(this), 1000) }, disconnect() { this.isConnected = false; @@ -132,4 +132,11 @@ h1,h2,h3,h4,p,span{ right: 0; text-align: center; } +.list-enter-active, .list-leave-active { + transition: all 0.5s; +} +.list-enter, .list-leave-to /* .list-leave-active below version 2.1.8 */ { + opacity: 0; + transform: translateY(30px); +} diff --git a/frontend/src/components/Card.vue b/frontend/src/components/Card.vue index 09df376..b887ef0 100644 --- a/frontend/src/components/Card.vue +++ b/frontend/src/components/Card.vue @@ -47,10 +47,13 @@ export default { } .card.back{ color:white; - background: #987e51; -} -.card.back::before{ - background:red; + background: repeating-linear-gradient( + 45deg, + #987e51, + #987e51 5px, + #816b45 5px, + #816b45 10px + ); } .card.equipment { diff --git a/frontend/src/components/Deck.vue b/frontend/src/components/Deck.vue index 9946788..52f689d 100644 --- a/frontend/src/components/Deck.vue +++ b/frontend/src/components/Deck.vue @@ -8,7 +8,7 @@
- +
@@ -26,13 +26,25 @@ export default { name: 'PewPew!', icon: '💥', }, + pending_action: false, }), sockets: { - + self(self){ + self = JSON.parse(self) + this.pending_action = self.pending_action + } }, methods: { - - }, + action() { + if (this.pending_action && this.pending_action < 2) { + console.log('action') + if (this.pending_action == 0) + this.$socket.emit('pick') + else if (this.pending_action == 1) + this.$socket.emit('draw') + } + } + } } \ No newline at end of file