Last active
May 7, 2021 22:31
-
-
Save linnnegan/7c5bf8f0313a1218a4e6f57778f68d2e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sense_hat import SenseHat | |
| import time | |
| import random | |
| sense = SenseHat() | |
| #declare color tuples | |
| r = (255,0,0) | |
| w = (255,255,255) | |
| k = (0,0,0) | |
| no_arrow = [ | |
| w,w,w,w,w,w,w,w, | |
| w,w,w,w,w,w,w,w, | |
| w,w,w,w,w,w,w,w, | |
| w,w,w,w,w,w,w,w, | |
| w,w,w,w,w,w,w,w, | |
| w,w,w,w,w,w,w,w, | |
| w,w,w,w,w,w,w,w, | |
| w,w,w,w,w,w,w,w | |
| ] | |
| left_arrow =[ | |
| w,w,w,w,w,w,w,w, | |
| w,w,r,w,w,w,w,w, | |
| w,r,r,w,w,w,w,w, | |
| r,r,r,r,r,r,r,w, | |
| w,r,r,w,w,w,w,w, | |
| w,w,r,w,w,w,w,w, | |
| w,w,w,w,w,w,w,w, | |
| w,w,w,w,w,w,w,w | |
| ] | |
| right_arrow =[ | |
| w,w,w,w,w,w,w,w, | |
| w,w,w,w,w,r,w,w, | |
| w,w,w,w,w,r,r,w, | |
| w,r,r,r,r,r,r,r, | |
| w,w,w,w,w,r,r,w, | |
| w,w,w,w,w,r,w,w, | |
| w,w,w,w,w,w,w,w, | |
| w,w,w,w,w,w,w,w | |
| ] | |
| down_arrow =[ | |
| w,w,w,w,w,w,w,w, | |
| w,w,w,r,w,w,w,w, | |
| w,w,w,r,w,w,w,w, | |
| w,w,w,r,w,w,w,w, | |
| w,w,w,r,w,w,w,w, | |
| w,r,r,r,r,r,w,w, | |
| w,w,r,r,r,w,w,w, | |
| w,w,w,r,w,w,w,w | |
| ] | |
| up_arrow =[ | |
| w,w,w,r,w,w,w,w, | |
| w,w,r,r,r,w,w,w, | |
| w,r,r,r,r,r,w,w, | |
| w,w,w,r,w,w,w,w, | |
| w,w,w,r,w,w,w,w, | |
| w,w,w,r,w,w,w,w, | |
| w,w,w,r,w,w,w,w, | |
| w,w,w,r,w,w,w,w | |
| ] | |
| #list of arrows | |
| arrows = ["up", "right", "down", "left"] | |
| current_pattern = [] | |
| player_pattern = [] | |
| player_turn = False | |
| run_game = True | |
| level = 1 | |
| #variable to hold level | |
| def next_level(): | |
| global player_turn, level, current_pattern, player_pattern | |
| # | |
| player_pattern = [] | |
| current_pattern = [] | |
| sense.show_message(str(level)) | |
| for i in range(level + 2): | |
| current_pattern.append(random.choice(arrows)) | |
| for arrow in current_pattern: | |
| if arrow == "left": | |
| sense.set_pixels(left_arrow) | |
| elif arrow == "right": | |
| sense.set_pixels(right_arrow) | |
| elif arrow == "up": | |
| sense.set_pixels(up_arrow) | |
| else: | |
| sense.set_pixels(down_arrow) | |
| time.sleep(0.5) | |
| sense.set_pixels(no_arrow) | |
| time.sleep(0.5) | |
| level += level | |
| player_turn = True | |
| # sense.show_letter("?",text_colour = (0,255,0)) | |
| #################### | |
| def submit_guess(): | |
| global player_pattern, current_pattern, player_turn | |
| if current_pattern == player_pattern: | |
| sense.show_message("LEVEL CLEARED", text_colour = r, back_colour = w, scroll_speed = 0.05) | |
| player_turn = False | |
| else: | |
| sense.show_message("GAME OVER") | |
| player_pattern = [] | |
| next_level() | |
| while True: | |
| if player_turn == True: | |
| sense.show_letter("?") | |
| for event in sense.stick.get_events(): | |
| print(event.direction, event.action) | |
| if event.action == "pressed" and event.direction != "middle": | |
| player_pattern.append(event.direction) | |
| if event.action == "released" and event.direction == "middle": | |
| print("current: " + str(current_pattern)) | |
| print("player: " + str(player_pattern)) | |
| submit_guess() | |
| print("player_turn" + str(player_turn)) | |
| else: | |
| next_level() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment