diff --git a/audio.py b/audio.py index 1a41a2a..11b9037 100644 --- a/audio.py +++ b/audio.py @@ -34,8 +34,12 @@ class Audio: mixer.music.set_volume(0.5) @staticmethod - def stop_background_music(): - mixer.music.stop() + def pause_music(): + mixer.music.pause() + + @staticmethod + def unpause_background_music(): + mixer.music.unpause() @staticmethod def click(): diff --git a/audio/game_success.wav b/audio/game_success.wav deleted file mode 100644 index 6694594..0000000 Binary files a/audio/game_success.wav and /dev/null differ diff --git a/main.py b/main.py index f3cf94d..82e8b34 100644 --- a/main.py +++ b/main.py @@ -60,7 +60,9 @@ try: cards[i].goto(x, y) score = 0 + matches = 0 game_is_running = True + end_routine_done = False clicked_cards = [] def clicked_card(x, y): @@ -70,7 +72,7 @@ try: Audio.click() global clicked_cards for card in cards: - if card.is_mouse_over(x, y): + if card.is_mouse_over(x, y) and card.shape()[:10] != 'card_front': if len(clicked_cards) == 2: clicked_cards = [] card.to_front() @@ -86,6 +88,13 @@ try: while game_is_running: time.sleep(0.1) + if not end_routine_done: + if matches >= 8: + Audio.pause_music() + Audio.game_success() + time.sleep(3.1) + Audio.unpause_background_music() + end_routine_done = True if len(clicked_cards) == 2: if clicked_cards[0] != clicked_cards[1]: time.sleep(1) @@ -98,6 +107,7 @@ try: score += 5 update_score() Audio.match_made() + matches += 1 clicked_cards = [] screen.update()