0% found this document useful (0 votes)
190 views

Discreteproject

This document contains code for a Python program that allows users to play mini-games or get food in a virtual "Fun House". It includes functions for welcoming the user, displaying food/drink menus to purchase items within a $12 budget, and playing the game of Rock Paper Scissors against a computer opponent by randomly generating moves.

Uploaded by

api-728810835
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
190 views

Discreteproject

This document contains code for a Python program that allows users to play mini-games or get food in a virtual "Fun House". It includes functions for welcoming the user, displaying food/drink menus to purchase items within a $12 budget, and playing the game of Rock Paper Scissors against a computer opponent by randomly generating moves.

Uploaded by

api-728810835
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

DiscreteProject

March 3, 2024

[ ]: import random
from words import words
from hangman_visual import lives_visual_dict
import string

def WelcomeFunc():
print('\n')
print('Hello!!!')
print("Welcome to Taylor's Fun House!!!")
print("This Fun House gives you the option to play some of the best mini␣
↪games ever created and eat some great food!!")

print('First option of the Fun House is deciding if you would like to go␣
↪eat or play games!')

print("When selecting the game you want to play, next to it, it will have␣
↪(vs. CPU or vs. USER) CPU being computer and USER being against another␣

↪player")

print("Just make sure you pick the one thats best for you!!")
print("Each game will have its own rules and instrunctions upon entering␣
↪each one")

print("CAUTION: COMPUTER DOES NOT TAKE IT EASY ON THESE GAMES")


print("Enter at your own cost.....")
print('\n')
print("Please select an option (1-3)")
print('1. Food')
print('2. Games')
print('3. Exit')
num = input('Enter your value: ')
if num == '1':
FoodMenu()
elif num == '2':
Full_Game()
elif num == '3':
print("Thank you for coming, please come again soon!!!")
exit()
else:
print('Please enter a valid choice')

1
def FoodMenu():
print('\n')
print("Welcome to the Buffet at Taylor's Fun House!!!")
print("A menu will be presented to you, choose a drink, a main meal and␣
↪desert")

print("Remember you have $12 total to start, make sure you dont go over it!
↪")

print('\n')
print('---HERE IS OUR DRINK MENU---')
print('----------------------')
print('DRINKS: ')
print('1. Water $1.00 ')
print('2. Soda $2.50 ')
print('3. Coffee $2.00 ')
print('4. Tea $2.00 ')
print('5. Juice $2.00 ')
print('Please enter a number (1-5) of what drink you would like')
drink_choice = int(input("Drink Selection: "))
drink_var = ""
while drink_choice > 5 or drink_choice < 1:
drink_choice = int(input("You have entered a invalid option. Enter␣
↪valid input: "))

if drink_choice == 1:
print('You have selected: Water')
drink_bill = 1.00
print ("Total Bill: $ " + str(drink_bill))
drink_var = "Water"
elif drink_choice == 2:
print('You have selected: Soda')
drink_bill = 2.50
print ("Total Bill: $ " + str(drink_bill))
drink_var = "Soda"
elif drink_choice == 3:
print('You have selected: Coffee')
drink_bill = 2.00
print ("Total Bill: " + str(drink_bill))
drink_var = "Coffee"
elif drink_choice == 4:
print('You have selected: Tea')
drink_bill = 2.00
print ("Total Bill: " + str(drink_bill))
drink_var = "Tea"
elif drink_choice == 5:

2
print('You have selected: Juice')
drink_bill = 2.00
print ("Total Bill: " + str(drink_bill))
drink_var = "Juice"
else:
print("Please enter a valid input")

print('\n')
print('----------------------')
print('---HERE IS OUR FOOD MENU---')
print('FOOD: ')
print('1. Chicken Tenders $7.00 ')
print('2. Cheeseburger $8.50 ')
print('3. Pizza $6.00 ')
print('4. Mac and Cheese $5.50 ')
print('5. French Fries $3.00 ')
print('6. Salad $5.00 ')
print('7. Grilled Cheese $5.00 ' )
food_choice = int(input("Food Selection: "))
food_var = ""
while food_choice > 7 or food_choice < 1:
food_choice = int(input("You have entered a invalid option. Enter valid␣
↪input: "))

if food_choice == 1:
print('You have selected: Chicken Tenders')
food_bill = 7.00
total_bill = food_bill + drink_bill
print ("Total Bill: $ " + str(total_bill))
food_var = "Chicken Tenders"
elif food_choice == 2:
print('You have selected: Cheeseburger')
food_bill = 8.50
total_bill = food_bill + drink_bill
print ("Total Bill: $ " + str(total_bill))
food_var = "Cheeseburger"
elif food_choice == 3:
print('You have selected: Pizza')
food_bill = 6.00
total_bill = food_bill + drink_bill
print ("Total Bill: $ " + str(total_bill))
food_var = "Pizza"
elif food_choice == 4:
print('You have selected: Mac and Cheese')
food_bill = 5.50
total_bill = food_bill + drink_bill
print ("Total Bill: $ " + str(total_bill))

3
food_var = "Mac and Cheese"
elif food_choice == 5:
print('You have selected: French Fries')
food_bill = 3.00
total_bill = food_bill + drink_bill
print ("Total Bill: $ " + str(total_bill))
food_var = "French Fries"
elif food_choice == 6:
print('You have selected: Salad')
food_bill = 5.00
total_bill = food_bill + drink_bill
print ("Total Bill: $ " + str(total_bill))
food_var = "Salad"
elif food_choice == 7:
print('You have selected: Grilled Cheese')
food_bill = 5.00
total_bill = food_bill + drink_bill
print ("Total Bill: $ " + str(total_bill))
food_var = "Grilled Cheese"
else:
print("Please enter a valid input")

print('\n')
print('----------------------')
print('---HERE IS OUR DESSERT MENU---')
print('DESSERT: ')
print('1. Cake $4.00 ')
print('2. Cupcake $2.50 ')
print('3. Ice Cream $2.00 ')
print('4. Pie $2.00 ')
dessert_choice = int(input("Dessert Selection: "))
while dessert_choice > 7 or dessert_choice < 1:
dessert_choice = int(input("You have entered a invalid option. Enter␣
↪valid input: "))

if dessert_choice == 1:
print('You have selected: Cake')
dessert_bill = 4.00
total_bill = food_bill + drink_bill + dessert_bill
dessert_var = "Cake"
print ("Total Bill: $ " + str(total_bill))
elif dessert_choice == 2:
print('You have selected: Cupcake')
dessert_bill = 2.50
total_bill = food_bill + drink_bill + dessert_bill
print ("Total Bill: $ " + str(total_bill))
dessert_var = "Cupcake"

4
elif dessert_choice == 3:
print('You have selected: Ice Cream')
dessert_bill = 2.00
total_bill = food_bill + drink_bill + dessert_bill
print ("Total Bill: $ " + str(total_bill))
dessert_var = "Ice Cream"
elif dessert_choice == 4:
print('You have selected: Pie')
dessert_bill = 2.00
total_bill = food_bill + drink_bill + dessert_bill
print ("Total Bill: $ " + str(total_bill))
dessert_var = "Pie"
else:
print("Please enter a valid input")

print('\n')
print('----------------------')
if total_bill > 12:
print("You have exceded your funds, please start over. Remember you␣
↪only have $12!")

print('----------------------')
FoodMenu()
else:
print("HORRAYYY! You have successfully purchased everything withtin␣
↪your funds! ENJOY!!")

print('Would you like to go play games now?')


print("1. YES")
print("2. NO")
main_choice = int(input("User selection (1-2): "))
if main_choice == 1:
Full_Game()
elif main_choice == 2:
print("Thanks for coming!!")
exit()
else:
print("Please enter a valid input")

"""
print('\n')
print('----------------------')
print("You have selected: ")

print("Drink: ") (drink_var)


print("Food: ") (food_var)
print("Dessert: ") (dessert_var)

5
print("Total Cost: ") + str(total_bill)
if total_bill > 15:
print("You have exceded your funds, please start over. Remember you␣
↪only have $15!")

FoodMenu()
else:
print("HORRAYYY! You have successfully purchased everything withtin␣
↪your funds! ENJOY!!")

print('Would you like to go play games now?')


"""

def RPS():
print('\n')
print('Hello!!! Welcome to the game of Rock Paper Scissors!')
print('PROCEDURE:')
print('1. First, the game will start by the user getting the chance to pick␣
↪an option among rock paper and scissors')

print('2. After that, the computer will select a choice (randomly) from the␣
↪other two')

print('3. The winner is then annoucned per the winning rules')


print('\n')

print('Winning Rules as follows :')

print('Rock vs Paper-> Paper wins')


print('Rock vs Scissor-> Rock wins')
print('Paper vs Scissor-> Scissor wins')

while True:
print("Enter choice: \n 1. for Rock \n 2. for Paper \n 3. for Scissor␣
↪\n")

# take the input from user


choice = int(input("User turn: "))

# looping until user enter invalid input


while choice > 3 or choice < 1:
choice = int(input("Enter valid input: "))

6
# initialize value of choice_name variable
# corresponding to the choice value
if choice == 1:
choice_name = 'Rock'
elif choice == 2:
choice_name = 'Paper'
else:
choice_name = 'Scissor'

print("User choice is: " + choice_name)


print("\nNow its computer turn.......")

comp_choice = random.randint(1, 3)

while comp_choice == choice:


comp_choice = random.randint(1, 3)

# variable corresponding to the choice value


if comp_choice == 1:
comp_choice_name = 'Rock'
elif comp_choice == 2:
comp_choice_name = 'Paper'
else:
comp_choice_name = 'Scissor'

print("Computer choice is: " + comp_choice_name)

print(choice_name + " V/s " + comp_choice_name)

# condition for winning


if((choice == 1 and comp_choice == 2) or
(choice == 2 and comp_choice ==1 )):
print("Paper Wins => ", end = "")
result = "Paper"

elif((choice == 1 and comp_choice == 3) or


(choice == 3 and comp_choice == 1)):
print("Rock Wins =>", end = "")
result = "Rock"
else:
print("Scissor Wins =>", end = "")
result = "Scissor"

# Printing either user or computer wins


if result == choice_name:
print("<== USER WINS ==>")

7
else:
print("<== COMPUTER WINS ==>")

print("Do you want to play again? (Y/N)")


ans = input()

# if user input n or N then condition is True


if ans == 'n' or ans == 'N':
break

print("\nThanks for playing")

def print_tic_tac_toe(values):
print("\n")
print("\t | |")
print("\t {} | {} | {}".format(values[0], values[1], values[2]))
print('\t_____|_____|_____')

print("\t | |")
print("\t {} | {} | {}".format(values[3], values[4], values[5]))
print('\t_____|_____|_____')

print("\t | |")

print("\t {} | {} | {}".format(values[6], values[7], values[8]))


print("\t | |")
print("\n")

# Function to print the score-board


def print_scoreboard(score_board):
print("\t--------------------------------")
print("\t SCOREBOARD ")
print("\t--------------------------------")

players = list(score_board.keys())
print("\t ", players[0], "\t ", score_board[players[0]])
print("\t ", players[1], "\t ", score_board[players[1]])

print("\t--------------------------------\n")

8
# Function to check if any player has won
def check_win(player_pos, cur_player):

soln = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 4, 7], [2, 5, 8], [3, 6, 9],␣
↪[1, 5, 9], [3, 5, 7]]

for x in soln:
if all(y in player_pos[cur_player] for y in x):
return True
return False

# Function to check if the game is drawn


def check_draw(player_pos):
if len(player_pos['X']) + len(player_pos['O']) == 9:
return True
return False

# Function for a single game of Tic Tac Toe


def single_game(cur_player):

# Represents the Tic Tac Toe


values = [' ' for x in range(9)]

# Stores the positions occupied by X and O


player_pos = {'X':[], 'O':[]}

# Game Loop for a single game of Tic Tac Toe


while True:
print_tic_tac_toe(values)

try:
print("Player ", cur_player, " turn. Which box? : ", end="")
move = int(input())
except ValueError:
print("Wrong Input!!! Try Again")
continue
if move < 1 or move > 9:
print("Wrong Input!!! Try Again")
continue

if values[move-1] != ' ':


print("Place already filled. Try again!!")
continue

values[move-1] = cur_player

9
player_pos[cur_player].append(move)

# Function call for checking win


if check_win(player_pos, cur_player):
print_tic_tac_toe(values)
print("Player ", cur_player, " has won the game!!")
print("\n")
return cur_player

# Function call for checking draw game


if check_draw(player_pos):
print_tic_tac_toe(values)
print("Game Drawn")
print("\n")
return 'D'

# Switch player moves


if cur_player == 'X':
cur_player = 'O'
else:
cur_player = 'X'

def TTToe():
print('\n')
print('----------------------')
print('Hello!!! Welcome to the game of Tic-Tac-Toe!!!')
print("You will be playing against another USER, make sure to enter the␣
↪names when asked")

print("One will select X and one will select O")


print("The tic tac toe board has numbers representing each spot")
print("The numbers start at 1 in the top left, going right it would be 2␣
↪and 3, then straight down from the top left which is 1, the box below is 4.")

print("You then keep counting in that left to right pattern for the rest of␣
↪the boxes")

print("Input what number you want to take as your box and then you're off!!!
↪")

print("HAVE FUN!")

print("Player 1")
player1 = input("Enter the name : ")
print("\n")

10
print("Player 2")
player2 = input("Enter the name : ")
print("\n")

# Stores the player who chooses X and O


cur_player = player1

# Stores the choice of players


player_choice = {'X' : "", 'O' : ""}

# Stores the options


options = ['X', 'O']

# Stores the scoreboard


score_board = {player1: 0, player2: 0}
print_scoreboard(score_board)

# Game Loop for a series of Tic Tac Toe


while True:

print("Turn to choose for", cur_player)


print("Enter 1 for X")
print("Enter 2 for O")
print("Enter 3 to Quit")

try:
choice = int(input())
except ValueError:
print("Wrong Input!!! Try Again\n")
continue
if choice == 1:
player_choice['X'] = cur_player
if cur_player == player1:
player_choice['O'] = player2
else:
player_choice['O'] = player1

elif choice == 2:
player_choice['O'] = cur_player
if cur_player == player1:
player_choice['X'] = player2
else:
player_choice['X'] = player1

elif choice == 3:
print("Final Scores")
print_scoreboard(score_board)

11
break

else:
print("Wrong Choice!!!! Try Again\n")

winner = single_game(options[choice-1])

if winner != 'D' :
player_won = player_choice[winner]
score_board[player_won] = score_board[player_won] + 1

print_scoreboard(score_board)
if cur_player == player1:
cur_player = player2
else:
cur_player = player1

def get_valid_word(words):
word = random.choice(words)
while '-' in word or ' ' in word:
word = random.choice(words)

return word.upper()

def hangman():
word = get_valid_word(words)
word_letters = set(word)
alphabet = set(string.ascii_uppercase)
used_letters = set()

lives = 7

while len(word_letters) > 0 and lives > 0:


# letters used
# ' '.join(['a', 'b', 'cd']) --> 'a b cd'
print('You have', lives, 'lives left and you have used these letters:␣
↪', ' '.join(used_letters))

# what current word is (ie W - R D)

12
word_list = [letter if letter in used_letters else '-' for letter in␣
↪word]
print(lives_visual_dict[lives])
print('Current word: ', ' '.join(word_list))

user_letter = input('Guess a letter: ').upper()


if user_letter in alphabet - used_letters:
used_letters.add(user_letter)
if user_letter in word_letters:
word_letters.remove(user_letter)
print('')

else:
lives = lives - 1 # takes away a life if wrong
print('\nYour letter,', user_letter, 'is not in the word.')

elif user_letter in used_letters:


print('\nYou have already used that letter. Guess another letter.')

else:
print('\nThat is not a valid letter.')

# gets here when len(word_letters) == 0 OR when lives == 0


if lives == 0:
print(lives_visual_dict[lives])
print('You died, sorry. The word was', word)
else:
print('YAY! You guessed the word', word, '!!')

def hangman_Game():
print('Handle option \'Option 3\'')
hangman()

def GameInfo():
print('\n')
print('----------------------')
print ("Welcome to the GAME ROOOM")
print("You will have a choice to play any game you would like!")
print("Select an option down below to pick your game!")
print("WARNING: COMPUTER DOES NOT TAKE IT EASY FOR NEW COMERS")

13
menu_options = {
1: 'Rock, Paper, Scissors vs. CPU',
2: 'Tic-Tac-Toe (TWO Person game)',
3: 'Hangman vs. CPU',
4: 'Exit',
}

def print_game_menu():
for key in menu_options.keys():
print(key, '--', menu_options[key])

def Full_Game():
while(True):
GameInfo()
print_game_menu()
option = ''
try:
option = int(input('Enter your choice: '))
except:
print('Wrong input. Please enter a number ...')
#Check what choice was entered and act accordingly
if option == 1:
RPS()
elif option == 2:
TTToe()
elif option == 3:
hangman_Game()
elif option == 4:
print('Thank you for playing, you will be brougt back to the main␣
↪menu!')

WelcomeFunc()
else:
print('Invalid option. Please enter a number between 1 and 4.')

WelcomeFunc()

14

You might also like