victory conditions

This commit is contained in:
Alberto Xamin 2020-11-22 18:08:40 +01:00
parent f976770aae
commit 12b84a7ab9
No known key found for this signature in database
GPG Key ID: 4F026F48309500A2
3 changed files with 49 additions and 39 deletions

View File

@ -21,27 +21,6 @@ class Game:
self.readyCount = 0
self.waiting_for = 0
def handle_disconnect(self, player: players.Player):
print(f'player {player.name} left the game {self.name}')
index = self.players.index(player)
for c in player.hand:
self.deck.scrap(c)
for c in player.equipment:
self.deck.scrap(c)
died_in_his_turn = self.started and index == self.turn
if self.started and index < self.turn:
self.turn -= 1
self.players.pop(index)
if len(self.players) == 0:
print(f'no players left in game {self.name}')
return True
self.sio.emit('room', room=self.name, data={'name': self.name, 'started': self.started, 'players': [p.name for p in self.players]})
self.sio.emit('chat_message', room=self.name, data=f'{player.name} si è disconnesso.')
self.players_map = {c.name: i for i, c in enumerate(self.players)}
if died_in_his_turn:
self.next_turn()
return False
def add_player(self, player: players.Player):
if player in self.players:
return
@ -70,6 +49,7 @@ class Game:
self.sio.emit('start', room=self.name)
self.started = True
self.deck = Deck(self)
self.initial_players = len(self.players)
self.choose_characters()
def distribute_roles(self):
@ -185,6 +165,14 @@ class Game:
print('scrap')
self.sio.emit('scrap', room=self.name, data=self.deck.peek_scrap_pile().__dict__)
def handle_disconnect(self, player: players.Player):
print(f'player {player.name} left the game {self.name}')
self.player_death(player=player)
if len(self.players) == 0:
print(f'no players left in game {self.name}')
return True
else: return False
def player_death(self, player: players.Player):
print(f'player {player.name} died')
for c in player.hand:
@ -192,18 +180,25 @@ class Game:
for c in player.equipment:
self.deck.scrap(c)
index = self.players.index(player)
died_in_his_turn = index == self.turn
if index <= self.turn:
died_in_his_turn = self.started and index == self.turn
if self.started and index <= self.turn:
self.turn -= 1
self.players.pop(index)
if len(self.players) == 0:
print(f'no players left in game {self.name}')
return True
self.sio.emit('room', room=self.name, data={'name': self.name, 'started': self.started, 'players': [p.name for p in self.players]})
self.sio.emit('chat_message', room=self.name, data=f'{player.name} è morto.')
for p in self.players:
p.notify_self()
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)]
if len(winners) > 0:
print('WE HAVE A WINNER')
for p in self.players:
p.win_status = p in winners
p.notify_self()
return
if died_in_his_turn:
self.next_turn()

View File

@ -8,7 +8,7 @@ class Role(ABC):
self.health_mod = health_mod
@abstractmethod
def on_player_death(self, alive_players: list):
def on_player_death(self, alive_players: list, initial_players: int):
pass
class Sheriff(Role):
@ -17,10 +17,13 @@ class Sheriff(Role):
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]):
def on_player_death(self, alive_players: list, initial_players: int):
if initial_players == 3 and len(alive_players) == 1:
return True
elif initial_players != 3 and not any([isinstance(p.role, Outlaw) or isinstance(p.role, Renegade) for p in alive_players]):
print("The Sheriff won!")
pass
return True
return False
class Vice(Role):
@ -29,10 +32,13 @@ class Vice(Role):
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]):
def on_player_death(self, alive_players: list, initial_players: int):
if initial_players == 3 and len(alive_players) == 1:
return True
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!")
pass
return True
return False
class Outlaw(Role):
def __init__(self):
@ -40,10 +46,13 @@ class Outlaw(Role):
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]):
def on_player_death(self, alive_players: list, initial_players: int):
if initial_players == 3 and len(alive_players) == 1:
return True
elif initial_players != 3 and not any([isinstance(p.role, Sheriff) for p in alive_players]):
print("The Outlaw won!")
pass
return True
return False
class Renegade(Role):
def __init__(self):
@ -51,7 +60,10 @@ class Renegade(Role):
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:
def on_player_death(self, alive_players: list, initial_players: int):
if initial_players == 3 and len(alive_players) == 1:
return True
elif initial_players != 3 and len(alive_players) == 1 and isinstance(alive_players[0], Renegade):
print("The Renegade won!")
pass
return True
return False

View File

@ -26,6 +26,7 @@
<Chooser v-if="pending_action == 3" text="Scegli come rispondere" :cards="respondCards" :select="respond"/>
<Chooser v-if="shouldChooseCard" text="Scegli che carta pescare" :cards="available_cards" :select="choose"/>
<Chooser v-if="lives <= 0 && max_lives > 0" text="SEI MORTO" />
<Chooser v-if="win_status !== undefined" :text="win_status?'HAI VINTO':'HAI PERSO'" />
<Chooser v-if="is_my_turn" text="GIOCA IL TUO TURNO" :key="is_my_turn" class="turn-notify" />
<Chooser v-if="hasToPickResponse" text="ESTRAI UNA CARTA" :key="hasToPickResponse" class="turn-notify" />
</div>
@ -60,6 +61,7 @@ export default {
expected_response: null,
shouldChooseCard: false,
available_cards: [],
win_status: undefined,
}),
sockets: {
role(role) {
@ -78,6 +80,7 @@ export default {
this.is_my_turn = self.is_my_turn
this.expected_response = self.expected_response
this.available_cards = self.available_cards
this.win_status = self.win_status
if (this.pending_action == 5 && self.target_p) {
this.chooseCardFromPlayer(self.target_p)
} else if (this.pending_action == 5) {