|
| 1 | +import subprocess |
| 2 | +import os |
| 3 | +import sys |
| 4 | +import random |
| 5 | + |
| 6 | +def main(): |
| 7 | + status = "happy" |
| 8 | + hunger = 0 |
| 9 | + tired = 0 |
| 10 | + |
| 11 | + print("Welcome to the virtual pet game!") |
| 12 | + print("Keep your pet happy by feeding it...") |
| 13 | + print("Play with it...") |
| 14 | + print("Make it rest...") |
| 15 | + print("And buy it toys") |
| 16 | + print("Enjoy this simple command line game by Alter Net codes!") |
| 17 | + input("Press Enter to continue...") |
| 18 | + for i in range(20): |
| 19 | + print(" ") |
| 20 | + |
| 21 | + while True: |
| 22 | + print("Looks like your dog is", status) |
| 23 | + print("You can FEED, PLAY, REST, BUY TOYS, EXIT") |
| 24 | + if tired > 4: |
| 25 | + print("Your dog is tired.") |
| 26 | + if hunger > 4: |
| 27 | + print("Your dog is hungry.") |
| 28 | + |
| 29 | + task = input("What would you like to do? ").lower() |
| 30 | + |
| 31 | + if task == "play": |
| 32 | + hunger += 2 |
| 33 | + tired += 2 |
| 34 | + print("You go to the park to play with your dog!") |
| 35 | + status = "excited" |
| 36 | + print("Your dog is", status, "to be at the park") |
| 37 | + number = random.randint(1, 100) |
| 38 | + try: |
| 39 | + numberpicked = int(input("Pick a number from 1-100: ")) |
| 40 | + if numberpicked < number: |
| 41 | + print("Oh, not quite! The right number was:", number) |
| 42 | + print("You throw the ball about 20 feet!") |
| 43 | + print("Nice throw!") |
| 44 | + print(" ") |
| 45 | + status = "satisfied" |
| 46 | + elif numberpicked > number: |
| 47 | + print("Not quite! Still good! The right number was:", number) |
| 48 | + print("Nice! You throw the ball about 20 feet") |
| 49 | + print("Nice throw!") |
| 50 | + print(" ") |
| 51 | + status = "satisfied" |
| 52 | + else: |
| 53 | + print("YES! YOU GOT IT!!!") |
| 54 | + print("You throw the ball 50 feet!") |
| 55 | + print("ELEGANT!!!!!!!!") |
| 56 | + print("") |
| 57 | + status = "VERY happy" |
| 58 | + except ValueError: |
| 59 | + print("Please enter a valid number.") |
| 60 | + |
| 61 | + elif task == "feed": |
| 62 | + tired += 2 |
| 63 | + print("Good idea to feed him; he was at", hunger, "hunger points!") |
| 64 | + print("You feed your dog.") |
| 65 | + hunger = 0 |
| 66 | + status = "happy" |
| 67 | + print("Your dog is now cured of its hunger.") |
| 68 | + print(" ") |
| 69 | + |
| 70 | + elif task == "rest": |
| 71 | + hunger += 2 |
| 72 | + print("Good idea; your dog was at", tired, "tired points!") |
| 73 | + print("You put your dog to sleep.") |
| 74 | + tired = 0 |
| 75 | + status = "happy" |
| 76 | + print("Your dog is now cured of its tiredness.") |
| 77 | + print(" ") |
| 78 | + |
| 79 | + elif task == "buy toys": |
| 80 | + tired += 2 |
| 81 | + print("You buy a few toys for your dog.") |
| 82 | + status = "playful" |
| 83 | + print(" ") |
| 84 | + |
| 85 | + elif task == "exit": |
| 86 | + print("Goodbye!") |
| 87 | + print("See you later.") |
| 88 | + print("Saving and quitting...") |
| 89 | + |
| 90 | + # Path to the kernel script in the KERNEL folder |
| 91 | + kernel_script = os.path.join(os.getcwd(), 'KERNEL', 'kernel.py') |
| 92 | + |
| 93 | + # Check if the kernel script exists before trying to run it |
| 94 | + if os.path.isfile(kernel_script): |
| 95 | + try: |
| 96 | + # Run the kernel script as a subprocess |
| 97 | + subprocess.run([sys.executable, kernel_script], check=True) |
| 98 | + except subprocess.CalledProcessError as e: |
| 99 | + print(f"Error executing the kernel script: {e}") |
| 100 | + except Exception as e: |
| 101 | + print(f"An unexpected error occurred: {e}") |
| 102 | + else: |
| 103 | + print("yay sucsess!") |
| 104 | + |
| 105 | + break |
| 106 | + |
| 107 | + else: |
| 108 | + print("That is not a valid action!") |
| 109 | + |
| 110 | +if __name__ == "__main__": |
| 111 | + main() |
0 commit comments