From b2ad5fd75576e664cad41f62a8c0715bff181678 Mon Sep 17 00:00:00 2001 From: Storm dragon Date: Sat, 26 Mar 2016 09:27:32 -0400 Subject: [PATCH] Game is working. Just need to add mor neat stuff to the storm-games module. --- numnastics/numnastics.py | 23 +++++++++-------------- numnastics/storm_games.py | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/numnastics/numnastics.py b/numnastics/numnastics.py index 8582571..2d83f28 100755 --- a/numnastics/numnastics.py +++ b/numnastics/numnastics.py @@ -9,6 +9,7 @@ sounds = initialize_gui("Numnastics") def game(mode): i = 0 + startTime = time.time() tries = 0 numberList = list("123456789") random.shuffle(numberList) @@ -45,25 +46,19 @@ def game(mode): else: i = -1 sounds['error'].play() + endTime = round(time.time() - startTime, 2) + message = [ + "Congratulations! You beat Numnastics in " + str(tries) + " tries.",\ + "Your time was " + str(endTime) + " seconds."] + display_message(message) sounds['win'].play() - speak("solved in " + str(tries) + " tries.") + time.sleep(sounds['win'].get_length()) return "menu" # Game starts at main menu mode = game_menu("start game", "instructions", "credits", "exit_game") while True: - try: - if event.type == pygame.KEYDOWN: - # Escape is the back/exit key, close the game if not playing, or return to menu if playing. - if event.key == pygame.K_ESCAPE: - if mode != "menu": mode = "menu" - if mode == "menu": exit_game() - # Call the game menu, if needed. - if mode == "menu": mode = game_menu("start game", "instructions", "credits", "exit_game") - if mode == "start game": mode = game(mode) - except: - pass -# wait for an event - event = pygame.event.wait() + if mode == "menu": mode = game_menu("start game", "instructions", "credits", "exit_game") + if mode == "start game": mode = game(mode) time.sleep(.001) diff --git a/numnastics/storm_games.py b/numnastics/storm_games.py index c937335..38fa053 100755 --- a/numnastics/storm_games.py +++ b/numnastics/storm_games.py @@ -47,6 +47,23 @@ def initialize_gui(gameTitle): time.sleep(soundData['game-intro'].get_length()) return soundData +def display_message(info): + info.append("Press escape or enter to continue.") + info.reverse() + info.append("Use the up and down arrow keys to navigate this message.") + info.reverse() + i = 0 + speak(str(info[0:len(info)])) + while True: + event = pygame.event.wait() + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_ESCAPE or event.key == pygame.K_RETURN: return + if event.key == pygame.K_DOWN and i < len(info) - 1: i = i + 1 + if event.key == pygame.K_UP and i > 0: i = i - 1 + speak(info[i]) + event = pygame.event.clear() + time.sleep(0.001) + def instructions(): info = ( "Welcome to " + gameName + ": brought to you by Storm Dragon. Use the up and down arrows to navigate these instructions.",\