'''
Author: acbart (2/6/2019)
Version: 1
Co-author: Ikken Sakai (6/10/2021)

1. Give a brief description of how the code below works.
   Use plain, accessible language and avoid repeating
   the exact statements from the code. Aim to write at
   least 3 sentences.
   
   The code asks players to input their name. Then, it outputs sentence and their name.
   The computer desides a number of the answer, then, the code asks players to guess and input a number 1 to 10.
   The computer culculate whether the number that player input was same or different with the answer.
   If the number is collect, it shows correct. If it is wrong, the code shows the guessing number was higher or lower.
   
2. Make a modification to the code in some place that changes the game
   in some interesting way. This cannot be as simple as changing the
   MINIMUM or one of the printed messages, but make enough changes and
   they can add up. You might allow the player to play more rounds after
   the first one, or completely change all the messages to have a pirate
   theme, or make it so the player can specify the maximum number.
   Describe your change here clearly and explain why you thought it was
   interesting.
   
   I added 'level 2' on this game and changed maximum and minimum numbers.
   As a result, the difficulity level became high so players probably enjoy it.
   

'''

# Import the randint function generate random integers
from random import randint

# Establish the lower and uppper bound on the goal number
MINIMUM = 1
MAXIMUM = 10
MINIMUM_2 = 1000
MAXIMUM_2 = 9999

def print_welcome_1():
    '''
    Prompt the user for their name, and then display a
    simple message explaining the rules of the game.
    '''
    # Get the name of the user
    name = input("What is your name? ")
    # Show the user's name
    print("Hello", name, "and welcome to my guessing game level 1. There are 2 levels of the game. This is the level 1")
    # Print out the limits of the goal number
    print("I've thought of a number between", MINIMUM, "and", MAXIMUM)
    # Write out rest of the instructions
    print("You need to guess that number.")
    print("I'll tell you if you need to go higher or lower.")
    
def print_welcome_2():
    #This is showed when the player won the level 1
    print("Good job!" "and welcome to my guessing game level 2.")
    print("I've thought of a number between", MINIMUM_2, "and", MAXIMUM_2)
    print("You need to guess that number.")
    print("I'll tell you if you need to go higher or lower.")
def print_ending():
    '''
    Print out a conclusive message to wrap up the game.
    '''
    print("You win!")
    
def process_guess(guess, goal):
    '''
    Print out whether or not the user was above, below,
    or at the goal.
    
    Args:
        guess (int): The number that the user entered
            as their guess.
        goal (int): The number that the computer is
            thinking of.
    '''
    # Branch execution based on whether the guess was right
    if guess < goal:
        print("You need to go higher!")
    elif guess > goal:
        print("You need to go lower!")
    else:
        print("That's correct, it's", goal)
        
def process_guess_2(guess_2, goal_2):
    '''
    Print out whether or not the user was above, below,
    or at the goal.
    
    Args:
        guess (int): The number that the user entered
            as their guess.
        goal (int): The number that the computer is
            thinking of.
    '''
    # Branch execution based on whether the guess was right
    if guess_2 < goal_2:
        print("You need to go higher!")
    elif guess_2 > goal_2:
        print("You need to go lower!")
    else:
        print("That's correct, it's", goal_2)

def get_number():
    '''
    Ask the user for a number, and keep prompting
    them until they give you an actual number
    (as opposed to giving you a letter).
    '''
    # Get the guess from the user, returns a string
    number = input("What is your guess? ")
    # Was the string composed only of numbers?
    if number.isdigit():
        # If so, we can safely convert it to an integer
        number_as_int = int(number)
        # And return the result
        return number_as_int
    else:
        # Otherwise, call this function again recursively
        return get_number()
    
def get_number_2():
    '''
    Ask the user for a number, and keep prompting
    them until they give you an actual number
    (as opposed to giving you a letter).
    '''
    # Get the guess from the user, returns a string
    number_2 = input("What is your guess? ")
    # Was the string composed only of numbers?
    if number_2.isdigit():
        # If so, we can safely convert it to an integer
        number_as_int_2 = int(number_2)
        # And return the result
        return number_as_int_2
    else:
        # Otherwise, call this function again recursively
        return get_number_2()

def main_game():
    '''
    Play a round of the game.
    '''
    # Pick random number between MINIMUM and MAXIMUM
    goal = randint(MINIMUM, MAXIMUM)
    goal_2 = randint(MINIMUM_2, MAXIMUM_2)
    # Initially, the user hasn't guessed anything.
    user_guess = None
    user_guess_2 = None

    print_welcome_1()
    # Repeatedly ask the user until they get it right
    while user_guess != goal:
        user_guess = get_number()
        process_guess(user_guess, goal)
        
    print_welcome_2()
    
    while user_guess_2 != goal_2:
        user_guess_2 = get_number_2()
        process_guess(user_guess_2, goal_2)
    print_ending()

# This if statement is common in most professional Python
#   programs - don't worry too much about what it does,
#   but you can safely assume it will work when you press
#   the run button.
if __name__ == '__main__':
    main_game()