pick and play end turn
This commit is contained in:
parent
d811058338
commit
a119ce6852
@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import eventlet
|
import eventlet
|
||||||
import socketio
|
import socketio
|
||||||
|
|
||||||
@ -70,5 +71,25 @@ def set_character(sid, name):
|
|||||||
ses = sio.get_session(sid)
|
ses = sio.get_session(sid)
|
||||||
ses.set_character(name)
|
ses.set_character(name)
|
||||||
|
|
||||||
|
@sio.event
|
||||||
|
def refresh(sid):
|
||||||
|
ses = sio.get_session(sid)
|
||||||
|
ses.notify_self()
|
||||||
|
|
||||||
|
@sio.event
|
||||||
|
def draw(sid):
|
||||||
|
ses = sio.get_session(sid)
|
||||||
|
ses.draw()
|
||||||
|
|
||||||
|
@sio.event
|
||||||
|
def end_turn(sid):
|
||||||
|
ses = sio.get_session(sid)
|
||||||
|
ses.end_turn()
|
||||||
|
|
||||||
|
@sio.event
|
||||||
|
def play_card(sid, data):
|
||||||
|
ses = sio.get_session(sid)
|
||||||
|
ses.play_card(data['index'], data['against'])
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
eventlet.wsgi.server(eventlet.listen(('', 5001)), app)
|
eventlet.wsgi.server(eventlet.listen(('', 5001)), app)
|
||||||
|
@ -77,7 +77,7 @@ class Player:
|
|||||||
self.is_my_turn = True
|
self.is_my_turn = True
|
||||||
self.is_waiting_for_action = True
|
self.is_waiting_for_action = True
|
||||||
self.has_played_bang = False
|
self.has_played_bang = False
|
||||||
if any([isinstance(c) == cards.Dinamite or isinstance(c) == cards.Prigione for c in self.equipment]):
|
if any([isinstance(c, cards.Dinamite) or isinstance(c, cards.Prigione) for c in self.equipment]):
|
||||||
self.pending_action = PendingAction.PICK
|
self.pending_action = PendingAction.PICK
|
||||||
else:
|
else:
|
||||||
self.pending_action = PendingAction.DRAW
|
self.pending_action = PendingAction.DRAW
|
||||||
@ -97,7 +97,7 @@ class Player:
|
|||||||
def pick(self):
|
def pick(self):
|
||||||
pickable_cards = 1 + self.character.pick_mod
|
pickable_cards = 1 + self.character.pick_mod
|
||||||
for i in range(len(self.equipment)):
|
for i in range(len(self.equipment)):
|
||||||
if isinstance(self.equipment[i]) == cards.Dinamite:
|
if isinstance(self.equipment[i], cards.Dinamite):
|
||||||
while pickable_cards > 0:
|
while pickable_cards > 0:
|
||||||
pickable_cards -= 1
|
pickable_cards -= 1
|
||||||
picked: cards.Card = self.game.deck.pick_and_scrap()
|
picked: cards.Card = self.game.deck.pick_and_scrap()
|
||||||
@ -108,10 +108,10 @@ class Player:
|
|||||||
print(f'{self.name} Boom, -3 hp')
|
print(f'{self.name} Boom, -3 hp')
|
||||||
else:
|
else:
|
||||||
self.game.next_player().equipment.append(self.equipment.pop(i))
|
self.game.next_player().equipment.append(self.equipment.pop(i))
|
||||||
if any([isinstance(c) == cards.Dinamite or isinstance(c) == cards.Prigione for c in self.equipment]):
|
if any([isinstance(c, cards.Dinamite) or isinstance(c, cards.Prigione) for c in self.equipment]):
|
||||||
return
|
return
|
||||||
for i in range(len(self.equipment)):
|
for i in range(len(self.equipment)):
|
||||||
if isinstance(self.equipment[i]) == cards.Prigione:
|
if isinstance(self.equipment[i], cards.Prigione):
|
||||||
while pickable_cards > 0:
|
while pickable_cards > 0:
|
||||||
pickable_cards -= 1
|
pickable_cards -= 1
|
||||||
picked: cards.Card = self.game.deck.pick_and_scrap()
|
picked: cards.Card = self.game.deck.pick_and_scrap()
|
||||||
@ -128,16 +128,16 @@ class Player:
|
|||||||
playable_cards = []
|
playable_cards = []
|
||||||
for i in range(len(self.hand)):
|
for i in range(len(self.hand)):
|
||||||
card = self.hand[i]
|
card = self.hand[i]
|
||||||
if isinstance(card) == cards.Bang and self.has_played_bang and not any([isinstance(c) == cards.Volcanic for c in self.equipment]):
|
if isinstance(card, cards.Bang) and self.has_played_bang and not any([isinstance(c, cards.Volcanic) for c in self.equipment]):
|
||||||
continue
|
continue
|
||||||
elif isinstance(card) == cards.Birra and self.lives >= self.max_lives:
|
elif isinstance(card, cards.Birra) and self.lives >= self.max_lives:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
playable_cards.append(i)
|
playable_cards.append(i)
|
||||||
return playable_cards
|
return playable_cards
|
||||||
|
|
||||||
def get_public_description(self):
|
def get_public_description(self):
|
||||||
s = f"{self.name} {'Sheriff ⭐️' if isinstance(self.role) == roles.Sheriff else ''} ({self.lives}/{self.max_lives} ⁍) {len(self.hand)} Cards in hand, "
|
s = f"{self.name} {'Sheriff ⭐️' if isinstance(self.role, roles.Sheriff) else ''} ({self.lives}/{self.max_lives} ⁍) {len(self.hand)} Cards in hand, "
|
||||||
s += f"equipment {[str(c) for c in self.equipment]}"
|
s += f"equipment {[str(c) for c in self.equipment]}"
|
||||||
return s
|
return s
|
||||||
|
|
||||||
@ -149,17 +149,22 @@ class Player:
|
|||||||
print(self.name, 'is playing ', card, ' against:', againts)
|
print(self.name, 'is playing ', card, ' against:', againts)
|
||||||
if card.is_equipment and card.name not in [c.name for c in self.equipment]:
|
if card.is_equipment and card.name not in [c.name for c in self.equipment]:
|
||||||
if card.is_weapon:
|
if card.is_weapon:
|
||||||
|
has_weapon = False
|
||||||
for i in range(len(self.equipment)):
|
for i in range(len(self.equipment)):
|
||||||
if self.equipment[i].is_weapon:
|
if self.equipment[i].is_weapon:
|
||||||
self.game.deck.scrap(self.equipment[i])
|
self.game.deck.scrap(self.equipment[i])
|
||||||
self.equipment[i] = card
|
self.equipment[i] = card
|
||||||
|
has_weapon = True
|
||||||
break
|
break
|
||||||
|
if not has_weapon:
|
||||||
|
self.equipment.append(card)
|
||||||
else:
|
else:
|
||||||
self.equipment.append(card)
|
self.equipment.append(card)
|
||||||
else:
|
else:
|
||||||
if isinstance(card) == cards.Bang and self.has_played_bang and not any([isinstance(c) == cards.Volcanic for c in self.equipment]):
|
if isinstance(card, cards.Bang) and self.has_played_bang and not any([isinstance(c, cards.Volcanic) for c in self.equipment]):
|
||||||
print('you retard')
|
print('you retard')
|
||||||
self.game.deck.scrap(card)
|
self.game.deck.scrap(card)
|
||||||
|
self.notify_self()
|
||||||
|
|
||||||
def get_sight(self):
|
def get_sight(self):
|
||||||
aim = 0
|
aim = 0
|
||||||
@ -176,7 +181,10 @@ class Player:
|
|||||||
return self.character.visibility_mod + covers
|
return self.character.visibility_mod + covers
|
||||||
|
|
||||||
def end_turn(self, forced=False):
|
def end_turn(self, forced=False):
|
||||||
|
if not self.is_my_turn: return
|
||||||
if len(self.hand) > self.max_lives and not forced:
|
if len(self.hand) > self.max_lives and not forced:
|
||||||
print(f"I {self.name} have to many cards in my hand and I can't end the turn")
|
print(f"I {self.name} have to many cards in my hand and I can't end the turn")
|
||||||
else:
|
else:
|
||||||
|
self.pending_action = PendingAction.WAIT
|
||||||
|
self.notify_self()
|
||||||
self.game.next_turn()
|
self.game.next_turn()
|
||||||
|
@ -15,6 +15,7 @@ class Sheriff(Role):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__("Sceriffo", "Elimina tutti i Fuorilegge e il Rinnegato!", health_mod=+1)
|
super().__init__("Sceriffo", "Elimina tutti i Fuorilegge e il Rinnegato!", health_mod=+1)
|
||||||
self.max_players = 1
|
self.max_players = 1
|
||||||
|
self.icon = '⭐️'
|
||||||
|
|
||||||
def on_player_death(self, alive_players: list):
|
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]):
|
if not any([isinstance(p.role) == Outlaw or isinstance(p.role) == Renegade for p in alive_players]):
|
||||||
@ -26,6 +27,7 @@ class Vice(Role):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
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!")
|
||||||
self.max_players = 2
|
self.max_players = 2
|
||||||
|
self.icon = '🎖'
|
||||||
|
|
||||||
def on_player_death(self, alive_players: list):
|
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]):
|
if not any([isinstance(p.role) == Outlaw or isinstance(p.role) == Renegade for p in alive_players]):
|
||||||
@ -36,6 +38,7 @@ class Outlaw(Role):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__("Fuorilegge", "Elimina lo Sceriffo!")
|
super().__init__("Fuorilegge", "Elimina lo Sceriffo!")
|
||||||
self.max_players = 3
|
self.max_players = 3
|
||||||
|
self.icon = '🐺'
|
||||||
|
|
||||||
def on_player_death(self, alive_players: list):
|
def on_player_death(self, alive_players: list):
|
||||||
if not any([isinstance(p.role) == Sheriff for p in alive_players]):
|
if not any([isinstance(p.role) == Sheriff for p in alive_players]):
|
||||||
@ -46,6 +49,7 @@ class Renegade(Role):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__("Rinnegato", "Rimani l'ultimo personaggio in gioco!")
|
super().__init__("Rinnegato", "Rimani l'ultimo personaggio in gioco!")
|
||||||
self.max_players = 1
|
self.max_players = 1
|
||||||
|
self.icon = '🦅'
|
||||||
|
|
||||||
def on_player_death(self, alive_players: list):
|
def on_player_death(self, alive_players: list):
|
||||||
if len(alive_players) == 1 and isinstance(alive_players[0]) == Renegade:
|
if len(alive_players) == 1 and isinstance(alive_players[0]) == Renegade:
|
||||||
|
@ -73,7 +73,7 @@ export default {
|
|||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
this.username =(1+Math.random() * 100 % 100).toFixed(2).toString();
|
this.username =(1+Math.random() * 100 % 100).toFixed(2).toString();
|
||||||
this.setUsername();
|
this.setUsername();
|
||||||
}.bind(this), 200)
|
}.bind(this), 1000)
|
||||||
},
|
},
|
||||||
disconnect() {
|
disconnect() {
|
||||||
this.isConnected = false;
|
this.isConnected = false;
|
||||||
@ -132,4 +132,11 @@ h1,h2,h3,h4,p,span{
|
|||||||
right: 0;
|
right: 0;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
.list-enter-active, .list-leave-active {
|
||||||
|
transition: all 0.5s;
|
||||||
|
}
|
||||||
|
.list-enter, .list-leave-to /* .list-leave-active below version 2.1.8 */ {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(30px);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -47,10 +47,13 @@ export default {
|
|||||||
}
|
}
|
||||||
.card.back{
|
.card.back{
|
||||||
color:white;
|
color:white;
|
||||||
background: #987e51;
|
background: repeating-linear-gradient(
|
||||||
}
|
45deg,
|
||||||
.card.back::before{
|
#987e51,
|
||||||
background:red;
|
#987e51 5px,
|
||||||
|
#816b45 5px,
|
||||||
|
#816b45 10px
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
.card.equipment {
|
.card.equipment {
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<div style="position:relative">
|
<div style="position:relative">
|
||||||
<div class="card back" style="position:absolute; bottom:-3pt;right:-2pt;"/>
|
<div class="card back" style="position:absolute; bottom:-3pt;right:-2pt;"/>
|
||||||
<div class="card back" style="position:absolute; bottom:-1pt;right:-1pt;"/>
|
<div class="card back" style="position:absolute; bottom:-1pt;right:-1pt;"/>
|
||||||
<card :card="card" class="back"/>
|
<card :card="card" class="back" @click.native="action"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -26,13 +26,25 @@ export default {
|
|||||||
name: 'PewPew!',
|
name: 'PewPew!',
|
||||||
icon: '💥',
|
icon: '💥',
|
||||||
},
|
},
|
||||||
|
pending_action: false,
|
||||||
}),
|
}),
|
||||||
sockets: {
|
sockets: {
|
||||||
|
self(self){
|
||||||
|
self = JSON.parse(self)
|
||||||
|
this.pending_action = self.pending_action
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
action() {
|
||||||
},
|
if (this.pending_action && this.pending_action < 2) {
|
||||||
|
console.log('action')
|
||||||
|
if (this.pending_action == 0)
|
||||||
|
this.$socket.emit('pick')
|
||||||
|
else if (this.pending_action == 1)
|
||||||
|
this.$socket.emit('draw')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
@ -3,9 +3,10 @@
|
|||||||
<h1>Lobby: {{ lobbyName }}</h1>
|
<h1>Lobby: {{ lobbyName }}</h1>
|
||||||
<h3>Giocatori</h3>
|
<h3>Giocatori</h3>
|
||||||
<div style="display:flex">
|
<div style="display:flex">
|
||||||
<div style="position: relative;width:260pt;height:400pt;">
|
<!-- <div style="position: relative;width:260pt;height:400pt;"> -->
|
||||||
<Card v-for="p in playersTable" v-bind:key="p" :card="p.card" :style="p.style"/>
|
<Card v-for="p in playersTable" v-bind:key="p" :card="p.card"/>
|
||||||
</div>
|
<!-- :style="p.style"/> -->
|
||||||
|
<!-- </div> -->
|
||||||
<Card v-if="startGameCard" :card="startGameCard" @click.native="startGame"/>
|
<Card v-if="startGameCard" :card="startGameCard" @click.native="startGame"/>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="started">
|
<div v-if="started">
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
|
<p v-if="instruction">⏯ {{instruction}}</p>
|
||||||
|
<button v-if="canEndTurn" @click="end_turn">Termina Turno</button>
|
||||||
<div class="equipment-slot">
|
<div class="equipment-slot">
|
||||||
<Card v-if="my_role" :card="my_role" class="back"/>
|
<Card v-if="my_role" :card="my_role" class="back"/>
|
||||||
<Card v-if="character" :card="character"/>
|
<Card v-if="character" :card="character"/>
|
||||||
@ -7,9 +9,13 @@
|
|||||||
<Card v-for="card in equipment" v-bind:key="card.name+card.number" :card="card" />
|
<Card v-for="card in equipment" v-bind:key="card.name+card.number" :card="card" />
|
||||||
</transition-group>
|
</transition-group>
|
||||||
</div>
|
</div>
|
||||||
<div class="hand">
|
<div>
|
||||||
<i>Mano</i>
|
<span>Mano</span>
|
||||||
<Card v-for="card in hand" v-bind:key="card.name+card.number" :card="card" @mouseover.native="hint=card.desc" @mouseleave.native="hint=''"/>
|
<transition-group name="list" tag="div" class="hand">
|
||||||
|
<Card v-for="card in hand" v-bind:key="card.name+card.number" :card="card"
|
||||||
|
@click.native="play_card(card)"
|
||||||
|
@mouseover.native="hint=card.desc" @mouseleave.native="hint=''"/>
|
||||||
|
</transition-group>
|
||||||
</div>
|
</div>
|
||||||
<p>{{hint}}</p>
|
<p>{{hint}}</p>
|
||||||
</div>
|
</div>
|
||||||
@ -31,6 +37,7 @@ export default {
|
|||||||
lives: 0,
|
lives: 0,
|
||||||
max_lives: 0,
|
max_lives: 0,
|
||||||
hint: '',
|
hint: '',
|
||||||
|
pending_action: null
|
||||||
}),
|
}),
|
||||||
sockets: {
|
sockets: {
|
||||||
role(role) {
|
role(role) {
|
||||||
@ -38,7 +45,7 @@ export default {
|
|||||||
},
|
},
|
||||||
self(self) {
|
self(self) {
|
||||||
self = JSON.parse(self)
|
self = JSON.parse(self)
|
||||||
console.log(self)
|
this.pending_action = self.pending_action
|
||||||
this.character = self.character
|
this.character = self.character
|
||||||
this.character.is_character = true
|
this.character.is_character = true
|
||||||
this.hand = self.hand
|
this.hand = self.hand
|
||||||
@ -47,9 +54,36 @@ export default {
|
|||||||
this.max_lives = self.max_lives
|
this.max_lives = self.max_lives
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
computed:{
|
||||||
|
instruction() {
|
||||||
|
if (this.pending_action == null)
|
||||||
|
return ''
|
||||||
|
let x = ['Estrai una carta', 'Pesca le tue carte', 'Gioca le tue carte', 'Rispondi alla carta', 'Attendi']
|
||||||
|
return x[this.pending_action]
|
||||||
|
},
|
||||||
|
canEndTurn() {
|
||||||
|
return (this.pending_action == 2 && this.hand.length <= this.lives)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
methods: {
|
||||||
|
end_turn(){
|
||||||
|
console.log('ending turn')
|
||||||
|
this.$socket.emit('end_turn')
|
||||||
|
},
|
||||||
|
play_card(card) {
|
||||||
|
if (this.pending_action == 2) {
|
||||||
|
let card_data = {
|
||||||
|
index: this.hand.indexOf(card),
|
||||||
|
against: null
|
||||||
|
}
|
||||||
|
console.log(card_data)
|
||||||
|
this.$socket.emit('play_card', card_data)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.$socket.emit('refresh')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@ -62,7 +96,7 @@ export default {
|
|||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
.hand {
|
.hand {
|
||||||
margin-top: 12pt;
|
margin-top: -16pt;
|
||||||
position: relative;
|
position: relative;
|
||||||
display:flex;
|
display:flex;
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
@ -80,6 +114,6 @@ export default {
|
|||||||
}
|
}
|
||||||
.equipment-slot, .equipment-slot>div {
|
.equipment-slot, .equipment-slot>div {
|
||||||
display:flex;
|
display:flex;
|
||||||
margin:0;
|
margin: 10pt 0pt;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
Loading…
Reference in New Issue
Block a user