def load_game(): try: game = input( "Please choose a game to play:\n" "1. Memory Game - A sequence of number will appear for 1 second,\n" "And you have to guess it back\n" "2. Guess Game - Guess a number and see if you chose like the computer\n" "3. Currency Roulette - Try and guess the value of a random amount of USD in ILS\n" "Please write your number here: ") game = int(game) user_check_game = range_validator(1, 3, game) difficulty = input("\nPlease choose game difficulty from 1 to 5: ") difficulty = int(difficulty) user_check_difficulty = range_validator(1, 5, difficulty) user_check = user_check_game and user_check_difficulty if user_check: end_game1 = play_games(1, game, difficulty, MemoryGame) end_game2 = play_games(2, game, difficulty, GuessGame) end_game3 = play_games(3, game, difficulty, CurrencyRouletteGame) if end_game1 or end_game2 or end_game3: add_score(difficulty, name) return True else: return False else: print("Exit code " + str(bad_return_code)) print("\nYou didn't put the right numbers!", "\n") return False except ValueError as e: print("Exit code " + str(bad_return_code)) print("\nYou have to choose numbers!", e, "\n") return False
def play(difficulty): game_res = False c = CurrencyConverter() curr_rate = c.convert(1, 'USD', 'ILS') rnd_num = random.randint(MIN_NUM, MAX_NUM) print("---------- Amount -------------------------------") print("Amount = " + str(rnd_num) + "$") rnd_amount = round(curr_rate * rnd_num, 2) print(str(rnd_amount) + " ILS") # gwt interval intv = get_money_interval(difficulty, rnd_amount) # ---------------------------------------------------- if len(intv) == 2: while True: # get user guess guess = get_guess_from_user() # check value if float(guess) >= float(intv[0]) and float(guess) <= float(intv[1]): add_score(difficulty) print("You Won! In Interval range...") game_res = True break else: print("Wrong Guess = " + str(guess) + " ... Try again ...") else: print("Unexpected Error....Try Later") # ---------------------------------------------------- return game_res
def play(difficulty): # Generate random list random_list = generate_sequence(difficulty) # Receive player input user_list = get_list_from_user(len(random_list)) # Compare Player input with the random list and continue if player succeed to guess is_succeed = is_list_equal(random_list, list(map(int, user_list))) # Run the player score function with the points to add. add_score(int(is_succeed))
def is_list_equal(guess, generated, difficulty): if guess == generated: print("great memory!") add_score(difficulty) return True else: print("you need to work on that memory") return False
def compare_results(difficulty, secret_number): if secret_number == difficulty: print(True) from Score import add_score print( '-----------------------------------------------------------------------' ) add_score(difficulty) else: print(False)
def load_game(): print_game_list() game_number = get_game_number() game_difficulty = get_game_difficulty() game = GAME_LIST[game_number-1]["name"]() if game.play(game_difficulty): print("You WIN") add_score(game_difficulty) else: print("You LOSE")
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 get_money_interval(difficulty, guess, number): rate = exchange_rate() total = rate * number if int(total) - (5 - int(difficulty)) < int( guess) < int(total) + (5 - int(difficulty)): print("you guessed right") add_score(difficulty) return True else: print("you might have more luck next time") return False
def is_list_equal(list_A, list_B): if list_A == list_B: print('True') difficulty = len(list_A) print( '-----------------------------------------------------------------------' ) add_score(difficulty) else: print('False')
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 load_game(): #ask the user to choose a game try: input_game = ( "Please choose a game to play:\n" "1. Memory Game - a sequence of numbers will appear for 1 second and you have to guess it back\n" "2. Guess Game - guess a number and see if you chose like the computer" ) game_chosen = int(input(input_game)) except: game_chosen = 0 while (game_chosen != 1 and game_chosen != 2): print(ERROR_MESSAGE) try: game_chosen = int(input(input_game)) except: game_chosen = 0 #ask the user to choose the difficulty try: input_difficulty = "Please choose game difficulty from 1 to 5:" difficulty_chosen = int(input(input_difficulty)) except: difficulty_chosen = 0 difficulty_list = [1, 2, 3, 4, 5] while (difficulty_chosen not in difficulty_list): try: print(ERROR_MESSAGE) difficulty_chosen = int( input("Please choose game difficulty from 1 to 5:")) except: difficulty_chosen = 0 #play the MemoryGame if (game_chosen == 1): game_result = MemoryGame.play(difficulty_chosen) if (game_result == True): add_score(difficulty_chosen) print("Well done, your score in this game is: " + str(difficulty_chosen)) else: print("Let's try again") load_game() #play the GuessGame elif (game_chosen == 2): game_result = GuessGame.play(difficulty_chosen) if (game_result == True): add_score(difficulty_chosen) print("Well done, your score is: " + str(difficulty_chosen)) else: print("Let's try again") load_game()
def check_inputs(user_input, difficulty): if user_input != 1 and user_input != 2: print(ERROR_MESSAGE) if difficulty not in [1, 2, 3, 4, 5]: print(ERROR_MESSAGE) if user_input == 1: result = play1(difficulty) if result == True: add_score(difficulty) if user_input == 2: result = play(difficulty) if result == True: add_score(difficulty)
def load_game(): games = [MemoryGame, GuessGame, CurrencyRouletteGame] for i, game in enumerate(games): print("{num}: {description}".format( num=i+1, description=game.get_description())) choise = get_choise(1, len(games)) difficulty = get_choise( min=1, max=5, message="Please choose game difficulty from 1 to 5: ") result = games[choise-1](difficulty).play() if result: add_score(difficulty) print("you Won!") else: print("you lose, try again")
def load_game(): try: game = options_1_to_(3, game_to_play) difficulty = options_1_to_(5, game_difficulty) except EOFError as err: raise EOFError( f'{err}, please enable "-it" flags in "docker run" command' ) from err play_status = GAMES[game - 1](difficulty).play() if play_status: print('lost') else: print('won') add_score(difficulty)
def play(difficulty): # Get random number random_number = generate_number(difficulty) # Get user input user_input = get_guess_from_user(difficulty) print("random number is %d , your guess is %d" % (random_number, user_input)) # Get results comparison result = compare_results(user_input, random_number) # Return True / False if the user lost or won. if result == True: print("True") add_score(difficulty) else: print("False")
def load_game(): memory_mame = Memorygmae() guess_name = Guessgmae() game_id = input( "Please choose a game to play:\n1. Memory Game - a sequence of numbers will appear for 1 second and you have to guess it back\n2. Guess Game - guess a number and see if you chose like the computer\n" ) level = input("Please choose game difficulty from 1 to 5: ") if validate_input(int(game_id), int(level)) == False: return Utils.ERROR_MESSAGE else: win = memory_mame.play(level) if int( game_id) == 1 else guess_name.play(level) print(str(win)) if win == True: add_score(level) else: load_game()
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 play(difficulty): game_res = False secret_number = generate_number(difficulty) print("secret_number = " + str(secret_number)) user_guess = get_guess_from_user(difficulty) print("user_guess = " + str(user_guess)) while True: res_compare = compare_results(secret_number, user_guess) if res_compare == True: add_score(difficulty) print( "********************* You Won !!!!!! ********************************" ) game_res = True break else: print("Please guess again...") user_guess = get_guess_from_user(difficulty) return game_res
def load_game(): flag = True while flag: game = input("""Please choose a game to play: 1. Memory Game - a sequence of numbers will appear for 1 second and you have to guess it back 2. Guess Game - guess a number and see if you chose like the computer 3. Currency Roulette - try and guess the value of a random amount of USD in ILS Your choice: """) is_digit = game.isdigit() if is_digit: game = int(game) if 1 <= game <= 3: flag = False flag = True while flag: difficulty = input("Please choose game difficulty from 1 to 5: ") is_digit = difficulty.isdigit() if is_digit: difficulty = int(difficulty) if 1 <= difficulty <= 5: flag = False game_result = False if game == 1: game_result = MemoryGame.play(difficulty) elif game == 2: game_result = GuessGame.play(difficulty) else: game_result = CurrencyRouletteGame.play(difficulty) if game_result: add_score(difficulty) print("You have won") else: print("You have lost")
def start_game(game, difficulty): if (difficulty < 1 or difficulty > 5): # invalid difficulty input return ERROR_MESSAGE elif game == 1: # user want to play the memory game won = play_memory_game(difficulty) elif game == 2: # user want to play the guess game won = play_guess_game(difficulty) else: # invalid game input return ERROR_MESSAGE if won: # add winning score to the user in case he won the game add_score(difficulty) # NOTE: # according to diagram in the project specification it should call load_game function no mather what the # result. load_game()
def compare_results(guess, number, difficulty): tries = 0 tries += 1 if guess > number: print("guess lower ;)") if guess < number: print("guess higher") while guess != number and tries < 3: guess = int(input("try again: ")) tries += 1 if guess > number: print("guess lower") if guess < number: print("guess higher") if guess == number: print(f"you guessed correctly after {tries} attempts") add_score(difficulty) return True else: print("you lost this game") return False
def load_game(): str = "\nPlease choose a game to play: \n" str += " 1. Memory Game - a sequence of numbers will appear for 1 second and you have to guess it back\n" str += " 2. Guess Game - guess a number and see if you chose like the computer\n" game = input(str) if (game != "1") and (game != "2"): print(Utils.error_message()) return #print(game) difficulty = int(input("\nPlease choose game difficulty from 1 to 5:\n")) if (difficulty < 1) or (difficulty > 5): print(Utils.error_message()) return #print(difficulty) if game == "1": #print("chose memory") answer = MemoryGame.play(difficulty) #print(answer) if answer: print("you won {} points".format(difficulty)) add_score(difficulty) load_game() else: print("you lost") load_game() elif game == "2": #print("chose guess") answer = GuessGame.play(difficulty) #print(answer) if answer: print("you won {} points".format(difficulty)) add_score(difficulty) load_game() else: print("you lost") load_game()
def play(difficulty): game_res = False rnd_list = generate_sequence(int(difficulty)) print(rnd_list) usr_list = get_list_from_user(difficulty) print("Random List : " + str(rnd_list)) print("Your List : " + str(usr_list)) eq_res = is_list_equal(rnd_list, usr_list) if eq_res: add_score(difficulty) print( "********************* You Won !!!!!! ********************************" ) game_res = True else: print("Failed! Try again ...") return game_res
def load_game(): clean_screen() # print header for game selection 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") print("3. Currency Roulette - try and guess the value of a random amount of USD in ILS") print("Enter Selection:") while (True): try: game_slected = int(input()) if ( game_slected <= 3 and game_slected >= 1): break else: raise ValueError() except ValueError: print("Must be a number between 1 to 3 !!") clean_screen() print("Please choose game difficulty from 1 to 5:") print("Enter Selection:") while (True): try: diff = int(input()) if (diff < 1 or diff > 5): os.system('cls') raise ValueError() else: os.system('cls') break except ValueError: print("Must be a number between 1 to 5 !!") if game_slected == 1: memory_game = MemoryGame(diff) if (memory_game.play()): print("Yeeppee... YOU WON") print("Updating score file...") add_score(diff) else: print("Sorry... YOU LOSE") elif game_slected == 2: guess_game = GuessGame(diff) if (guess_game.play()): print("Yeeppee... YOU WON") print("Updating score file...") add_score(diff) else: print("Sorry... YOU LOSE") elif game_slected == 3: currency_game = CurrencyRouletteGame(diff) if (currency_game.play()): print("Yeeppee... YOU WON") print("Updating score file...") add_score(diff) else: print("Sorry... YOU LOSE")
def load_game(): # entry no.1 entry_no_1 = False while entry_no_1 is False: max_value = 4 print("\n" + memory_game_desc + "\n", "\n" + guess_game_desc + "\n", "\n" + cur_game_desc + "\n" + "\n" + exit_desc + "\n") game_id = input("Please choose a game to play:" + "\n") entry_no_1 = input_validator(game_id, max_value) if int(game_id) == 4: exit() # entry no.2 entry_no_2 = False while entry_no_2 is False: max_value = 5 difficulty = input("Please choose game difficulty from 1 to 5: ") entry_no_2 = input_validator(difficulty, max_value) # menu choice = '' choice = int(game_id) if choice == 1: play_memo(int(difficulty)) clear_screen() add_score(difficulty) load_game() elif choice == 2: play_guess(int(difficulty)) clear_screen() add_score(difficulty) load_game() elif choice == 3: play_cur(int(difficulty)) clear_screen() add_score(difficulty) load_game() else: print('something went wrong...choice: ', choice, "type: ", type(choice))
def load_game(): print('\n' + "Please choose a game to play:" + '\n' + "1. Memory Game - a sequence of numbers will appear for 1 second and you have to guess it back" + "\n" + "2. Guess Game - guess a number and see if you chose like the computer. " + '\n' + "3. Currency Roulette - try and guess the value of random amount of USD in ILS." + "\n") chosen_game = int(input("Enter the number of the game here: ")) while chosen_game > 3 or chosen_game < 1: print("Invalid game number") chosen_game = int(input("Choose game number between 1 to 3: ")) difficulty = int(input("Choose game difficulty between 1 to 5: ")) while difficulty > 5 or difficulty < 1: print("invalid difficulty") difficulty = int(input("Choose game difficulty between 1 to 5: ")) try: if chosen_game == 1: win = play_memory_game(difficulty) if win == True: add_score(difficulty) else: print("You did'nt win points on this round ") elif chosen_game == 2: win = play_guess_game(difficulty) if win == True: add_score(difficulty) else: print("You did'nt win points on this round ") elif chosen_game == 3: win = play_currency_game(difficulty) if win == True: add_score(difficulty) else: print("You did'nt win points on this round ") except BaseException as e: print('Error: Game not found') print(e.args)
def load_game(): # Open the main menu, to the game selection # decision : the game number the player choose # difficulty : the number of difficulty the player choose print("""Please choose a game to play: 1. Memory Game - a sequence of numbers will appear for 1 second and you have to guess it back 2. Guess Game - guess a number and see if you chose like the computer 3. Currency Roulette - try and guess the value of a random amount of USD in ILS""" ) while True: try: decision = int(input("Please insert a number between 1 - 3: ")) while 3 < decision or decision < 1: decision = int(input("Please insert a number between 1 - 3: ")) difficulty = int( input('Please choose game difficulty from 1 to 5:')) while 5 < difficulty or difficulty < 1: difficulty = int( input("Please insert a number between 1 - 5: ")) except ValueError: print( "Error: Enter just numbers please, not letters, words ,etc...") continue if decision == 1: # Calling Game number one (Guess game) GuessGame.play(difficulty) if bool(GuessGame) is True: add_score(difficulty=difficulty) if decision == 2: # Calling Game number Two (Memory game) MemoryGame.play(difficulty) if bool(MemoryGame) is True: add_score(difficulty=difficulty) if decision == 3: # Calling Game number Two (CurrencyRoulette Game) CurrencyRouletteGame.play(difficulty) if bool(CurrencyRouletteGame) is True: add_score(difficulty=difficulty) return difficulty, decision
def play(difficulty): guessed_from_user = get_guess_from_user(difficulty) generated_number = generate_number(difficulty) points_to_add = compare_results(generated_number, guessed_from_user) # Run the player score function with the points to add. add_score(int(points_to_add))
from MemoryGame import mgplay from CurrencyRouletteGame import crgpaly from Utils import Screen_cleaner from Score import add_score p_continue = 'y' user_name = "asa" #input('insert your name:') while p_continue == 'y': Screen_cleaner() print(welcome(user_name)) #get game number and level game_number = load_game() game_difficulty = choose_level() if int(game_number)==1: status = ggplay(game_difficulty) elif int(game_number)==2: status = mgplay(game_difficulty) elif int(game_number)==3: status = crgpaly(game_difficulty) #print result and add score if status: add_score(game_difficulty,user_name) print("Great job , you won") else: print("You lost , try again") p_continue = input("do you want to play again y or n ?")
from Live import welcome, load_game from Score import add_score print(welcome("Adi")) game, level = load_game() if game == 1: import MemoryGame game_res = MemoryGame.play(level) if game_res == True: add_score(points=level) print("You Won") else: print("You Lost") elif game == 2: import GuessGame game_res = GuessGame.play(level) if game_res == True: add_score(points=level) print("You Won") else: print("You Lost")