Fancy sprint function

This commit is contained in:
Anthony Wang 2023-01-15 00:25:41 -05:00
parent 362819952e
commit 0a7a3d27c5
Signed by: a
GPG Key ID: 42A5B952E6DD8D38

108
main.py
View File

@ -1,3 +1,4 @@
import time
import random
# Initializing variables
@ -9,125 +10,132 @@ player_location = "lobby"
chef_angry = False
chef_names = ["Soup Nazi", "Halloween Lady", "Good Evening Lady"]
def sprint(s):
for c in s:
print(c, end="", flush=True)
time.sleep(0.025)
print()
# 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)
sprint("Name: " + player_name)
sprint("Hunger: " + str(player_hunger))
sprint("Health: " + str(player_health))
sprint("Inventory: " + str(player_inventory))
sprint("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)
sprint("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)")
sprint("You approach " + chef_name + " in the kitchen.")
sprint("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.")
sprint("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.")
sprint("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!")
sprint("You successfully steal some food and your hunger is now at " + str(player_hunger) + ".")
sprint("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.")
sprint("You try to steal some food from the kitchen, but " + chef_name + " catches you.")
sprint("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.")
sprint("You quickly run away from " + chef_name + " before they can react.")
else:
print("Invalid action. Please try again.")
sprint("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)")
sprint("You approach a vending machine.")
sprint("What would you like to do? (buy, hack)")
action = input()
if action == "buy":
print("You insert some money and select your desired snack.")
sprint("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) + ".")
sprint("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.")
sprint("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!")
sprint("You successfully hack the vending machine and your hunger is now at " + str(player_hunger) + ".")
sprint("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.")
sprint("You try to hack the vending machine, but you are unsuccessful.")
sprint("A security guard approaches and asks you to leave the building.")
move_location("outside")
player_health -= 10
else:
print("Invalid action. Please try again.")
sprint("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)")
sprint("You approach " + student_name + " in the dining hall.")
sprint("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.")
sprint("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.")
sprint(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.")
sprint("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.")
sprint(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?")
sprint("Your current inventory: " + str(player_inventory))
sprint("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 + ".")
sprint("You successfully trade your " + trade_item + " for " + student_name + "'s " + student_item + ".")
else:
print(student_name + " doesn't like your item.")
sprint(student_name + " doesn't like your item.")
else:
print("You do not have that item in your inventory.")
sprint("You do not have that item in your inventory.")
else:
print("You do not have any items to trade.")
sprint("You do not have any items to trade.")
else:
print("Invalid action. Please try again.")
sprint("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? ")
sprint("Welcome to Next Dining: The Video Game!")
sprint("What is your name?")
player_name = input()
display_status()
# Gameplay
while player_health > 0 and player_hunger <= 100:
print("What would you like to do? (move, interact, check status)")
sprint("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)")
sprint("Where would you like to go? (kitchen, dining hall, vending room, outside)")
new_location = input()
move_location(new_location)
elif action == "interact":
@ -138,11 +146,11 @@ def play_game():
elif player_location == "dining hall":
interact_with_student()
else:
print("There is nothing to interact with in this location.")
sprint("There is nothing to interact with in this location.")
elif action == "check status":
display_status()
else:
print("Invalid action. Please try again.")
sprint("Invalid action. Please try again.")
# Hunger and health decrement
player_hunger += 5
@ -151,18 +159,18 @@ def play_game():
# Check for game over
if player_health <= 0:
print("Your health has reached zero. Game over.")
sprint("Your health has reached zero. Game over.")
break
elif player_hunger >= 100:
print("You have died of starvation. Game over.")
sprint("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.")
sprint("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.")
sprint("Thank you for playing Next Dining: The Video Game! Better luck next time.")
if "extra meal ticket" in player_inventory:
print("Congratulations! You won!")
sprint("Congratulations! You won!")
break
play_game()