From 7338f8d6fc9fd7d78bb29385710295861b1d57bc Mon Sep 17 00:00:00 2001 From: Alberto Xamin Date: Tue, 24 Nov 2020 19:40:28 +0100 Subject: [PATCH] =?UTF-8?q?modalit=C3=A0=203=20giocatori?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/game.py | 29 ++++++++++++----------------- backend/players.py | 2 ++ backend/roles.py | 27 +++++++++++++++++++-------- frontend/src/components/Lobby.vue | 2 +- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/backend/game.py b/backend/game.py index 4e4f8eb..c0f5712 100644 --- a/backend/game.py +++ b/backend/game.py @@ -56,7 +56,11 @@ class Game: def distribute_roles(self): available_roles: List[roles.Role] = [] if len(self.players) == 3: - available_roles = [roles.Vice(), roles.Renegade(), roles.Outlaw()] + available_roles = [ + roles.Vice('Elimina il Rinnegato 🦅, se non lo elimini tu elimina anche il Fuorilegge'), + roles.Renegade('Elimina il Fuorilegge 🐺, se non lo elimini tu elimina anche il Vice'), + roles.Outlaw('Elimina il Vice 🎖, se non lo elimini tu elimina anche il Rinnegato') + ] elif len(self.players) >= 4: available_roles = [roles.Sheriff(), roles.Renegade(), roles.Outlaw(), roles.Outlaw(), roles.Vice(), roles.Outlaw(), roles.Vice()] available_roles = available_roles[:len(self.players)] @@ -178,7 +182,7 @@ class Game: for i in range(len(player.attacker.equipment)): self.deck.scrap(player.attacker.equipment.pop()) player.attacker.notify_self() - elif player.attacker and isinstance(player.role, roles.Outlaw): + elif player.attacker and isinstance(player.role, roles.Outlaw) or self.initial_players == 3: for i in range(3): player.attacker.hand.append(self.deck.draw()) player.attacker.notify_self() @@ -210,7 +214,10 @@ class Game: self.players_map = {c.name: i for i, c in enumerate(self.players)} if self.started: print('Check win status') - winners = [p for p in self.players if p.role != None and p.role.on_player_death(self.players, initial_players=self.initial_players)] + attacker_role = None + if player.attacker: + attacker_role = player.attacker.role + winners = [p for p in self.players if p.role != None and p.role.on_player_death(self.players, initial_players=self.initial_players, dead_role=player.role, attacker_role=attacker_role)] if len(winners) > 0: print('WE HAVE A WINNER') for p in self.players: @@ -242,19 +249,7 @@ class Game: 'is_sheriff': isinstance(p.role, roles.Sheriff), 'is_my_turn': p.is_my_turn, 'pending_action': p.pending_action, - 'character': p.character.__dict__ + 'character': p.character.__dict__, + 'icon': p.role.icon if self.initial_players == 3 and p.role else '🤠' } for p in self.players] self.sio.emit('players_update', room=self.name, data=data) - - -# game = Game() -# p1 = players.Player('p1') -# game.add_player(p1) -# p2 = players.Player('p2') -# game.add_player(p2) -# p3 = players.Player('p3') -# game.add_player(p3) -# game.start_game() -# for p in game.players: -# p.set_character(random.choice(p.available_characters)) -# game.distribute_roles() diff --git a/backend/players.py b/backend/players.py index 8362bb0..f87ff6b 100644 --- a/backend/players.py +++ b/backend/players.py @@ -466,6 +466,8 @@ class Player: self.attacker = None def get_sight(self): + if not self.character: + return 0 aim = 0 range = 0 for card in self.equipment: diff --git a/backend/roles.py b/backend/roles.py index c5378c4..d9bc7b5 100644 --- a/backend/roles.py +++ b/backend/roles.py @@ -6,10 +6,9 @@ class Role(ABC): self.name = name self.goal = goal self.health_mod = health_mod - self.alt_goal = '' @abstractmethod - def on_player_death(self, alive_players: list, initial_players: int): + def on_player_death(self, alive_players: list, initial_players: int, dead_role=None, attacker_role=None): pass class Sheriff(Role): @@ -28,42 +27,54 @@ class Sheriff(Role): class Vice(Role): - def __init__(self): + def __init__(self, alternative_goal): super().__init__("Vice", "Proteggi lo Sceriffo! Elimina tutti i Fuorilegge e il Rinnegato!") + if alternative_goal: + self.goal = alternative_goal self.max_players = 2 self.icon = '🎖' - def on_player_death(self, alive_players: list, initial_players: int): + def on_player_death(self, alive_players: list, initial_players: int, dead_role=None, attacker_role=None): if initial_players == 3 and len(alive_players) == 1: return True + elif initial_players == 3 and attacker_role != None: + return isinstance(dead_role, Renegade) and isinstance(attacker_role, Vice) elif initial_players != 3 and not any([isinstance(p.role, Outlaw) or isinstance(p.role, Renegade) for p in alive_players]): print("The Vice won!") return True return False class Outlaw(Role): - def __init__(self): + def __init__(self, alternative_goal): super().__init__("Fuorilegge", "Elimina lo Sceriffo!") + if alternative_goal: + self.goal = alternative_goal self.max_players = 3 self.icon = '🐺' - def on_player_death(self, alive_players: list, initial_players: int): + def on_player_death(self, alive_players: list, initial_players: int, dead_role=None, attacker_role=None): if initial_players == 3 and len(alive_players) == 1: return True + elif initial_players == 3 and attacker_role != None: + return isinstance(dead_role, Vice) and isinstance(attacker_role, Outlaw) elif initial_players != 3 and not any([isinstance(p.role, Sheriff) for p in alive_players]): print("The Outlaw won!") return True return False class Renegade(Role): - def __init__(self): + def __init__(self, alternative_goal): super().__init__("Rinnegato", "Rimani l'ultimo personaggio in gioco!") + if alternative_goal: + self.goal = alternative_goal self.max_players = 1 self.icon = '🦅' - def on_player_death(self, alive_players: list, initial_players: int): + def on_player_death(self, alive_players: list, initial_players: int, dead_role=None, attacker_role=None): if initial_players == 3 and len(alive_players) == 1: return True + elif initial_players == 3 and attacker_role != None: + return isinstance(dead_role, Outlaw) and isinstance(attacker_role, Renegade) elif initial_players != 3 and len(alive_players) == 1 and isinstance(alive_players[0], Renegade): print("The Renegade won!") return True diff --git a/frontend/src/components/Lobby.vue b/frontend/src/components/Lobby.vue index 4128f0e..0727304 100644 --- a/frontend/src/components/Lobby.vue +++ b/frontend/src/components/Lobby.vue @@ -141,7 +141,7 @@ export default { return { name: player.name, number: ((this.username == player.name) ? 'YOU' : (this.players[0].name == player.name) ? 'OWNER' :'') + (player.dist ? `${player.dist}⛰` : ''), - icon: (player.lives === undefined || player.lives > 0) ? (player.is_sheriff ? '⭐' : '🤠') : '☠️', + icon: (player.lives === undefined || player.lives > 0) ? (player.is_sheriff ? '⭐' : player.icon || '🤠' ) : '☠️', is_character: true, } },