Game is working. Just need to add mor neat stuff to the storm-games module.

This commit is contained in:
Storm dragon 2016-03-26 09:27:32 -04:00
parent dccdfc988d
commit b2ad5fd755
2 changed files with 26 additions and 14 deletions

View File

@ -9,6 +9,7 @@ sounds = initialize_gui("Numnastics")
def game(mode): def game(mode):
i = 0 i = 0
startTime = time.time()
tries = 0 tries = 0
numberList = list("123456789") numberList = list("123456789")
random.shuffle(numberList) random.shuffle(numberList)
@ -45,25 +46,19 @@ def game(mode):
else: else:
i = -1 i = -1
sounds['error'].play() 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() sounds['win'].play()
speak("solved in " + str(tries) + " tries.") time.sleep(sounds['win'].get_length())
return "menu" return "menu"
# Game starts at main menu # Game starts at main menu
mode = game_menu("start game", "instructions", "credits", "exit_game") mode = game_menu("start game", "instructions", "credits", "exit_game")
while True: while True:
try: if mode == "menu": mode = game_menu("start game", "instructions", "credits", "exit_game")
if event.type == pygame.KEYDOWN: if mode == "start game": mode = game(mode)
# 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()
time.sleep(.001) time.sleep(.001)

View File

@ -47,6 +47,23 @@ def initialize_gui(gameTitle):
time.sleep(soundData['game-intro'].get_length()) time.sleep(soundData['game-intro'].get_length())
return soundData 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(): def instructions():
info = ( info = (
"Welcome to " + gameName + ": brought to you by Storm Dragon. Use the up and down arrows to navigate these instructions.",\ "Welcome to " + gameName + ": brought to you by Storm Dragon. Use the up and down arrows to navigate these instructions.",\