Created
March 17, 2021 11:59
-
-
Save matdziu/962cbbac5216678bb8d224dfbb0eee71 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
| import random | |
| import time | |
| import matplotlib.image as mpimg | |
| import matplotlib.pyplot as plt | |
| class Level: | |
| def start(self): | |
| pass | |
| class ImagePuzzleLevel(Level): | |
| def start(self): | |
| print("Close the image to continue...") | |
| image = mpimg.imread("puzzleimage.png") | |
| plt.imshow(image) | |
| plt.axis("off") | |
| plt.show() | |
| answer = input("What is the answer? ") | |
| if answer == "island": | |
| print("Correct!") | |
| return True | |
| else: | |
| print("Wrong :(") | |
| return False | |
| # level1 = ImagePuzzleLevel() | |
| # level1.start() | |
| class QuizLevel(Level): | |
| def start(self): | |
| questions_with_correct_answers = {"What is the capital of Russia?": "Moscow", | |
| "What is the capital of Poland?": "Warsaw", | |
| "What is the capital of France?": "Paris", | |
| "What is the capital of Italy?": "Rome"} | |
| score = 0 | |
| for question, correct_answer in questions_with_correct_answers.items(): | |
| answer = input(question) | |
| if answer == correct_answer: | |
| score += 1 | |
| if score == len(questions_with_correct_answers): | |
| print("You passed!") | |
| return True | |
| else: | |
| print("You failed :(") | |
| return False | |
| # level2 = QuizLevel() | |
| # level2.start() | |
| class MemoryLevel(Level): | |
| def start(self): | |
| print("Remember all these numbers: ") | |
| numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] | |
| picked_numbers = [] | |
| while len(picked_numbers) < 5: | |
| picked_numbers.append(random.choice(numbers)) | |
| print(picked_numbers) | |
| time.sleep(5) | |
| self.__clear() | |
| answer = [] | |
| while len(answer) < 5: | |
| answer_number = input("Type a number: ") | |
| answer.append(int(answer_number)) | |
| if answer == picked_numbers: | |
| print("Correct!") | |
| return True | |
| else: | |
| print("Wrong :(") | |
| return False | |
| def __clear(self): | |
| for i in range(0, 100): | |
| print("\n") | |
| # level3 = MemoryLevel() | |
| # level3.start() | |
| class GuessWordsLevel(Level): | |
| def start(self): | |
| print("Guess the word by filling the missing letter:") | |
| words_to_guess = ["bird", "dog", "table", "garden", "computer"] | |
| score = 0 | |
| for word in words_to_guess: | |
| blank_letter = random.choice(word) | |
| word_with_blank = word.replace(blank_letter, "_") | |
| answer = input(f"{word_with_blank}: ") | |
| if answer == word: | |
| score += 1 | |
| if score == len(words_to_guess): | |
| print("You passed!") | |
| return True | |
| else: | |
| print("You failed :(") | |
| return False | |
| # level4 = GuessWordsLevel() | |
| # level4.start() | |
| class DoYouFeelLuckyLevel(Level): | |
| def start(self): | |
| coin = ["heads", "tails"] | |
| result_of_coin_flip = random.choice(coin) | |
| user_choice = input("Heads or tails? ") | |
| if result_of_coin_flip == user_choice: | |
| print("You won!") | |
| return True | |
| else: | |
| print("You lost :(") | |
| return False | |
| # level5 = DoYouFeelLuckyLevel() | |
| # level5.start() | |
| level1 = ImagePuzzleLevel() | |
| level2 = QuizLevel() | |
| level3 = MemoryLevel() | |
| level4 = GuessWordsLevel() | |
| level5 = DoYouFeelLuckyLevel() | |
| levels = [level1, level2, level3, level4, level5] | |
| print("Win every level to win the game. Good luck!") | |
| game_score = 0 | |
| for level in levels: | |
| success = level.start() | |
| if success: | |
| game_score += 1 | |
| if game_score == len(levels): | |
| print("Congratulations! You passed my annoying little game!") | |
| else: | |
| print("You failed. Try again :(") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment