Game is playable now.
This commit is contained in:
parent
3dd751cd99
commit
c07beea0d8
@ -9,6 +9,7 @@ sounds = initialize_gui("Numnastics")
|
|||||||
|
|
||||||
def game(mode):
|
def game(mode):
|
||||||
i = 0
|
i = 0
|
||||||
|
tries = 0
|
||||||
numberList = list("123456789")
|
numberList = list("123456789")
|
||||||
random.shuffle(numberList)
|
random.shuffle(numberList)
|
||||||
while ''.join(numberList) != "123456789":
|
while ''.join(numberList) != "123456789":
|
||||||
@ -22,28 +23,36 @@ def game(mode):
|
|||||||
elif mode == "menu": exit_game()
|
elif mode == "menu": exit_game()
|
||||||
elif event.key in [pygame.K_1, pygame.K_2, pygame.K_3, pygame.K_4, pygame.K_5, pygame.K_6,pygame.K_7, pygame.K_8, pygame.K_9]:
|
elif event.key in [pygame.K_1, pygame.K_2, pygame.K_3, pygame.K_4, pygame.K_5, pygame.K_6,pygame.K_7, pygame.K_8, pygame.K_9]:
|
||||||
i = numberList.index((pygame.key.name(event.key)))
|
i = numberList.index((pygame.key.name(event.key)))
|
||||||
|
speak(numberList[i])
|
||||||
elif event.key in [pygame.K_LEFT, pygame.K_UP]:
|
elif event.key in [pygame.K_LEFT, pygame.K_UP]:
|
||||||
if i > 0: i = i - 1
|
if i > 0: i = i - 1
|
||||||
|
speak(numberList[i])
|
||||||
elif event.key in [pygame.K_RIGHT, pygame.K_DOWN]:
|
elif event.key in [pygame.K_RIGHT, pygame.K_DOWN]:
|
||||||
if i < len(numberList) - 1: i = i + 1
|
if i < len(numberList) - 1: i = i + 1
|
||||||
|
speak(numberList[i])
|
||||||
elif event.key == pygame.K_SPACE:
|
elif event.key == pygame.K_SPACE:
|
||||||
speak(str(' '.join(numberList[i:len(numberList)])))
|
speak(str(' '.join(numberList[i:len(numberList)])))
|
||||||
continue
|
continue
|
||||||
else:
|
elif event.key == pygame.K_RETURN:
|
||||||
i = -1
|
|
||||||
sounds['error'].play()
|
|
||||||
if i != -1:
|
if i != -1:
|
||||||
reversedNumberList = numberList[i:len(numberList)]
|
reversedNumberList = numberList[i:len(numberList)]
|
||||||
reversedNumberList.reverse()
|
reversedNumberList.reverse()
|
||||||
del numberList[i:len(numberList)]
|
del numberList[i:len(numberList)]
|
||||||
numberList.extend(reversedNumberList)
|
numberList.extend(reversedNumberList)
|
||||||
|
tries = tries + 1
|
||||||
|
sounds['flip'].play()
|
||||||
|
speak(str(' '.join(numberList[i:len(numberList)])))
|
||||||
|
else:
|
||||||
|
i = -1
|
||||||
|
sounds['error'].play()
|
||||||
|
sounds['win'].play()
|
||||||
|
speak("solved in " + str(tries) + " tries.")
|
||||||
|
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:
|
||||||
# wait for an event
|
try:
|
||||||
event = pygame.event.wait()
|
|
||||||
# if the event is about a keyboard button that have been pressed...
|
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
# Escape is the back/exit key, close the game if not playing, or return to menu if playing.
|
# 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 event.key == pygame.K_ESCAPE:
|
||||||
@ -52,5 +61,9 @@ while True:
|
|||||||
# Call the game menu, if needed.
|
# Call the game menu, if needed.
|
||||||
if mode == "menu": mode = game_menu("start game", "instructions", "credits", "exit_game")
|
if mode == "menu": mode = game_menu("start game", "instructions", "credits", "exit_game")
|
||||||
if mode == "start game": mode = game(mode)
|
if mode == "start game": mode = game(mode)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
# wait for an event
|
||||||
|
event = pygame.event.wait()
|
||||||
time.sleep(.001)
|
time.sleep(.001)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user