panico e catbalou
This commit is contained in:
parent
5068eafe5b
commit
badc9565da
@ -101,5 +101,10 @@ def respond(sid, data):
|
||||
ses = sio.get_session(sid)
|
||||
ses.respond(data)
|
||||
|
||||
@sio.event
|
||||
def choose(sid, card_index):
|
||||
ses = sio.get_session(sid)
|
||||
ses.choose(card_index)
|
||||
|
||||
if __name__ == '__main__':
|
||||
eventlet.wsgi.server(eventlet.listen(('', 5001)), app)
|
||||
|
@ -25,6 +25,7 @@ class Game:
|
||||
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)
|
||||
@ -34,6 +35,8 @@ class Game:
|
||||
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):
|
||||
@ -125,7 +128,8 @@ class Game:
|
||||
for c in player.equipment:
|
||||
self.deck.scrap(c)
|
||||
index = self.players.index(player)
|
||||
if index < self.turn:
|
||||
died_in_his_turn = index == self.turn
|
||||
if index <= self.turn:
|
||||
self.turn -= 1
|
||||
self.players.pop(index)
|
||||
if len(self.players) == 0:
|
||||
@ -136,6 +140,8 @@ class Game:
|
||||
for p in self.players:
|
||||
p.notify_self()
|
||||
self.players_map = {c.name: i for i, c in enumerate(self.players)}
|
||||
if died_in_his_turn:
|
||||
self.next_turn()
|
||||
|
||||
def notify_all(self):
|
||||
data = [{
|
||||
|
@ -13,6 +13,7 @@ class PendingAction(IntEnum):
|
||||
PLAY = 2
|
||||
RESPOND = 3
|
||||
WAIT = 4
|
||||
CHOOSE = 5
|
||||
|
||||
class Player:
|
||||
def __init__(self, name, sid, sio):
|
||||
@ -36,6 +37,7 @@ class Player:
|
||||
self.on_pick_cb = None
|
||||
self.on_response_cb = None
|
||||
self.expected_response = None
|
||||
self.target_p: str = None
|
||||
|
||||
def join_game(self, game):
|
||||
self.game = game
|
||||
@ -85,6 +87,7 @@ class Player:
|
||||
def play_turn(self):
|
||||
if self.lives == 0:
|
||||
self.end_turn(forced=True)
|
||||
self.sio.emit('chat_message', room=self.game.name, data=f'È il turno di {self.name}.')
|
||||
print(f'I {self.name} was notified that it is my turn')
|
||||
self.was_shot = False
|
||||
self.is_my_turn = True
|
||||
@ -118,6 +121,7 @@ class Player:
|
||||
if picked.suit == cards.Suit.SPADES and 2 <= picked.number <= 9 and pickable_cards == 0:
|
||||
self.lives -= 3
|
||||
self.game.deck.scrap(self.equipment.pop(i))
|
||||
self.sio.emit('chat_message', room=self.game.name, data=f'{self.name} ha fatto esplodere la dinamite.')
|
||||
print(f'{self.name} Boom, -3 hp')
|
||||
else:
|
||||
self.game.next_player().equipment.append(self.equipment.pop(i))
|
||||
@ -189,40 +193,76 @@ class Player:
|
||||
self.hand.insert(hand_index, card)
|
||||
return
|
||||
if isinstance(card, cards.Bang) and againts != None:
|
||||
self.sio.emit('chat_message', room=self.game.name, data=f'{self.name} ha giocato {card.name} contro {againts}.')
|
||||
self.has_played_bang = True
|
||||
self.game.attack(self, againts)
|
||||
if isinstance(card, cards.Birra) and len(self.game.players) != 2:
|
||||
self.sio.emit('chat_message', room=self.game.name, data=f'{self.name} ha giocato una {card.name}.')
|
||||
self.lives = min(self.lives+1, self.max_lives)
|
||||
if isinstance(card, cards.CatBalou):
|
||||
pass
|
||||
if isinstance(card, cards.CatBalou) and againts != None:
|
||||
self.sio.emit('chat_message', room=self.game.name, data=f'{self.name} ha giocato {card.name} contro {againts}.')
|
||||
self.pending_action = PendingAction.CHOOSE
|
||||
self.choose_action = 'discard'
|
||||
self.target_p = againts
|
||||
print('choose now')
|
||||
if isinstance(card, cards.Diligenza):
|
||||
self.sio.emit('chat_message', room=self.game.name, data=f'{self.name} ha giocato {card.name} e ha pescato 2 carte.')
|
||||
for i in range(2):
|
||||
self.hand.append(self.game.deck.draw())
|
||||
if isinstance(card, cards.Duello):
|
||||
self.sio.emit('chat_message', room=self.game.name, data=f'{self.name} ha giocato {card.name} contro {againts}.')
|
||||
pass
|
||||
if isinstance(card, cards.Emporio):
|
||||
self.sio.emit('chat_message', room=self.game.name, data=f'{self.name} ha giocato {card.name}.')
|
||||
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
|
||||
if isinstance(card, cards.Indiani):
|
||||
self.sio.emit('chat_message', room=self.game.name, data=f'{self.name} ha giocato {card.name}.')
|
||||
pass
|
||||
if isinstance(card, cards.Mancato):
|
||||
pass
|
||||
if isinstance(card, cards.Panico):
|
||||
pass
|
||||
self.sio.emit('chat_message', room=self.game.name, data=f'{self.name} ha giocato {card.name} contro {againts}.')
|
||||
self.pending_action = PendingAction.CHOOSE
|
||||
self.choose_action = 'steal'
|
||||
self.target_p = againts
|
||||
print('choose now')
|
||||
if isinstance(card, cards.Saloon):
|
||||
self.sio.emit('chat_message', room=self.game.name, data=f'{self.name} ha giocato {card.name} e ha curato 1 punto vita a tutti.')
|
||||
for p in self.game.players:
|
||||
p.lives = min(p.lives+1, p.max_lives)
|
||||
p.notify_self()
|
||||
if isinstance(card, cards.WellsFargo):
|
||||
self.sio.emit('chat_message', room=self.game.name, data=f'{self.name} ha giocato {card.name} e ha pescato 3 carte.')
|
||||
for i in range(3):
|
||||
self.hand.append(self.game.deck.draw())
|
||||
self.game.deck.scrap(card)
|
||||
self.notify_self()
|
||||
|
||||
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))
|
||||
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()
|
||||
|
||||
def barrel_pick(self):
|
||||
pickable_cards = 1 + self.character.pick_mod
|
||||
while pickable_cards > 0:
|
||||
|
@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div :class="{ card: true, equipment: card.is_equipment, character:card.is_character}">
|
||||
<div :class="{ card: true, equipment: card.is_equipment, character:card.is_character, back:card.is_back}">
|
||||
<h4>{{card.name}}</h4>
|
||||
<div class="emoji">{{card.icon}}</div>
|
||||
<div v-if="card.is_character" class="alt_text">{{card.alt_text}}</div>
|
||||
|
@ -17,11 +17,12 @@
|
||||
</div>
|
||||
<div v-if="started">
|
||||
<deck/>
|
||||
<player/>
|
||||
<player :chooseCardFromPlayer="choose"/>
|
||||
</div>
|
||||
<chat/>
|
||||
<transition name="bounce">
|
||||
<Chooser v-if="showChooser" text="Scegli il tuo personaggio" :cards="availableCharacters" :select="setCharacter"/>
|
||||
<Chooser v-if="hasToChoose" text="Scegli una carta" :cards="chooseCards" :select="chooseCard"/>
|
||||
</transition>
|
||||
</div>
|
||||
</template>
|
||||
@ -55,6 +56,8 @@ export default {
|
||||
distances: {},
|
||||
availableCharacters: [],
|
||||
self: {},
|
||||
hasToChoose: false,
|
||||
chooseCards: [],
|
||||
}),
|
||||
sockets: {
|
||||
room(data) {
|
||||
@ -130,6 +133,27 @@ export default {
|
||||
this.availableCharacters = []
|
||||
this.$socket.emit('set_character', char.name)
|
||||
},
|
||||
choose(player_name) {
|
||||
console.log('choose from' + player_name)
|
||||
let pl = this.players.filter(x=>x.name === player_name)[0]
|
||||
console.log(pl)
|
||||
let arr = []
|
||||
for (let i=0; i<pl.ncards; i++)
|
||||
arr.push({
|
||||
name: 'PewPew!',
|
||||
icon: '💥',
|
||||
is_back: true,
|
||||
})
|
||||
pl.equipment.forEach(x=>arr.push(x))
|
||||
this.chooseCards = arr
|
||||
this.hasToChoose = true
|
||||
},
|
||||
chooseCard(card) {
|
||||
this.$socket.emit('choose', this.chooseCards.indexOf(card))
|
||||
console.log(card + ' ' + this.chooseCards.indexOf(card))
|
||||
this.chooseCards = []
|
||||
this.hasToChoose = false
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
@ -34,6 +34,9 @@ import Chooser from '@/components/Chooser.vue'
|
||||
|
||||
export default {
|
||||
name: 'Player',
|
||||
props: {
|
||||
chooseCardFromPlayer: Function
|
||||
},
|
||||
components: {
|
||||
Card,
|
||||
Chooser,
|
||||
@ -65,6 +68,9 @@ export default {
|
||||
this.lives = self.lives
|
||||
this.max_lives = self.max_lives
|
||||
this.has_played_bang = self.has_played_bang
|
||||
if (this.pending_action == 5) {
|
||||
this.chooseCardFromPlayer(self.target_p)
|
||||
}
|
||||
},
|
||||
self_vis(vis) {
|
||||
console.log('received visibility update')
|
||||
@ -82,7 +88,7 @@ export default {
|
||||
instruction() {
|
||||
if (this.pending_action == null)
|
||||
return ''
|
||||
let x = ['Estrai una carta', 'Pesca le tue carte', 'Gioca le tue carte', 'Rispondi alla carta', 'Attendi']
|
||||
let x = ['Estrai una carta', 'Pesca le tue carte', 'Gioca le tue carte', 'Rispondi alla carta', 'Attendi', 'Scegli una carta']
|
||||
return x[this.pending_action]
|
||||
},
|
||||
canEndTurn() {
|
||||
|
Loading…
Reference in New Issue
Block a user