#!/usr/bin/python3
#Nicholas Roczynski
import random #This imports the random library
from os import system #Imports library so you can clear the screen
dice = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] #List of numbers on the dice of the list
def main(): #Main menu function
print("What would you like to do?") #Asks the user what they want to do in the code
print()
print("1. Play") #Play the game
print("2. Quit") #Quit the game
print("3. How to Play") #Shows user how to play
print()
choice = input(" ==> ") #Your input choice what you wanna do
if choice == "1": #If you type 1...
system("clear") #Screen gets cleared
game() #Brings you to the game function
elif choice == "2": #If you type 2...
system("clear") #Screen gets cleared
print("Thanks for Playing, Goodbye!") #Thank you message
print()
elif choice == "3": #If you type 3...
system("clear") #Screen gets cleared
howToPlay() #Brings you to the "how to play" screen
else: #If the user types ANYTHING else than 1, 2, or 3...
print("Error, please Try Again.") #Error message
system("clear") #Screen gets cleared
main() #Brings you back to the main menu
def howToPlay(): #How to play function
print("To play the game, it's very simple. You must press *Enter* to 'roll'")
print("the dice from 1-20. If you get a bigger number than the computer (your")
print("rival), you win, and your point value increases. Do this for 10 rounds,")
print("and whoever has the most points at the end of the game, wins the whole")
print("thing. If you wanna play again, enter yes on the end screen. If not,")
print("Say no, and you will be brought back to the Main Menu. Play as much as")
print("you want, and have fun!!! :)")
print()
print("Press *Enter* to go back.")
input()
system("clear") #Clears the screen
main() #Brings you back to the main menu
def game(): #Actual game function
user_score = 0 #Your score at the beginning equals 0
cpu_score = 0 #The AI's score at the beginning equals 0, too
for i in range(10): #Entire nested code repeats 10 times
user_dice = random.choice(dice) #User gets dice number at random
cpu_dice = random.choice(dice) #Same goes with the COM
print("Your Score: {}".format(user_score)) #Prints your score
print("Computer's Score: {}".format(cpu_score)) #Prints the computer's score
print()
print("Press *Enter* to Roll the Dice!") #Once pressed, the user and computer will get a random number
input()
system("clear") #Screen gets cleared
print("You got {}".format(user_dice)) #Tells what number you got
print("The Computer got {}".format(cpu_dice)) #Tells what the computer got
print()
if user_dice > cpu_dice: #If your number is bigger than the cpu's
print(" You win!! ") #You win
print("Press *Enter* to Continue")
user_score = user_score + 1 #Your score increases by 1
input()
system("clear") #Screen gets cleared
elif user_dice < cpu_dice: #If your number is smaller than the cpu's
print(" You Lose... ") #You lose
print("Press *Enter* to Continue")
cpu_score = cpu_score + 1 #Computer's score increases by 1
input()
system("clear") #Screen gets cleared
else: #If your number matches the cpu's
print(" It's a tie! ") #It's a tie
print("Press *Enter* to Continue")
input()
system("clear") #Screen gets cleared
if user_score > cpu_score: #If your score is bigger...
print("Your Score: {}".format(user_score)) #Prints your score
print("Computer's Score: {}".format(cpu_score)) #Prints the computer's score
print()
print("Congrats, You Win!!!") #You win!
print()
print("Press *Enter* to Continue.")
input()
system("clear") #Screen gets cleared
end() #Goes to the end screen
elif user_score < cpu_score: #If the computer's score is bigger...
print("Your Score: {}".format(user_score)) #Prints your score
print("Computer's Score: {}".format(cpu_score)) #Prints the computer's score
print()
print("Sorry, the Computer Won...:") #You
print("Better Luck Next Time!") #lose...
print()
print("Press *Enter* to Continue.")
input()
system("clear") #Clears the screen
end() #Goes to the end screen
else: #If it's a tie...
print("Your Score: {}".format(user_score)) #Prints your score
print("Computer's Score: {}".format(cpu_score)) #Prints the computer's score
print()
print("It's a Draw!") #It's a tie
print("Better Luck Next Time!") #Better luck next time
print()
print("Press *Enter* to Continue.")
input()
system("clear") #Screen gets cleared
end() #Goes to the end screen
def end(): #End screen
print("Wanna Play Again?") #Asks the user if they wanna go again
print(" Yes or No?? ") #Yes or no option
print()
end_choice = input(" ==> ") #Your ending choice
if end_choice == "Yes" or end_choice == "yes": #If you wanna play again...
system("clear") #Screen gets cleared
game() #Brings you back to the actual game for round 2
elif end_choice == "No" or end_choice == "no": #If no...
system("clear") #Screen gets cleared
main() #Brings you back to the main menu
else: #If the user types ANTHING ELSE than yes or no...
print("Error, please Try Again") #Error message
input()
system("clear") #Screen gets cleared
end() #Brings you back to the end screen
if __name__ == "__main__": #Runs only if the file is a script or application
print(" Welcome to the Dice Roller!! ")
print()
print("**********************************************")
print()
print(" ~ Press *Enter* to Begin! ~ ")
input()
system("clear") #Screen gets cleared
main() #Brings you to the main menu