Add ChatGPT-generated next-dining.py

main
Anthony Wang 2023-01-14 23:15:05 -05:00
parent 5da3c0bac1
commit 7303f9ab30
Signed by: a
GPG Key ID: 42A5B952E6DD8D38
1 changed files with 168 additions and 0 deletions

168
next-dining.py 100644
View File

@ -0,0 +1,168 @@
import random
# Initializing variables
player_name = ""
player_hunger = 90
player_health = 100
player_inventory = []
player_location = "lobby"
chef_angry = False
chef_names = ["Soup Nazi", "Halloween Lady", "Good Evening Lady"]
# Function to display player's current status
def display_status():
print("Name: " + player_name)
print("Hunger: " + str(player_hunger))
print("Health: " + str(player_health))
print("Inventory: " + str(player_inventory))
print("Location: " + player_location)
# Function to move player to a new location
def move_location(new_location):
global player_location
player_location = new_location
print("You are now in the " + new_location)
# Function to handle player's interactions with chefs
def interact_with_chef():
global chef_angry, player_hunger, player_health, player_inventory
chef_name = random.choice(chef_names)
print("You approach " + chef_name + " in the kitchen.")
print("What would you like to do? (speak, steal, run)")
action = input()
if action == "speak":
print("You ask " + chef_name + " for some food. They glare at you and refuse to give you any.")
chef_angry = True
elif action == "steal":
if "stealth" in player_inventory:
print("You use your stealth skills to sneak some food from the kitchen without " + chef_name + " noticing.")
player_hunger -= 25
print("You successfully steal some food and your hunger is now at " + str(player_hunger) + ".")
print("You gained a stir fry!")
player_inventory.append("stir fry")
else:
print("You try to steal some food from the kitchen, but " + chef_name + " catches you.")
print("They are furious and call security to escort you out of the building.")
move_location("outside")
player_health -= 25
elif action == "run":
print("You quickly run away from " + chef_name + " before they can react.")
else:
print("Invalid action. Please try again.")
interact_with_chef()
# Function to handle player's interactions with vending machines
def interact_with_vending_machine():
global player_hunger, player_health, player_inventory
print("You approach a vending machine.")
print("What would you like to do? (buy, hack)")
action = input()
if action == "buy":
print("You insert some money and select your desired snack.")
player_hunger -= 15
print("You successfully buy a snack and your hunger is now at " + str(player_hunger) + ".")
elif action == "hack":
if "hacking" in player_inventory:
print("You use your hacking skills to hack the vending machine and get a free snack.")
player_hunger -= 25
print("You successfully hack the vending machine and your hunger is now at " + str(player_hunger) + ".")
print("Additionally, you gained stealth!")
player_inventory.append("stealth")
else:
print("You try to hack the vending machine, but you are unsuccessful.")
print("A security guard approaches and asks you to leave the building.")
move_location("outside")
player_health -= 10
else:
print("Invalid action. Please try again.")
interact_with_vending_machine()
# Function to handle player's interactions with other students
def interact_with_student():
global player_hunger, player_health, player_inventory
student_name = "John" # name of student is randomly generated
print("You approach " + student_name + " in the dining hall.")
print("What would you like to do? (speak, learn, trade)")
action = input()
if action == "speak":
print("You strike up a conversation with " + student_name + " and learn some valuable information about the dining hall.")
player_hunger += 5
elif action == "learn":
print(student_name + " teaches you how to hack.")
player_hunger += 5
player_inventory.append("hacking")
elif action == "trade":
print("You ask " + student_name + " if they would like to trade items.")
student_item = "extra meal ticket" # item student has is randomly generated
print(student_name + " has an " + student_item + " and is willing to trade it for one of your items.")
if player_inventory:
print("Your current inventory: " + str(player_inventory))
print("What item would you like to trade?")
trade_item = input()
if trade_item in player_inventory:
if trade_item == "stir fry"
player_inventory.remove(trade_item)
player_inventory.append(student_item)
print("You successfully trade your " + trade_item + " for " + student_name + "'s " + student_item + ".")
else:
print(student_name + " doesn't like your item.")
else:
print("You do not have that item in your inventory.")
else:
print("You do not have any items to trade.")
else:
print("Invalid action. Please try again.")
interact_with_student()
# Main game loop
def play_game():
global player_hunger, player_health, player_inventory
# Introduction
print("Welcome to Next Dining: The Video Game!")
player_name = input("What is your name? ")
display_status()
# Gameplay
while player_health > 0 and player_hunger <= 100:
print("What would you like to do? (move, interact, check status)")
action = input()
if action == "move":
print("Where would you like to go? (kitchen, dining hall, vending room, outside)")
new_location = input()
move_location(new_location)
elif action == "interact":
if player_location == "kitchen":
interact_with_chef()
elif player_location == "vending room":
interact_with_vending_machine()
elif player_location == "dining hall":
interact_with_student()
else:
print("There is nothing to interact with in this location.")
elif action == "check status":
display_status()
else:
print("Invalid action. Please try again.")
# Hunger and health decrement
player_hunger += 5
if chef_angry:
player_health -= 10
# Check for game over
if player_health <= 0:
print("Your health has reached zero. Game over.")
break
elif player_hunger >= 100:
print("You have died of starvation. Game over.")
break
elif player_location == "outside":
print("You have been kicked out of the building and cannot continue playing.")
break
# End game message
print("Thank you for playing Next Dining: The Video Game! Better luck next time.")
if "extra meal ticket" in player_inventory:
print("Congratulations! You won!")
break
play_game()