Guest User

Untitled

a guest
Nov 10th, 2025
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.45 KB | Source Code | 0 0
  1. import time
  2. import sys
  3.  
  4. # -------------------------------
  5. # Typewriter Effect
  6. # -------------------------------
  7. def typewriter(text, speed=0.05):
  8. """Print text gradually like a typewriter effect."""
  9. for char in text:
  10. sys.stdout.write(char)
  11. sys.stdout.flush()
  12. time.sleep(speed)
  13. print() # new line at end
  14.  
  15. # -------------------------------
  16. # Game Over
  17. # -------------------------------
  18. def game_over(health, courage, inventory):
  19. typewriter("\n--- GAME OVER ---", 0.05)
  20. typewriter(f"Courage: {courage}", 0.03)
  21. typewriter(f"Health: {health}", 0.03)
  22. typewriter(f"Inventory: {inventory}", 0.03)
  23.  
  24. choice = input("\nTry again? (Y/N): ").lower()
  25. if choice == "y":
  26. typewriter("\nIf you insist...", 0.06)
  27. time.sleep(1.5)
  28. return True
  29. else:
  30. typewriter("\n", 0.05)
  31. time.sleep(1.5)
  32. typewriter("Goodbye...\n", 0.06)
  33. time.sleep(1.5)
  34. return False
  35.  
  36. # -------------------------------
  37. # Intro Scene
  38. # -------------------------------
  39. def intro_scene():
  40. begin = input("Shall we begin? (Y/N)? ").lower()
  41. if begin == "n":
  42. typewriter("You can't delay the inevitable.", 0.05)
  43. time.sleep(1)
  44. typewriter("Get up...", 0.3)
  45. time.sleep(1.5)
  46. return True
  47. else:
  48. typewriter("Wake up...", 0.3)
  49. time.sleep(1.5)
  50. return True
  51.  
  52. # -------------------------------
  53. # Cabin Scene
  54. # -------------------------------
  55. def cabin_scene(health, courage, inventory):
  56. typewriter("You wake up in a small cabin in the woods.", 0.04)
  57. time.sleep(1.5)
  58. typewriter("It's raining outside, and you hear footsteps nearby...", 0.04)
  59. time.sleep(1.5)
  60. typewriter("\nDo you OPEN the door or HIDE under the bed?", 0.03)
  61. choice1 = input("> ").lower()
  62.  
  63. if choice1 == "open":
  64. courage += 10
  65. typewriter("\nYou open the door slowly... A lost traveler stands outside asking for help.", 0.04)
  66. time.sleep(1)
  67. typewriter("Do you INVITE them in or REFUSE?", 0.03)
  68. choice2 = input("> ").lower()
  69.  
  70. if choice2 == "invite":
  71. typewriter("\nYou share some soup with the traveler. They thank you and give you a map.", 0.04)
  72. time.sleep(1)
  73. inventory.append("map")
  74. typewriter("You received a map.", 0.04)
  75. else:
  76. typewriter("\nYou keep the door shut. The footsteps fade. Loneliness fills the cabin...", 0.04)
  77. time.sleep(1)
  78. typewriter("But you aren't alone...", 0.04)
  79. time.sleep(1)
  80. typewriter("Game over.", 0.04)
  81. return None, courage, inventory
  82.  
  83. elif choice1 == "hide":
  84. courage -= 5
  85. typewriter("\nYou crawl under the bed and hold your breath...", 0.04)
  86. time.sleep(1)
  87. typewriter("After a moment, a wolf sneaks in!", 0.04)
  88. time.sleep(1)
  89. typewriter("Do you STAY quiet or RUN outside?", 0.03)
  90. choice2 = input("> ").lower()
  91.  
  92. if choice2 == "stay":
  93. typewriter("\nThe wolf sniffs around but leaves. You survive!", 0.04)
  94. time.sleep(1)
  95. typewriter("But now you're all alone...", 0.06)
  96. time.sleep(1)
  97. typewriter("Game over.", 0.04)
  98. return None, courage, inventory
  99. else:
  100. typewriter("\nYou dash outside but slip on the mud. The wolf bites you.", 0.04)
  101. time.sleep(1)
  102. health -= 100
  103. typewriter(f"Your health is now {health}", 0.04)
  104. time.sleep(1)
  105. typewriter("...", 0.1)
  106. time.sleep(1.5)
  107. typewriter("You bled out.", 0.04)
  108. time.sleep(2)
  109. typewriter("It seems cowardice gets you nowhere.", 0.04)
  110. time.sleep(2)
  111. typewriter("Game over.", 0.04)
  112. return None, courage, inventory
  113. else:
  114. typewriter("\nYou hesitate too long... the footsteps reach the door.", 0.04)
  115. time.sleep(1)
  116. typewriter("Game over!", 0.04)
  117. return None, courage, inventory
  118.  
  119. return health, courage, inventory
  120.  
  121. # -------------------------------
  122. # Forest Scene
  123. # -------------------------------
  124. def forest_scene(health, courage, inventory):
  125. if "map" in inventory:
  126. typewriter("\nDo you want to FOLLOW the map or STAY in the cabin?", 0.03)
  127. next_scene = input("> ").lower()
  128.  
  129. if next_scene == "follow":
  130. typewriter("\nYou pack your things and step into the dark forest...", 0.04)
  131. time.sleep(1)
  132. typewriter("After an hour, you reach an old bridge. It looks weak.", 0.04)
  133. time.sleep(1)
  134. typewriter("Do you CROSS it or FIND another way?", 0.03)
  135. bridge_choice = input("> ").lower()
  136.  
  137. if bridge_choice == "cross":
  138. typewriter("\nYou make it halfway... the bridge creaks.", 0.04)
  139. time.sleep(1)
  140. typewriter("You run and barely make it across—but you drop your map!", 0.04)
  141. if "map" in inventory:
  142. inventory.remove("map")
  143. health -= 10
  144. typewriter(f"Health: {health}", 0.04)
  145. time.sleep(1)
  146. else:
  147. typewriter("\nYou walk along the riverbank and find a safer crossing.", 0.04)
  148. health += 5
  149. typewriter(f"Health: {health}", 0.04)
  150. else:
  151. typewriter("\nYou stay in the cabin. It's quiet...", 0.06)
  152. time.sleep(1)
  153. typewriter("The world moves on without you. Your story ends here.", 0.04)
  154. return None, inventory
  155.  
  156. else:
  157. typewriter("\nYou have no map, so you cannot continue into the forest yet.", 0.04)
  158.  
  159. return health, courage, inventory
  160.  
  161. # -------------------------------
  162. # Mountain Scene
  163. # -------------------------------
  164. def mountain_scene(health, courage, inventory):
  165. typewriter("\nYou find yourself at the edge of a colossal mountain.", 0.04)
  166. time.sleep(1.5)
  167. typewriter("The wind howls. There's a narrow path leading up and a dark cave nearby.", 0.04)
  168. time.sleep(1)
  169. typewriter("Do you CLIMB the path or ENTER the cave?", 0.03)
  170. choicem = input("> ").lower()
  171.  
  172. if choicem == "climb":
  173. courage += 10
  174. typewriter("You start climbing carefully...", 0.04)
  175. time.sleep(1)
  176. typewriter("Halfway up, rocks crumble under your feet. You barely hang on.", 0.04)
  177. health -= 15
  178. typewriter(f"You survive but lose some health. Health: {health}", 0.04)
  179. else:
  180. typewriter("You step into the cave. It's cold and dark.", 0.04)
  181. time.sleep(1)
  182. typewriter("You find a glowing stone— it feels warm to the touch.", 0.04)
  183. inventory.append("Glowing stone")
  184. typewriter("You gained: Glowing stone", 0.04)
  185.  
  186. return health, courage, inventory
  187.  
  188. # -------------------------------
  189. # Empty scene
  190. # -------------------------------
  191.  
  192. # -------------------------------
  193. # Main Game Loop
  194. # -------------------------------
  195. def main():
  196. while True:
  197. health = 100
  198. courage = 0
  199. inventory = []
  200.  
  201. typewriter("\n--- NEW GAME ---", 0.05)
  202. time.sleep(1)
  203.  
  204. # Intro
  205. continue_game = intro_scene()
  206. if not continue_game:
  207. break
  208.  
  209. # Cabin
  210. result = cabin_scene(health, courage, inventory)
  211. if result[0] is None:
  212. restart = game_over(health, courage, inventory)
  213. if restart:
  214. print("\n" * 50)
  215. continue
  216. else:
  217. break
  218. else:
  219. health, courage, inventory = result
  220.  
  221. # Forest
  222. result = forest_scene(health, courage, inventory)
  223. if result[0] is None:
  224. restart = game_over(health, courage, inventory)
  225. if restart:
  226. print("\n" * 50)
  227. continue
  228. else:
  229. break
  230. else:
  231. health, inventory = result
  232.  
  233. # Mountain
  234. health, courage, inventory = mountain_scene(health, courage, inventory)
  235.  
  236. # Survived all scenes
  237. restart = game_over(health, courage, inventory)
  238. if restart:
  239. print("\n" * 50)
  240. continue
  241. else:
  242. break
  243.  
  244. # -------------------------------
  245. # Run the Game
  246. # -------------------------------
  247. if __name__ == "__main__":
  248. main()
Advertisement
Add Comment
Please, Sign In to add comment