modalità 3 giocatori

This commit is contained in:
Alberto Xamin 2020-11-24 19:40:28 +01:00
parent 8d95154940
commit 7338f8d6fc
No known key found for this signature in database
GPG Key ID: 4F026F48309500A2
4 changed files with 34 additions and 26 deletions

View File

@ -56,7 +56,11 @@ class Game:
def distribute_roles(self): def distribute_roles(self):
available_roles: List[roles.Role] = [] available_roles: List[roles.Role] = []
if len(self.players) == 3: 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: elif len(self.players) >= 4:
available_roles = [roles.Sheriff(), roles.Renegade(), roles.Outlaw(), roles.Outlaw(), roles.Vice(), roles.Outlaw(), roles.Vice()] available_roles = [roles.Sheriff(), roles.Renegade(), roles.Outlaw(), roles.Outlaw(), roles.Vice(), roles.Outlaw(), roles.Vice()]
available_roles = available_roles[:len(self.players)] available_roles = available_roles[:len(self.players)]
@ -178,7 +182,7 @@ class Game:
for i in range(len(player.attacker.equipment)): for i in range(len(player.attacker.equipment)):
self.deck.scrap(player.attacker.equipment.pop()) self.deck.scrap(player.attacker.equipment.pop())
player.attacker.notify_self() 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): for i in range(3):
player.attacker.hand.append(self.deck.draw()) player.attacker.hand.append(self.deck.draw())
player.attacker.notify_self() player.attacker.notify_self()
@ -210,7 +214,10 @@ class Game:
self.players_map = {c.name: i for i, c in enumerate(self.players)} self.players_map = {c.name: i for i, c in enumerate(self.players)}
if self.started: if self.started:
print('Check win status') 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: if len(winners) > 0:
print('WE HAVE A WINNER') print('WE HAVE A WINNER')
for p in self.players: for p in self.players:
@ -242,19 +249,7 @@ class Game:
'is_sheriff': isinstance(p.role, roles.Sheriff), 'is_sheriff': isinstance(p.role, roles.Sheriff),
'is_my_turn': p.is_my_turn, 'is_my_turn': p.is_my_turn,
'pending_action': p.pending_action, '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] } for p in self.players]
self.sio.emit('players_update', room=self.name, data=data) 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()

View File

@ -466,6 +466,8 @@ class Player:
self.attacker = None self.attacker = None
def get_sight(self): def get_sight(self):
if not self.character:
return 0
aim = 0 aim = 0
range = 0 range = 0
for card in self.equipment: for card in self.equipment:

View File

@ -6,10 +6,9 @@ class Role(ABC):
self.name = name self.name = name
self.goal = goal self.goal = goal
self.health_mod = health_mod self.health_mod = health_mod
self.alt_goal = ''
@abstractmethod @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 pass
class Sheriff(Role): class Sheriff(Role):
@ -28,42 +27,54 @@ class Sheriff(Role):
class Vice(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!") 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.max_players = 2
self.icon = '🎖' 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: if initial_players == 3 and len(alive_players) == 1:
return True 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]): 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!") print("The Vice won!")
return True return True
return False return False
class Outlaw(Role): class Outlaw(Role):
def __init__(self): def __init__(self, alternative_goal):
super().__init__("Fuorilegge", "Elimina lo Sceriffo!") super().__init__("Fuorilegge", "Elimina lo Sceriffo!")
if alternative_goal:
self.goal = alternative_goal
self.max_players = 3 self.max_players = 3
self.icon = '🐺' 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: if initial_players == 3 and len(alive_players) == 1:
return True 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]): elif initial_players != 3 and not any([isinstance(p.role, Sheriff) for p in alive_players]):
print("The Outlaw won!") print("The Outlaw won!")
return True return True
return False return False
class Renegade(Role): class Renegade(Role):
def __init__(self): def __init__(self, alternative_goal):
super().__init__("Rinnegato", "Rimani l'ultimo personaggio in gioco!") super().__init__("Rinnegato", "Rimani l'ultimo personaggio in gioco!")
if alternative_goal:
self.goal = alternative_goal
self.max_players = 1 self.max_players = 1
self.icon = '🦅' 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: if initial_players == 3 and len(alive_players) == 1:
return True 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): elif initial_players != 3 and len(alive_players) == 1 and isinstance(alive_players[0], Renegade):
print("The Renegade won!") print("The Renegade won!")
return True return True

View File

@ -141,7 +141,7 @@ export default {
return { return {
name: player.name, name: player.name,
number: ((this.username == player.name) ? 'YOU' : (this.players[0].name == player.name) ? 'OWNER' :'') + (player.dist ? `${player.dist}` : ''), 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, is_character: true,
} }
}, },