sid ketchum
This commit is contained in:
parent
4ba53b2589
commit
abff5e0500
@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
from typing import List
|
||||||
import eventlet
|
import eventlet
|
||||||
import socketio
|
import socketio
|
||||||
|
|
||||||
@ -10,7 +11,7 @@ app = socketio.WSGIApp(sio, static_files={
|
|||||||
'/': {'content_type': 'text/html', 'filename': 'index.html'}
|
'/': {'content_type': 'text/html', 'filename': 'index.html'}
|
||||||
})
|
})
|
||||||
|
|
||||||
games = []
|
games: List[Game] = []
|
||||||
|
|
||||||
def advertise_lobbies():
|
def advertise_lobbies():
|
||||||
sio.emit('lobbies', room='lobby', data=[{'name': g.name, 'players': len(g.players)} for g in games if not g.started])
|
sio.emit('lobbies', room='lobby', data=[{'name': g.name, 'players': len(g.players)} for g in games if not g.started])
|
||||||
@ -39,6 +40,8 @@ def disconnect(sid):
|
|||||||
|
|
||||||
@sio.event
|
@sio.event
|
||||||
def create_room(sid, room_name):
|
def create_room(sid, room_name):
|
||||||
|
while len([g for g in games if g.name == room_name]):
|
||||||
|
room_name += '_1'
|
||||||
sio.leave_room(sid, 'lobby')
|
sio.leave_room(sid, 'lobby')
|
||||||
sio.enter_room(sid, room_name)
|
sio.enter_room(sid, room_name)
|
||||||
g = Game(room_name, sio)
|
g = Game(room_name, sio)
|
||||||
@ -53,6 +56,8 @@ def join_room(sid, room_name):
|
|||||||
sio.leave_room(sid, 'lobby')
|
sio.leave_room(sid, 'lobby')
|
||||||
sio.enter_room(sid, room_name)
|
sio.enter_room(sid, room_name)
|
||||||
i = [g.name for g in games].index(room_name)
|
i = [g.name for g in games].index(room_name)
|
||||||
|
while len([p for p in games[i].players if p.name == sio.get_session(sid).name]):
|
||||||
|
sio.get_session(sid).name += '_1'
|
||||||
games[i].add_player(sio.get_session(sid))
|
games[i].add_player(sio.get_session(sid))
|
||||||
advertise_lobbies()
|
advertise_lobbies()
|
||||||
|
|
||||||
|
@ -87,6 +87,10 @@ class Player:
|
|||||||
def notify_self(self):
|
def notify_self(self):
|
||||||
if self.lives <= 0 and self.max_lives > 0:
|
if self.lives <= 0 and self.max_lives > 0:
|
||||||
print('dying, attacker', self.attacker)
|
print('dying, attacker', self.attacker)
|
||||||
|
if isinstance(self.character, characters.SidKetchum) and len(self.hand) > 1:
|
||||||
|
self.lives += 1
|
||||||
|
self.game.deck.scrap(self.hand.pop(randrange(0, len(self.hand))))
|
||||||
|
self.game.deck.scrap(self.hand.pop(randrange(0, len(self.hand))))
|
||||||
self.game.player_death(self)
|
self.game.player_death(self)
|
||||||
if isinstance(self.character, characters.CalamityJanet):
|
if isinstance(self.character, characters.CalamityJanet):
|
||||||
self.expected_response = [cards.Mancato(0,0).name, cards.Bang(0,0).name]
|
self.expected_response = [cards.Mancato(0,0).name, cards.Bang(0,0).name]
|
||||||
@ -109,7 +113,8 @@ class Player:
|
|||||||
|
|
||||||
def play_turn(self):
|
def play_turn(self):
|
||||||
if self.lives == 0:
|
if self.lives == 0:
|
||||||
self.end_turn(forced=True)
|
return self.end_turn(forced=True)
|
||||||
|
self.scrapped_cards = 0
|
||||||
self.sio.emit('chat_message', room=self.game.name, data=f'È il turno di {self.name}.')
|
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')
|
print(f'I {self.name} was notified that it is my turn')
|
||||||
self.was_shot = False
|
self.was_shot = False
|
||||||
@ -463,6 +468,10 @@ class Player:
|
|||||||
|
|
||||||
def scrap(self, card_index):
|
def scrap(self, card_index):
|
||||||
if self.is_my_turn or isinstance(self.character, characters.SidKetchum):
|
if self.is_my_turn or isinstance(self.character, characters.SidKetchum):
|
||||||
|
self.scrapped_cards += 1
|
||||||
|
if isinstance(self.character, characters.SidKetchum) and self.scrapped_cards == 2:
|
||||||
|
self.scrapped_cards = 0
|
||||||
|
self.lives = min(self.lives+1, self.max_lives)
|
||||||
self.game.deck.scrap(self.hand.pop(card_index))
|
self.game.deck.scrap(self.hand.pop(card_index))
|
||||||
self.notify_self()
|
self.notify_self()
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
<input type="submit" />
|
<input type="submit" />
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<Lobby :username="username" v-else/>
|
<Lobby v-show="isInLobby" :username="username" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="center-stuff">
|
<div v-else class="center-stuff">
|
||||||
@ -83,6 +83,9 @@ export default {
|
|||||||
},
|
},
|
||||||
lobbies(data) {
|
lobbies(data) {
|
||||||
this.openLobbies = data;
|
this.openLobbies = data;
|
||||||
|
},
|
||||||
|
room() {
|
||||||
|
this.isInLobby = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -102,13 +105,11 @@ export default {
|
|||||||
createLobby(e) {
|
createLobby(e) {
|
||||||
if (this.lobbyName.trim().length > 0) {
|
if (this.lobbyName.trim().length > 0) {
|
||||||
this.$socket.emit('create_room', this.lobbyName)
|
this.$socket.emit('create_room', this.lobbyName)
|
||||||
this.isInLobby = true;
|
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
},
|
},
|
||||||
joinLobby(lobby) {
|
joinLobby(lobby) {
|
||||||
this.$socket.emit('join_room', lobby.name)
|
this.$socket.emit('join_room', lobby.name)
|
||||||
this.isInLobby = true;
|
|
||||||
},
|
},
|
||||||
init() {
|
init() {
|
||||||
location.reload();
|
location.reload();
|
||||||
|
@ -161,6 +161,7 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
end_turn(){
|
end_turn(){
|
||||||
console.log('ending turn')
|
console.log('ending turn')
|
||||||
|
this.cancelEndingTurn()
|
||||||
this.$socket.emit('end_turn')
|
this.$socket.emit('end_turn')
|
||||||
},
|
},
|
||||||
scrap(c) {
|
scrap(c) {
|
||||||
@ -251,7 +252,7 @@ export default {
|
|||||||
}
|
}
|
||||||
.hand>.card:hover {
|
.hand>.card:hover {
|
||||||
margin-right:35pt;
|
margin-right:35pt;
|
||||||
margin-top:-0.5pt;
|
transform: translateY(-15px);
|
||||||
}
|
}
|
||||||
.equipment-slot {
|
.equipment-slot {
|
||||||
display:flex;
|
display:flex;
|
||||||
|
Loading…
Reference in New Issue
Block a user