Buzzer related events
This commit is contained in:
parent
793d155c78
commit
6fde22965c
@ -36,8 +36,10 @@ def on_join_contestant(data):
|
||||
@socketio.on('buzz')
|
||||
def on_buzz():
|
||||
contestant = session.game.contestants[request.sid]
|
||||
if contestant.locked:
|
||||
if contestant.locked or not session.game.buzzers_armed:
|
||||
return
|
||||
session.game.buzzing_contestant = contestant
|
||||
session.game.buzzers_armed = False
|
||||
emit('contestant-buzzed', {'sid': request.sid}, to=session.room)
|
||||
|
||||
|
||||
@ -63,6 +65,8 @@ def on_activate_clue(data):
|
||||
name = data['name']
|
||||
value = data['value']
|
||||
clues = session.game.categories.get(name)
|
||||
for contestant in session.game.contestants.values():
|
||||
contestant.locked = False
|
||||
if clues:
|
||||
match = None
|
||||
for clue in clues:
|
||||
@ -75,9 +79,28 @@ def on_activate_clue(data):
|
||||
|
||||
@socketio.on('start-clue-clock')
|
||||
def on_start_clue_clock():
|
||||
session.game.buzzers_armed = True
|
||||
emit('clue-clock-on', to=session.room)
|
||||
|
||||
|
||||
@socketio.on('clue-clock-timeout')
|
||||
def on_clue_clock_timeout():
|
||||
if session.game.buzzers_armed:
|
||||
session.game.buzzers_armed = False
|
||||
emit('clue-clock-off', to=session.room)
|
||||
|
||||
|
||||
@socketio.on('contestant-correct')
|
||||
def on_contestant_correct():
|
||||
emit('contestant-scores', to=session.room)
|
||||
|
||||
|
||||
@socketio.on('contestant-incorrect')
|
||||
def on_contestant_incorrect():
|
||||
session.game.buzzing_contestant.locked = True
|
||||
emit('contestant-penalized', to=session.room)
|
||||
|
||||
|
||||
def main():
|
||||
socketio.run(app, host='0.0.0.0', debug=True)
|
||||
|
||||
|
@ -9,11 +9,12 @@ class Game:
|
||||
def __init__(self, code):
|
||||
self.code = code
|
||||
self.locked = False
|
||||
self.players = {}
|
||||
self.contestants = {}
|
||||
self.categories = {}
|
||||
self.buzzers_armed = False
|
||||
|
||||
def add_contestant(self, sid, signature):
|
||||
self.players[sid] = Contestant(signature)
|
||||
self.contestants[sid] = Contestant(signature)
|
||||
|
||||
def load_clues(self):
|
||||
while len(self.categories) < 6:
|
||||
@ -30,7 +31,7 @@ class Game:
|
||||
class Contestant:
|
||||
def __init__(self, signature):
|
||||
self.signature = signature
|
||||
self.points = 0
|
||||
self.locked = False
|
||||
|
||||
|
||||
class Category:
|
||||
|
Loading…
Reference in New Issue
Block a user