def play(self): _secret = self.generate_sequence() print("secret:", *_secret, end='', flush=True) sleep(0.7) screen_cleaner() guesses = self.get_list_from_user() # return True if lost(nonEqual), False if won(equal) return not self.is_list_equal(guesses, _secret)
def welcome(): screen_cleaner() clear_score() name = input("What is your name? ") # Check if valid name while not all(char.isalpha() for char in name) or not len(name) > 1: name = input("That ain't no name. What's your real name? ") return "Hello " + name.capitalize() + " and welcome to the World of Games(WOG).\n\
def generate_sequence(difficulty): random_list = [] for i in range(difficulty): random_number = (random.randint(1, 101)) random_list.append(random_number) print(random_list) time_sleep(0.7) screen_cleaner() return random_list
def generate_sequence(difficulty): random_list = [0] * difficulty for i in range(len(random_list)): number = random.randint(1, 101) random_list[i] = number print(random_list) time.sleep(0.7) screen_cleaner() return random_list
def is_list_equal(list_a, list_b): if list_a == list_b: print("You won") return 1 else: print("You Lost") print("\n") time.sleep(3) screen_cleaner() return 0
def play_again(): answer = "" while answer != "yes" or answer != "no": answer = input("Would you like to play another game? (type yes or no) ") if answer == "yes": screen_cleaner() return True elif answer == "no": print("Thank you for playing.") return False
def play_memory(difficulty): print(f"""welcome to the Memory Game i will display {difficulty} numbers for 1 seconds and you will have to remember them in the correct order. get ready!""") for x in range(0, 5): # will display loading for 5 second for the user to prepare b = "Loading" + "." * x print(b, end="\r") time.sleep(1) screen_cleaner() is_list_equal(generate_sequence(difficulty), get_list_from_user(difficulty), difficulty)
def generate_sequence(difficulty): lst = [] for i in range(1,difficulty+1): rand_num = random.randint(1,101) lst.append(str(rand_num)) print(lst) time.sleep(0.7) from Utils import screen_cleaner screen_cleaner() return lst
def play(difficulty): print("Hello and welcome to Memory Game!\n" "In this game you need to memorize a list of numbers and remember them\n" "Pay attention we are about to start in 5 seconds!") time.sleep(5) screen_cleaner() end_game = max_retries(main_game, difficulty=difficulty) if end_game: return True else: return False
def generate_sequence(difficulty): import random list_a = [] for x in range(difficulty): list_a.append(random.randint(1, 101)) print(*list_a, sep=" ") import time time.sleep(0.7) from Utils import screen_cleaner screen_cleaner() return list_a
def generate_sequence(difficulty): seed_val = randint(1, 10) seed(seed_val) gen_list = arr.array("i", []) for i in range(difficulty): rand_num = randint(1, 101) gen_list.append(rand_num) print(*gen_list, sep=", ") time.sleep(0.7) screen_cleaner() return gen_list
def play(difficulty): list_a = generate_sequence(difficulty) print(list_a) time.sleep(0.7) screen_cleaner() list_b = get_list_from_user(difficulty) if is_list_equal(list_a, list_b) == True: print("True") add_score(difficulty) else: print("False")
def play(difficulty): num = generate_number(difficulty) guess = get_guess_from_user(difficulty) result = compare_results(guess, num) # Will return 1 to let the Live script knows user won, else will return 0 if result == 1: return 1 else: print("The number was", num, "\n") time.sleep(3) screen_cleaner() return 0
def welcome(): global name name = input("Please enter your name: ") if not (name.isdigit() or name == "\n"): screen_cleaner() name = name.upper() print("Hello %s and welcome to the World of Games (WoG)!\n" "Here you can find many cool games to play.\n" % name) return True else: print("Exit code " + str(bad_return_code)) print("Your name is not valid!\n") return False
def main_game(difficulty): generated_list = generate_sequence(difficulty) for num in range(0, int(difficulty)): print("number in place " + str(num + 1) + " is: " + str(generated_list[num])) time.sleep(0.7) screen_cleaner() user_check, user_list = get_list_from_user(difficulty) if not user_check: user_answer = is_list_equal(generated_list, user_list, difficulty) if not user_answer: print("Your memory is great! All " + str(difficulty) + " are correct!" + "\nYou Won!\nGoodBay!") time.sleep(3) return True else: return False
def play(difficulty): """ This Method will Start the game. :param difficulty: user difficulty :return: True if user won or False if user lost """ computer_mem_list = generate_sequence(difficulty) print(computer_mem_list) time.sleep(0.7) screen_cleaner() user_mem_list = get_list_from_user(difficulty) if is_list_equal(computer_mem_list, user_mem_list): return True else: return False
def generate_sequence(difficulty): # generate a new list of random numbers numbers = [] show = '' while len(numbers) < difficulty: n = random.randint(1, 101) numbers.append(n) # build display text if len(show) > 0: show += ' ' show += str(n) # show cards print(show) # hide cards time.sleep(0.7) screen_cleaner() return numbers
def play(difficulty): """ A. Will get a number variable named difficulty B. Will call the functions above and play the game. C. Will return True / False if the user lost or won (based on is_list_equal()). :param difficulty: :return: True / False if the user lost or won """ print("===================== welcome to the memory game =====================") print("you need to remember a sequence of numbers that the computer will show") print("======================================================================") generated_list = generate_sequence(difficulty) print("After seeing the numbers, enter the numbers you saw, each one separated withEnter.") print(generated_list) time.sleep(0.7) screen_cleaner() user_list = get_list_from_user(difficulty) return is_list_equal(user_list, generated_list)
def play(self): """ Prints a welcome message, and runs the memory game- presents the user with a list of numbers between 1 and MAX_VALUE, with the length of difficulty. The list vanishes after SLEEP_TIME seconds, and user needs to try and recall all items in the list :return: If player won the game or not :rtype: bool """ print(""" Welcome to _| _| _|_|_| _|_| _|_| _|_| _|_|_| _|_| _|_| _| _|_| _| _| _| _|_|_| _|_|_| _|_| _|_| _| _| _| _|_|_|_| _| _| _| _| _| _|_| _| _| _| _|_| _| _| _| _| _| _|_|_|_| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _|_|_| _| _| _| _|_| _| _|_|_| _|_|_| _|_|_| _| _| _| _|_|_| _| _|_| """) generated_list = self.generate_sequence() print( f"You will be presented with a list of {self.difficulty} numbers on the screen, for {SLEEP_TIME} seconds. " f"Please memorize this list.") sleep(2) for second in range(5, 0, -1): print(f"The list will be presented in {second}", end='\r') sleep(1) print("Here: ") print(generated_list, end='\r') sleep(SLEEP_TIME) screen_cleaner() user_guessed_list = self.get_list_from_user() game_won = self.is_list_equal(user_guessed_list, generated_list) if game_won: print("Wow, you're amazing! You guessed the two lists perfectly!") else: print(f"Sorry mate, the list was actually {generated_list}") return game_won
def main(): screen_cleaner() print(f""" Welcome to the _ __ __ __ ____ | | / /___ _____/ /___/ / ____ / __/ ____ _____ _____ ___ ___ _____ | | /| / / __ \/ ___/ / __ / / __ \/ /_ / __ `/ __ `/ __ `__ \/ _ \/ ___/ | |/ |/ / /_/ / / / / /_/ / / /_/ / __/ / /_/ / /_/ / / / / / / __(__ ) |__/|__/\____/_/ /_/\__,_/ \____/_/ \__, /\__,_/_/ /_/ /_/\___/____/ /____/ """) print(welcome("Tsahhi")) go_for_play = True while go_for_play: game_index, difficulty = load_game() if game_index == 1: game_to_play = MemoryGame elif game_index == 2: game_to_play = GuessGame else: game_to_play = CurrencyRouletteGame won_the_game = game_to_play(difficulty).play() if won_the_game: add_score(difficulty) print("Way to go, you winner! dare for another round?") else: print("Better luck next time- want to take this time right now?") continue_str = "Please enter Y or N: " should_continue = input(continue_str).lower().strip() valid_options = ['y', 'n'] while should_continue not in valid_options: should_continue = input(continue_str).lower().strip() go_for_play = should_continue == 'y' print("Thank you for playing in the World of Games!")
def load_game(): print("Please choose a game to play:") print( "1. Memory Game - a sequence of numbers will appear for 1 second and you have to guess it back \n" ) print( "2. Guess Game - guess a number and see if you chose like the computer \n" ) while True: selection = input("Select which game you'd like to play: ") try: #Checking value is an integer if int(selection) == 1: from MemoryGame import play diff = input("Please choose game difficulty from 1 to 5: ") if int(diff) > 5 or int( diff) < 1: #Checking value not crossing 1-5 screen_cleaner() print(error) result = 0 else: result = play(int(diff)) elif int(selection) == 2: from GuessGame import play diff = input("Please choose game difficulty from 1 to 5: ") if int(diff) > 5 or int( diff) < 1: #Checking value not crossing 1-5 screen_cleaner() print(error) result = 0 else: result = play(int(diff)) else: screen_cleaner() print(error) result = 0 except ValueError: print("You've inserted a non integer value, please try again \n") continue else: break # Selected game will return 1 in order to update score. else will return 0 to intiate the reload game. if result == 1: add_score(int(diff)) return 1 # Will return 1 to finish the game w/o reload. else: return 0
def generate_sequence(difficulty): random_list = random.sample(range(1, 101), difficulty) print(random_list) time.sleep(0.7) screen_cleaner() return random_list
def play(self, difficulty): self.generate_sequence(difficulty) print(self.numbers_list) time.sleep(0.7) screen_cleaner() return is_list_equal(self.numbers_list, get_list_from_user(difficulty))
def generate_sequence(difficulty): random_numbers = [random.randrange(1, 101) for i in range(difficulty)] print(random_numbers) time.sleep(0.7) screen_cleaner() return random_numbers
def load_game(): print("Please choose a game to play:") print( "1. Memory Game - a sequence of numbers will appear for 1 second and you have to guess it back" ) print( "2. Guess Game - guess a number and see if you chose like the computer" ) game_number = input("Choose: 1 or 2: ") game_difficulty = 0 try: game_difficulty = int( input("Please choose game difficulty from 1 to 5: ")) except ValueError: print("You can only put numbers 1-5") if game_difficulty < 1 or game_difficulty > 5: return error_message() if game_number == '1': print("Play memory Game") # Load the mem game. (MemeoryGame.py --> play(difficulty) # i call it play_mem (import play as play_mem) to differentiate between two functions with the same name # if the user wan the game, play function to return true. if play_mem(game_difficulty) == True: add_score(game_difficulty) if end_game_decision() == True: screen_cleaner() load_game() else: print("You lost this time...") time_sleep(7) screen_cleaner() if end_game_decision() == True: screen_cleaner() load_game() elif game_number == '2': print("Play guess Game") # will call the guess game (GuessGamy.py --> play(difficulty) ) and check if wan if play(game_difficulty) == True: add_score(game_difficulty) if end_game_decision() == True: screen_cleaner() load_game() else: print("You lost this time...") time_sleep(4) screen_cleaner() if end_game_decision() == True: screen_cleaner() load_game() else: # if user entered game number different from 1/2 print("You can choose only Number 1 or 2") return error_message()
def generate_sequence(difficulty): generate_list = random.sample(range(1, 101), difficulty) print(generate_list) screen_cleaner() return generate_list
def show_sequence(x): print(x) sleep(0.7) screen_cleaner()
from Live import load_game, welcome from Utils import screen_cleaner from Utils import run_flask screen_cleaner() # Clean screen on new game print(welcome("Ziv")) load_game() # run_flask() # Rise web server to show game scores
# MainGame.py from Live import load_game, welcome from Utils import screen_cleaner from MainScores import score_server gamer_name = str(input("Please enter your name: ")) screen_cleaner() print(welcome(gamer_name)) load_game() score_server()