Last active
June 30, 2023 13:14
-
-
Save Gertkeno/c88cd953143ecb66c6a4a718050aacd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import sys | |
pet = { | |
"name": input("Name your pet!\n>"), | |
"hunger": 0, | |
"happiness": 100, | |
} | |
# create a filled bar i.e. [###### ] | |
def to_bar(value, char): | |
fill = int(value / 10) | |
return "[" + char * fill + " " * (10 - fill) + "]" | |
def show_stats(): | |
print(pet["name"], ":", to_bar(pet["hunger"], 'X'), to_bar(pet["happiness"], '#')) | |
def feed(): | |
pet["hunger"] -= 40 | |
# negative numbers are set to 0 | |
if pet["hunger"] < 0: | |
pet["hunger"] = 0 | |
print(pet["name"], "is stuffed!") | |
def play(): | |
pet["happiness"] += 30 | |
if pet["happiness"] > 100: | |
pet["happiness"] = 100 | |
def tick(delta): | |
pet["hunger"] += round(delta/2) | |
pet["happiness"] -= round(delta/3) | |
if pet["hunger"] > 100: | |
print(pet["name"], "is starving and ran away!") | |
sys.exit() | |
elif pet["happiness"] < 0: | |
print(pet["name"], "ran away!") | |
sys.exit() | |
while True: | |
start_time = time.time() | |
action = input("\nFeed, Play, or check on pet?\n>").lower() | |
if action == "feed": | |
feed() | |
elif action == "play": | |
play() | |
elif action == "check": | |
pass | |
else: | |
print("You cannot", action) | |
elapsed_time = time.time() - start_time | |
tick(elapsed_time) | |
show_stats() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment