Merge branch 'dev' into main
This commit is contained in:
commit
ed6610176e
@ -10,6 +10,7 @@ from players import Player
|
||||
sio = socketio.Server(cors_allowed_origins="*")
|
||||
app = socketio.WSGIApp(sio, static_files={
|
||||
'/': {'content_type': 'text/html', 'filename': 'index.html'},
|
||||
'/favicon.ico': {'filename': 'favicon.ico'},
|
||||
'/css': './css',
|
||||
'/js': './js',
|
||||
})
|
||||
@ -53,7 +54,7 @@ def disconnect(sid):
|
||||
@sio.event
|
||||
def create_room(sid, room_name):
|
||||
while len([g for g in games if g.name == room_name]):
|
||||
room_name += '_1'
|
||||
room_name += f'_{random.randint(0,100)}'
|
||||
sio.leave_room(sid, 'lobby')
|
||||
sio.enter_room(sid, room_name)
|
||||
g = Game(room_name, sio)
|
||||
@ -78,7 +79,7 @@ def join_room(sid, room):
|
||||
sio.leave_room(sid, 'lobby')
|
||||
sio.enter_room(sid, 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'
|
||||
sio.get_session(sid).name += f'_{random.randint(0,100)}'
|
||||
games[i].add_player(sio.get_session(sid))
|
||||
advertise_lobbies()
|
||||
|
||||
@ -91,6 +92,7 @@ def chat_message(sid, msg):
|
||||
def start_game(sid):
|
||||
ses = sio.get_session(sid)
|
||||
ses.game.start_game()
|
||||
advertise_lobbies()
|
||||
|
||||
@sio.event
|
||||
def set_character(sid, name):
|
||||
|
@ -1,7 +1,7 @@
|
||||
from typing import List, Set, Dict, Tuple, Optional
|
||||
from abc import ABC, abstractmethod
|
||||
from enum import IntEnum
|
||||
|
||||
import roles as r
|
||||
|
||||
class Suit(IntEnum):
|
||||
DIAMONDS = 0 # ♦
|
||||
@ -41,8 +41,28 @@ class Card(ABC):
|
||||
return f'{self.name} {char}{self.number}'
|
||||
return super().__str__()
|
||||
|
||||
def play_card(self, player, against):
|
||||
contro = f'contro {against}' if against else ''
|
||||
def play_card(self, player, against):#self --> carta
|
||||
if self.is_equipment:
|
||||
if self.is_weapon:
|
||||
has_weapon = False
|
||||
for i in range(len(player.equipment)):
|
||||
if player.equipment[i].is_weapon:
|
||||
player.game.deck.scrap(player.equipment[i])
|
||||
player.equipment[i] = self
|
||||
has_weapon = True
|
||||
break
|
||||
if not has_weapon:
|
||||
player.equipment.append(self)
|
||||
elif self.name in [c.name for c in player.equipment if not isinstance(c, Dinamite)]:
|
||||
for i in range(len(player.equipment)):
|
||||
print('tipo',type(self))
|
||||
if type(player.equipment[i]) == type(self):
|
||||
player.game.deck.scrap(self.equipment[i])
|
||||
player.equipment[i] = self
|
||||
break
|
||||
else:
|
||||
player.equipment.append(self)
|
||||
contro = f' contro {against}' if against else ''
|
||||
player.sio.emit('chat_message', room=player.game.name,
|
||||
data=f'{player.name} ha giocato {self.name}{contro}.')
|
||||
return True
|
||||
@ -83,6 +103,13 @@ class Prigione(Card):
|
||||
self.desc = "Equipaggia questa carta a un altro giocatore, tranne lo Sceriffo. Il giocatore scelto all'inizio del suo turno, prima di pescare dovrà estrarre: se esce Cuori scarta questa carta e gioca normalmente il turno, altrimenti scarta questa carta e salta il turno"
|
||||
self.need_target = True
|
||||
|
||||
def play_card(self, player, against):
|
||||
if against != None and not isinstance(player.game.get_player_named(against).role, r.Sheriff):
|
||||
player.sio.emit('chat_message', room=player.game.name,
|
||||
data=f'{self.name} ha giocato {self.name} contro {against}.')
|
||||
player.game.get_player_named(against).equipment.append(self)
|
||||
player.game.get_player_named(against).notify_self()
|
||||
return False
|
||||
|
||||
class Remington(Card):
|
||||
def __init__(self, suit, number):
|
||||
@ -170,7 +197,7 @@ class CatBalou(Card):
|
||||
self.need_target = True
|
||||
|
||||
def play_card(self, player, against):
|
||||
if against != None:
|
||||
if against != None and (len(player.game.get_player_named(against).hand) + len(player.game.get_player_named(against).equipment)) > 0:
|
||||
super().play_card(player, against=against)
|
||||
from players import PendingAction
|
||||
player.pending_action = PendingAction.CHOOSE
|
||||
@ -272,7 +299,7 @@ class Panico(Card):
|
||||
self.desc = "Pesca una carta da un giocatore a distanza 1, scegli a caso dalla mano, oppure fra quelle che ha in gioco"
|
||||
|
||||
def play_card(self, player, against):
|
||||
if against != None:
|
||||
if against != None and (len(player.game.get_player_named(against).hand) + len(player.game.get_player_named(against).equipment)) > 0:
|
||||
super().play_card(player, against=against)
|
||||
from players import PendingAction
|
||||
player.pending_action = PendingAction.CHOOSE
|
||||
|
@ -160,7 +160,7 @@ class Player:
|
||||
randrange(0, len(self.game.get_player_named(pile).hand))))
|
||||
self.game.get_player_named(pile).notify_self()
|
||||
self.sio.emit('chat_message', room=self.game.name,
|
||||
data=f'{self.name} ha pescato la prima carta dalla mano di {self.attacker.name}.')
|
||||
data=f'{self.name} ha pescato la prima carta dalla mano di {pile}.')
|
||||
self.hand.append(self.game.deck.draw())
|
||||
else:
|
||||
for i in range(2):
|
||||
@ -251,32 +251,8 @@ class Player:
|
||||
return
|
||||
card: cs.Card = self.hand.pop(hand_index)
|
||||
print(self.name, 'is playing ', card, ' against:', against)
|
||||
if isinstance(card, cs.Prigione) and not isinstance(self.game.get_player_named(against).role, r.Sheriff):
|
||||
self.sio.emit('chat_message', room=self.game.name,
|
||||
data=f'{self.name} ha giocato {card.name} contro {against}.')
|
||||
self.game.get_player_named(against).equipment.append(card)
|
||||
self.game.get_player_named(against).notify_self()
|
||||
elif card.is_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)
|
||||
elif card.name in [c.name for c in self.equipment if not isinstance(c, cs.Dinamite)]:
|
||||
for i in range(len(self.equipment)):
|
||||
if type(self.equipment[i]) == type(card):
|
||||
self.game.deck.scrap(self.equipment[i])
|
||||
self.equipment[i] = card
|
||||
break
|
||||
else:
|
||||
self.equipment.append(card)
|
||||
else:
|
||||
did_play_card = card.play_card(self, against)
|
||||
if not card.is_equipment:
|
||||
if did_play_card:
|
||||
self.game.deck.scrap(card)
|
||||
else:
|
||||
@ -431,6 +407,7 @@ class Player:
|
||||
else:
|
||||
self.on_failed_response_cb()
|
||||
self.game.responders_did_respond_resume_turn()
|
||||
if self.mancato_needed <= 0:
|
||||
self.attacker = None
|
||||
|
||||
def get_sight(self, countWeapon=True):
|
||||
|
@ -75,7 +75,7 @@ class Renegade(Role):
|
||||
return True
|
||||
elif initial_players == 3 and attacker_role != None:
|
||||
return isinstance(dead_role, Outlaw) and isinstance(attacker_role, Renegade)
|
||||
elif initial_players != 3 and len(alive_players) == 1 and isinstance(alive_players[0], Renegade):
|
||||
elif initial_players != 3 and len(alive_players) == 1 and isinstance(alive_players[0].role, Renegade):
|
||||
print("The Renegade won!")
|
||||
return True
|
||||
return False
|
||||
|
@ -3,8 +3,8 @@
|
||||
<div style="flex-grow: 4;">
|
||||
<h2 v-if="!started">Lobby: {{ lobbyName }}</h2>
|
||||
<h3>Giocatori (tu sei {{username}})</h3>
|
||||
<div v-if="!started" >
|
||||
<PrettyCheck v-if="isRoomOwner" class="p-switch p-fill" v-model="privateRoom">Stanza Privata</PrettyCheck>
|
||||
<div v-if="!started">
|
||||
<PrettyCheck v-if="isRoomOwner" class="p-switch p-fill" v-model="privateRoom" style="margin-top:5px; margin-bottom:3px;">Stanza Privata</PrettyCheck>
|
||||
<label v-if="password !== ''">Password: <b class="selectable" style="font-size:larger;">{{ password }}</b></label>
|
||||
</div>
|
||||
|
||||
|
@ -5,7 +5,7 @@ Vue.config.productionTip = false
|
||||
import VueSocketIO from 'vue-socket.io'
|
||||
Vue.use(new VueSocketIO({
|
||||
debug: Vue.config.devtools,
|
||||
connection: Vue.config.devtools ? 'http://localhost:5001' : window.location.origin,
|
||||
connection: Vue.config.devtools ? `http://${window.location.hostname}:5001` : window.location.origin,
|
||||
}))
|
||||
|
||||
import PrettyCheckbox from 'pretty-checkbox-vue';
|
||||
|
Loading…
Reference in New Issue
Block a user