gatling, indiani
This commit is contained in:
parent
f65f46528e
commit
ce8f9da155
@ -19,6 +19,7 @@ class Game:
|
||||
self.started = False
|
||||
self.turn = 0
|
||||
self.readyCount = 0
|
||||
self.waiting_for = 0
|
||||
|
||||
def handle_disconnect(self, player: players.Player):
|
||||
print(f'player {player.name} left the game {self.name}')
|
||||
@ -96,13 +97,37 @@ class Game:
|
||||
'max_lives': self.players[j].max_lives,
|
||||
} for j in range(len(self.players)) if i != j]
|
||||
|
||||
def attack_others(self, attacker:Player):
|
||||
attacker.pending_action = players.PendingAction.WAIT
|
||||
attacker.notify_self()
|
||||
self.waiting_for = 0
|
||||
self.readyCount = 0
|
||||
for p in self.players:
|
||||
if p != attacker:
|
||||
if p.get_banged():
|
||||
self.waiting_for += 1
|
||||
|
||||
def indian_others(self, attacker:Player):
|
||||
attacker.pending_action = players.PendingAction.WAIT
|
||||
attacker.notify_self()
|
||||
self.waiting_for = 0
|
||||
self.readyCount = 0
|
||||
for p in self.players:
|
||||
if p != attacker:
|
||||
if p.get_indians():
|
||||
self.waiting_for += 1
|
||||
|
||||
def attack(self, attacker:Player, target_username:str):
|
||||
if self.players[self.players_map[target_username]].get_banged():
|
||||
self.readyCount = 0
|
||||
self.waiting_for = 1
|
||||
attacker.pending_action = players.PendingAction.WAIT
|
||||
attacker.notify_self()
|
||||
|
||||
def duel(self, attacker:Player, target_username:str):
|
||||
if self.players[self.players_map[target_username]].get_dueled(attacker=attacker):
|
||||
self.readyCount = 0
|
||||
self.waiting_for = 1
|
||||
attacker.pending_action = players.PendingAction.WAIT
|
||||
attacker.notify_self()
|
||||
|
||||
@ -110,6 +135,10 @@ class Game:
|
||||
return self.players[self.players_map[name]]
|
||||
|
||||
def responders_did_respond_resume_turn(self):
|
||||
self.readyCount += 1
|
||||
if self.readyCount == self.waiting_for:
|
||||
self.waiting_for = 0
|
||||
self.readyCount = 0
|
||||
self.players[self.turn].pending_action = players.PendingAction.PLAY
|
||||
self.players[self.turn].notify_self()
|
||||
|
||||
|
@ -220,13 +220,10 @@ class Player:
|
||||
pass
|
||||
if isinstance(card, cards.Gatling):
|
||||
self.sio.emit('chat_message', room=self.game.name, data=f'{self.name} ha giocato {card.name}.')
|
||||
for p in self.game.players:
|
||||
if p != self:
|
||||
self.game.attack(self, p)
|
||||
pass
|
||||
self.game.attack_others(self)
|
||||
if isinstance(card, cards.Indiani):
|
||||
self.sio.emit('chat_message', room=self.game.name, data=f'{self.name} ha giocato {card.name}.')
|
||||
pass
|
||||
self.game.indian_others(self)
|
||||
if isinstance(card, cards.Mancato):
|
||||
pass
|
||||
if isinstance(card, cards.Panico):
|
||||
@ -304,6 +301,20 @@ class Player:
|
||||
self.notify_self()
|
||||
return True
|
||||
|
||||
def get_indians(self, attacker = None):
|
||||
if len([c for c in self.hand if isinstance(c, cards.Bang)]) == 0:
|
||||
print('Cant defend')
|
||||
self.take_damage_response()
|
||||
return False
|
||||
else:
|
||||
print('has bang')
|
||||
self.pending_action = PendingAction.RESPOND
|
||||
self.expected_response = cards.Bang(0,0).name
|
||||
self.event_type = 'indians'
|
||||
self.on_failed_response_cb = self.take_damage_response
|
||||
self.notify_self()
|
||||
return True
|
||||
|
||||
def get_dueled(self, attacker):
|
||||
if len([c for c in self.hand if isinstance(c, cards.Bang)]) == 0:
|
||||
print('Cant defend')
|
||||
|
Loading…
Reference in New Issue
Block a user