This commit is contained in:
Alberto Xamin 2020-11-22 16:13:21 +01:00
parent 50f03ee43b
commit 360457907b
No known key found for this signature in database
GPG Key ID: 4F026F48309500A2
3 changed files with 58 additions and 18 deletions

View File

@ -6,7 +6,7 @@ from cards import Bang
import players
from characters import all_characters
from deck import Deck
from players import Player
from players import PendingAction, Player
import roles
class Game:
@ -109,6 +109,9 @@ class Game:
if p != attacker:
if p.get_banged():
self.waiting_for += 1
if self.waiting_for == 0:
attacker.pending_action = players.PendingAction.PLAY
attacker.notify_self()
def indian_others(self, attacker:Player):
attacker.pending_action = players.PendingAction.WAIT
@ -119,6 +122,9 @@ class Game:
if p != attacker:
if p.get_indians():
self.waiting_for += 1
if self.waiting_for == 0:
attacker.pending_action = players.PendingAction.PLAY
attacker.notify_self()
def attack(self, attacker:Player, target_username:str):
if self.players[self.players_map[target_username]].get_banged():
@ -134,6 +140,26 @@ class Game:
attacker.pending_action = players.PendingAction.WAIT
attacker.notify_self()
def emporio(self):
self.available_cards = [self.deck.draw() for i in range(len(self.players))]
self.players[self.turn].pending_action = players.PendingAction.CHOOSE
self.players[self.turn].available_cards = [self.deck.draw() for i in range(len(self.players))]
self.players[self.turn].notify_self()
def respond_emporio(self, player, i):
player.hand.append(self.available_cards.pop(i))
player.available_cards = []
player.pending_action = players.PendingAction.WAIT
player.notify_self()
nextPlayer = self.players[(self.turn + (len(self.players)-len(self.available_cards))) % len(self.players)]
if nextPlayer == self.players[self.turn]:
self.players[self.turn].pending_action = players.PendingAction.PLAY
self.players[self.turn].notify_self()
else:
nextPlayer.pending_action = players.PendingAction.CHOOSE
nextPlayer.available_cards = self.available_cards
nextPlayer.notify_self()
def get_player_named(self, name:str):
return self.players[self.players_map[name]]

View File

@ -217,7 +217,7 @@ class Player:
self.game.duel(self, againts)
if isinstance(card, cards.Emporio):
self.sio.emit('chat_message', room=self.game.name, data=f'{self.name} ha giocato {card.name}.')
pass
self.game.emporio()
if isinstance(card, cards.Gatling):
self.sio.emit('chat_message', room=self.game.name, data=f'{self.name} ha giocato {card.name}.')
self.game.attack_others(self)
@ -247,21 +247,24 @@ class Player:
def choose(self, card_index):
if self.pending_action != PendingAction.CHOOSE:
return
target = self.game.get_player_named(self.target_p)
card = None
if card_index >= len(target.hand):
card = target.equipment.pop(card_index - len(target.hand))
if self.target_p and self.target_p != '':
target = self.game.get_player_named(self.target_p)
card = None
if card_index >= len(target.hand):
card = target.equipment.pop(card_index - len(target.hand))
else:
card = target.hand.pop(card_index)
target.notify_self()
if self.choose_action == 'steal':
self.hand.append(card)
else:
self.game.deck.scrap(card)
self.target_p = ''
self.choose_action = ''
self.pending_action = PendingAction.PLAY
self.notify_self()
else:
card = target.hand.pop(card_index)
target.notify_self()
if self.choose_action == 'steal':
self.hand.append(card)
else:
self.game.deck.scrap(card)
self.target_p = ''
self.choose_action = ''
self.pending_action = PendingAction.PLAY
self.notify_self()
self.game.respond_emporio(self, card_index)
def barrel_pick(self):
pickable_cards = 1 + self.character.pick_mod

View File

@ -24,6 +24,7 @@
<p>{{hint}}</p>
<Chooser v-if="card_against" text="Contro chi vuoi giocare la carta" :cards="visiblePlayers" :select="selectAgainst"/>
<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="is_my_turn" text="GIOCA IL TUO TURNO" :key="is_my_turn" class="turn-notify" />
</div>
@ -56,6 +57,8 @@ export default {
visiblePlayers: [],
is_my_turn: false,
expected_response: null,
shouldChooseCard: false,
available_cards: [],
}),
sockets: {
role(role) {
@ -73,8 +76,11 @@ export default {
this.has_played_bang = self.has_played_bang
this.is_my_turn = self.is_my_turn
this.expected_response = self.expected_response
if (this.pending_action == 5) {
this.available_cards = self.available_cards
if (this.pending_action == 5 && self.target_p) {
this.chooseCardFromPlayer(self.target_p)
} else if (this.pending_action == 5) {
this.shouldChooseCard = true
}
},
self_vis(vis) {
@ -140,7 +146,12 @@ export default {
}
console.log(card_data)
this.$socket.emit('play_card', card_data)
}
},
choose(card) {
this.$socket.emit('choose', this.available_cards.indexOf(card))
this.available_cards = []
this.shouldChooseCard = false
},
},
mounted() {
this.$socket.emit('refresh')