pick and play end turn

This commit is contained in:
Alberto Xamin 2020-11-20 22:38:55 +01:00
parent d811058338
commit a119ce6852
No known key found for this signature in database
GPG Key ID: 4F026F48309500A2
8 changed files with 118 additions and 28 deletions

View File

@ -1,3 +1,4 @@
import json
import eventlet
import socketio
@ -70,5 +71,25 @@ def set_character(sid, name):
ses = sio.get_session(sid)
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__':
eventlet.wsgi.server(eventlet.listen(('', 5001)), app)

View File

@ -77,7 +77,7 @@ class Player:
self.is_my_turn = True
self.is_waiting_for_action = True
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
else:
self.pending_action = PendingAction.DRAW
@ -97,7 +97,7 @@ class Player:
def pick(self):
pickable_cards = 1 + self.character.pick_mod
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:
pickable_cards -= 1
picked: cards.Card = self.game.deck.pick_and_scrap()
@ -108,10 +108,10 @@ class Player:
print(f'{self.name} Boom, -3 hp')
else:
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
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:
pickable_cards -= 1
picked: cards.Card = self.game.deck.pick_and_scrap()
@ -128,16 +128,16 @@ class Player:
playable_cards = []
for i in range(len(self.hand)):
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
elif isinstance(card) == cards.Birra and self.lives >= self.max_lives:
elif isinstance(card, cards.Birra) and self.lives >= self.max_lives:
continue
else:
playable_cards.append(i)
return playable_cards
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]}"
return s
@ -149,17 +149,22 @@ class Player:
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_weapon:
has_weapon = False
for i in range(len(self.equipment)):
if self.equipment[i].is_weapon:
self.game.deck.scrap(self.equipment[i])
self.equipment[i] = card
has_weapon = True
break
if not has_weapon:
self.equipment.append(card)
else:
self.equipment.append(card)
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')
self.game.deck.scrap(card)
self.notify_self()
def get_sight(self):
aim = 0
@ -176,7 +181,10 @@ class Player:
return self.character.visibility_mod + covers
def end_turn(self, forced=False):
if not self.is_my_turn: return
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")
else:
self.pending_action = PendingAction.WAIT
self.notify_self()
self.game.next_turn()

View File

@ -15,6 +15,7 @@ class Sheriff(Role):
def __init__(self):
super().__init__("Sceriffo", "Elimina tutti i Fuorilegge e il Rinnegato!", health_mod=+1)
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]):
@ -26,6 +27,7 @@ class Vice(Role):
def __init__(self):
super().__init__("Vice", "Proteggi lo Sceriffo! Elimina tutti i Fuorilegge e il Rinnegato!")
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]):
@ -36,6 +38,7 @@ class Outlaw(Role):
def __init__(self):
super().__init__("Fuorilegge", "Elimina lo Sceriffo!")
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]):
@ -46,6 +49,7 @@ class Renegade(Role):
def __init__(self):
super().__init__("Rinnegato", "Rimani l'ultimo personaggio in gioco!")
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:

View File

@ -73,7 +73,7 @@ export default {
setTimeout(function(){
this.username =(1+Math.random() * 100 % 100).toFixed(2).toString();
this.setUsername();
}.bind(this), 200)
}.bind(this), 1000)
},
disconnect() {
this.isConnected = false;
@ -132,4 +132,11 @@ h1,h2,h3,h4,p,span{
right: 0;
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>

View File

@ -47,10 +47,13 @@ export default {
}
.card.back{
color:white;
background: #987e51;
}
.card.back::before{
background:red;
background: repeating-linear-gradient(
45deg,
#987e51,
#987e51 5px,
#816b45 5px,
#816b45 10px
);
}
.card.equipment {

View File

@ -8,7 +8,7 @@
<div style="position:relative">
<div class="card back" style="position:absolute; bottom:-3pt;right:-2pt;"/>
<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>
</template>
@ -26,13 +26,25 @@ export default {
name: 'PewPew!',
icon: '💥',
},
pending_action: false,
}),
sockets: {
self(self){
self = JSON.parse(self)
this.pending_action = self.pending_action
}
},
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>
<style scoped>

View File

@ -3,9 +3,10 @@
<h1>Lobby: {{ lobbyName }}</h1>
<h3>Giocatori</h3>
<div style="display:flex">
<div style="position: relative;width:260pt;height:400pt;">
<Card v-for="p in playersTable" v-bind:key="p" :card="p.card" :style="p.style"/>
</div>
<!-- <div style="position: relative;width:260pt;height:400pt;"> -->
<Card v-for="p in playersTable" v-bind:key="p" :card="p.card"/>
<!-- :style="p.style"/> -->
<!-- </div> -->
<Card v-if="startGameCard" :card="startGameCard" @click.native="startGame"/>
</div>
<div v-if="started">

View File

@ -1,5 +1,7 @@
<template>
<div>
<p v-if="instruction"> {{instruction}}</p>
<button v-if="canEndTurn" @click="end_turn">Termina Turno</button>
<div class="equipment-slot">
<Card v-if="my_role" :card="my_role" class="back"/>
<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" />
</transition-group>
</div>
<div class="hand">
<i>Mano</i>
<Card v-for="card in hand" v-bind:key="card.name+card.number" :card="card" @mouseover.native="hint=card.desc" @mouseleave.native="hint=''"/>
<div>
<span>Mano</span>
<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>
<p>{{hint}}</p>
</div>
@ -31,6 +37,7 @@ export default {
lives: 0,
max_lives: 0,
hint: '',
pending_action: null
}),
sockets: {
role(role) {
@ -38,7 +45,7 @@ export default {
},
self(self) {
self = JSON.parse(self)
console.log(self)
this.pending_action = self.pending_action
this.character = self.character
this.character.is_character = true
this.hand = self.hand
@ -47,9 +54,36 @@ export default {
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>
<style scoped>
@ -62,7 +96,7 @@ export default {
opacity: 0.5;
}
.hand {
margin-top: 12pt;
margin-top: -16pt;
position: relative;
display:flex;
border: 1px solid #ccc;
@ -80,6 +114,6 @@ export default {
}
.equipment-slot, .equipment-slot>div {
display:flex;
margin:0;
margin: 10pt 0pt;
}
</style>