Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import sys
- # -------------------------------
- # Typewriter Effect
- # -------------------------------
- def typewriter(text, speed=0.05):
- """Print text gradually like a typewriter effect."""
- for char in text:
- sys.stdout.write(char)
- sys.stdout.flush()
- time.sleep(speed)
- print() # new line at end
- # -------------------------------
- # Game Over
- # -------------------------------
- def game_over(health, courage, inventory):
- typewriter("\n--- GAME OVER ---", 0.05)
- typewriter(f"Courage: {courage}", 0.03)
- typewriter(f"Health: {health}", 0.03)
- typewriter(f"Inventory: {inventory}", 0.03)
- choice = input("\nTry again? (Y/N): ").lower()
- if choice == "y":
- typewriter("\nIf you insist...", 0.06)
- time.sleep(1.5)
- return True
- else:
- typewriter("\n", 0.05)
- time.sleep(1.5)
- typewriter("Goodbye...\n", 0.06)
- time.sleep(1.5)
- return False
- # -------------------------------
- # Intro Scene
- # -------------------------------
- def intro_scene():
- begin = input("Shall we begin? (Y/N)? ").lower()
- if begin == "n":
- typewriter("You can't delay the inevitable.", 0.05)
- time.sleep(1)
- typewriter("Get up...", 0.3)
- time.sleep(1.5)
- return True
- else:
- typewriter("Wake up...", 0.3)
- time.sleep(1.5)
- return True
- # -------------------------------
- # Cabin Scene
- # -------------------------------
- def cabin_scene(health, courage, inventory):
- typewriter("You wake up in a small cabin in the woods.", 0.04)
- time.sleep(1.5)
- typewriter("It's raining outside, and you hear footsteps nearby...", 0.04)
- time.sleep(1.5)
- typewriter("\nDo you OPEN the door or HIDE under the bed?", 0.03)
- choice1 = input("> ").lower()
- if choice1 == "open":
- courage += 10
- typewriter("\nYou open the door slowly... A lost traveler stands outside asking for help.", 0.04)
- time.sleep(1)
- typewriter("Do you INVITE them in or REFUSE?", 0.03)
- choice2 = input("> ").lower()
- if choice2 == "invite":
- typewriter("\nYou share some soup with the traveler. They thank you and give you a map.", 0.04)
- time.sleep(1)
- inventory.append("map")
- typewriter("You received a map.", 0.04)
- else:
- typewriter("\nYou keep the door shut. The footsteps fade. Loneliness fills the cabin...", 0.04)
- time.sleep(1)
- typewriter("But you aren't alone...", 0.04)
- time.sleep(1)
- typewriter("Game over.", 0.04)
- return None, courage, inventory
- elif choice1 == "hide":
- courage -= 5
- typewriter("\nYou crawl under the bed and hold your breath...", 0.04)
- time.sleep(1)
- typewriter("After a moment, a wolf sneaks in!", 0.04)
- time.sleep(1)
- typewriter("Do you STAY quiet or RUN outside?", 0.03)
- choice2 = input("> ").lower()
- if choice2 == "stay":
- typewriter("\nThe wolf sniffs around but leaves. You survive!", 0.04)
- time.sleep(1)
- typewriter("But now you're all alone...", 0.06)
- time.sleep(1)
- typewriter("Game over.", 0.04)
- return None, courage, inventory
- else:
- typewriter("\nYou dash outside but slip on the mud. The wolf bites you.", 0.04)
- time.sleep(1)
- health -= 100
- typewriter(f"Your health is now {health}", 0.04)
- time.sleep(1)
- typewriter("...", 0.1)
- time.sleep(1.5)
- typewriter("You bled out.", 0.04)
- time.sleep(2)
- typewriter("It seems cowardice gets you nowhere.", 0.04)
- time.sleep(2)
- typewriter("Game over.", 0.04)
- return None, courage, inventory
- else:
- typewriter("\nYou hesitate too long... the footsteps reach the door.", 0.04)
- time.sleep(1)
- typewriter("Game over!", 0.04)
- return None, courage, inventory
- return health, courage, inventory
- # -------------------------------
- # Forest Scene
- # -------------------------------
- def forest_scene(health, courage, inventory):
- if "map" in inventory:
- typewriter("\nDo you want to FOLLOW the map or STAY in the cabin?", 0.03)
- next_scene = input("> ").lower()
- if next_scene == "follow":
- typewriter("\nYou pack your things and step into the dark forest...", 0.04)
- time.sleep(1)
- typewriter("After an hour, you reach an old bridge. It looks weak.", 0.04)
- time.sleep(1)
- typewriter("Do you CROSS it or FIND another way?", 0.03)
- bridge_choice = input("> ").lower()
- if bridge_choice == "cross":
- typewriter("\nYou make it halfway... the bridge creaks.", 0.04)
- time.sleep(1)
- typewriter("You run and barely make it across—but you drop your map!", 0.04)
- if "map" in inventory:
- inventory.remove("map")
- health -= 10
- typewriter(f"Health: {health}", 0.04)
- time.sleep(1)
- else:
- typewriter("\nYou walk along the riverbank and find a safer crossing.", 0.04)
- health += 5
- typewriter(f"Health: {health}", 0.04)
- else:
- typewriter("\nYou stay in the cabin. It's quiet...", 0.06)
- time.sleep(1)
- typewriter("The world moves on without you. Your story ends here.", 0.04)
- return None, inventory
- else:
- typewriter("\nYou have no map, so you cannot continue into the forest yet.", 0.04)
- return health, courage, inventory
- # -------------------------------
- # Mountain Scene
- # -------------------------------
- def mountain_scene(health, courage, inventory):
- typewriter("\nYou find yourself at the edge of a colossal mountain.", 0.04)
- time.sleep(1.5)
- typewriter("The wind howls. There's a narrow path leading up and a dark cave nearby.", 0.04)
- time.sleep(1)
- typewriter("Do you CLIMB the path or ENTER the cave?", 0.03)
- choicem = input("> ").lower()
- if choicem == "climb":
- courage += 10
- typewriter("You start climbing carefully...", 0.04)
- time.sleep(1)
- typewriter("Halfway up, rocks crumble under your feet. You barely hang on.", 0.04)
- health -= 15
- typewriter(f"You survive but lose some health. Health: {health}", 0.04)
- else:
- typewriter("You step into the cave. It's cold and dark.", 0.04)
- time.sleep(1)
- typewriter("You find a glowing stone— it feels warm to the touch.", 0.04)
- inventory.append("Glowing stone")
- typewriter("You gained: Glowing stone", 0.04)
- return health, courage, inventory
- # -------------------------------
- # Empty scene
- # -------------------------------
- # -------------------------------
- # Main Game Loop
- # -------------------------------
- def main():
- while True:
- health = 100
- courage = 0
- inventory = []
- typewriter("\n--- NEW GAME ---", 0.05)
- time.sleep(1)
- # Intro
- continue_game = intro_scene()
- if not continue_game:
- break
- # Cabin
- result = cabin_scene(health, courage, inventory)
- if result[0] is None:
- restart = game_over(health, courage, inventory)
- if restart:
- print("\n" * 50)
- continue
- else:
- break
- else:
- health, courage, inventory = result
- # Forest
- result = forest_scene(health, courage, inventory)
- if result[0] is None:
- restart = game_over(health, courage, inventory)
- if restart:
- print("\n" * 50)
- continue
- else:
- break
- else:
- health, inventory = result
- # Mountain
- health, courage, inventory = mountain_scene(health, courage, inventory)
- # Survived all scenes
- restart = game_over(health, courage, inventory)
- if restart:
- print("\n" * 50)
- continue
- else:
- break
- # -------------------------------
- # Run the Game
- # -------------------------------
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment