Skip to content

Commit 43f7b06

Browse files
committed
Sound effects for wrong answer and everybody is wrong
1 parent 8fc525b commit 43f7b06

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

config.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ beep_command: beep
2323
#pygame specific options
2424
player_buzzed: ./audio/buzz2.wav
2525
wrong_answer: ./audio/wrong.wav
26+
all_wrong: ./audio/hi-ho.wav

game_audio.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,30 @@
1313
class _NoAudio(object):
1414
def beep_for_player(self, i):
1515
return
16+
def everybody_wrong(self):
17+
return
18+
def wrong(self):
19+
return
1620

1721
class _PygameAudio(_NoAudio):
1822
def __init__(self):
1923
pygame.mixer.init()
2024
buzz_path = config.get("audio", "player_buzzed")
2125
wrong_answer_path = config.get("audio", "wrong_answer")
26+
everybody_wrong_path = config.get("audio","all_wrong")
2227

2328
self.player_buzz = pygame.mixer.Sound(buzz_path)
2429
self.wrong_answer = pygame.mixer.Sound(wrong_answer_path)
30+
self.all_wrong = pygame.mixer.Sound(everybody_wrong_path)
2531

2632
def beep_for_player(self, i):
27-
if i > 0:
28-
self.player_buzz.play()
29-
else: #host buzzer
30-
self.wrong_answer.play()
33+
self.player_buzz.play()
34+
35+
def wrong(self):
36+
self.wrong_answer.play()
37+
38+
def everybody_wrong(self):
39+
self.all_wrong.play()
3140

3241
class _BeepAudio(_NoAudio):
3342
def __init__(self, beep_command):
@@ -44,6 +53,9 @@ def beep_for_player(self, i):
4453
else self.beep_table[i])
4554
system("%s -r %s -l %s -f %s" % (self.beep_command, r, l, f))
4655

56+
def everybody_wrong(self):
57+
self.beep_for_player(-1)
58+
4759
def command_exists(cmd):
4860
return any(exists(join(pth, cmd))
4961
for pth in getenv('PATH').split(':'))

jeopardy.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,13 @@ def run_buzzin_attempts(
230230

231231
# everything below here is state != QUESTION_PRE_BUZZ
232232
# thanks to continue above
233-
234-
audio.beep_for_player(buzzed_in_player_id)
235-
236233
if buzzed_in_player_id == NOBODY_BUZZED:
237234
# Make sure players have had some time to answer first
238235
if time.time() - state_start_time > MIN_QUESTION_TIME:
236+
audio.everybody_wrong()
239237
state = QUESTION_EVERYBODY_WRONG
240238
else: # else a real player
239+
audio.beep_for_player(buzzed_in_player_id)
241240
players_allowed.remove(buzzed_in_player_id)
242241
state = QUESTION_WAIT_ANSWER
243242
else:
@@ -254,11 +253,12 @@ def run_buzzin_attempts(
254253
adjust_score_and_save(
255254
buzzed_in_player_id, answered_questions, player_names,
256255
scores, -question_score)
257-
258256
# if all the players have had a chance
259257
if len(players_allowed) == 1:
258+
audio.everybody_wrong()
260259
state = QUESTION_EVERYBODY_WRONG
261260
else:
261+
audio.wrong()
262262
state = QUESTION_BUZZ_OPEN_AFTER_WRONG
263263

264264
if previous_state != state:

0 commit comments

Comments
 (0)