Advertisement
drtyweasl

Fallout terminal code #1

May 1st, 2024 (edited)
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.51 KB | Source Code | 0 0
  1. import os
  2. import time
  3. import random
  4. import requests
  5. import json
  6. from os import environ
  7.  
  8. environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
  9. import pygame
  10.  
  11. project_root = os.path.dirname(os.path.abspath(__file__))
  12. pygame.init()
  13. pygame.mixer.init()
  14. enter = pygame.mixer.Sound(project_root + "/sounds/enter.wav")
  15. pop = pygame.mixer.Sound(project_root + "/sounds/scroll.wav")
  16. password_path = project_root + '/password.txt'
  17. hacking_attempts = 4
  18. good = pygame.mixer.Sound(project_root + "/sounds/good.wav")
  19. bad = pygame.mixer.Sound(project_root + "/sounds/bad.wav")
  20.  
  21.  
  22. def line(text, delay=0.01):
  23. for char in text:
  24. print(char, end='', flush=True)
  25. time.sleep(delay)
  26. print()
  27.  
  28.  
  29. def load_words(filename):
  30. with open(filename, 'r') as file:
  31. words = json.load(file)
  32. # Select a random subset of 2-5 words from the list
  33. num_words = random.randint(4, 8) # Choose how many words to pick
  34. selected_words = random.sample(words, num_words)
  35. return [word.upper() for word in selected_words] # Convert all to uppercase
  36.  
  37.  
  38. words = load_words(project_root + "/words.json")
  39.  
  40.  
  41. def generate_grid(rows, cols, words, characters):
  42. grid = [['' for _ in range(cols)] for _ in range(rows)]
  43. placed_words = []
  44.  
  45. # Place words in the grid
  46. for word in words:
  47. word_placed = False
  48. attempts = 0 # Prevent infinite loop
  49. while not word_placed and attempts < 100:
  50. direction = random.choice(['horizontal', 'vertical'])
  51. if direction == 'horizontal':
  52. start_row = random.randint(0, rows - 1)
  53. start_col = random.randint(0, cols - len(word))
  54. else:
  55. start_row = random.randint(0, rows - len(word))
  56. start_col = random.randint(0, cols - 1)
  57.  
  58. # Check if space is available
  59. if all(grid[start_row + i * (direction == 'vertical')][
  60. start_col + i * (direction == 'horizontal')] == '' for i in range(len(word))):
  61. for i in range(len(word)):
  62. grid[start_row + i * (direction == 'vertical')][start_col + i * (direction == 'horizontal')] = word[
  63. i]
  64. word_placed = True
  65. placed_words.append(word)
  66. attempts += 1
  67.  
  68. # Fill in remaining spaces with random characters
  69. for i in range(rows):
  70. for j in range(cols):
  71. if grid[i][j] == '':
  72. grid[i][j] = random.choice(characters)
  73.  
  74. return grid, placed_words
  75.  
  76.  
  77. def hacking():
  78. good.play()
  79. global hacking_attempts
  80. os.system('cls' if os.name == 'nt' else 'clear')
  81. line("(c) 2044 Maple LLC Practice Hacking Terminal v0.1.2")
  82. line(f"ATTEMPT(S) LEFT: {hacking_attempts} OF 4")
  83. print("")
  84.  
  85. words = load_words(project_root + "/words.json")
  86. characters = "!@#$%&*:[]"
  87. rows = 20
  88. cols = 20
  89.  
  90. grid, placed_words = generate_grid(rows, cols, words, characters)
  91. correct_word = random.choice(placed_words)
  92. for row in grid:
  93. print(' '.join(row))
  94.  
  95. while hacking_attempts > 0:
  96. guess = input("Enter your guess: ").upper()
  97. if guess in placed_words:
  98. if guess == correct_word:
  99. good.play()
  100. print("Access granted!")
  101. restart = input("Would you like to try again? (y/n): ")
  102. if restart == "y":
  103. hacking_attempts = 4
  104. hacking()
  105. else:
  106. main()
  107. break
  108.  
  109. break
  110. else:
  111. good.play()
  112. likeness = sum(a == b for a, b in zip(guess, correct_word))
  113. print(f"Likeness={likeness}")
  114. else:
  115. bad.play()
  116. print("Word not found in grid.")
  117.  
  118. hacking_attempts -= 1
  119. line(f"ATTEMPT(S) LEFT: {hacking_attempts} OF 4")
  120.  
  121. if hacking_attempts == 0:
  122. bad.play()
  123. print("Access denied. System locked!")
  124. print("Please wait 15 seconds before trying again.")
  125. time.sleep(15)
  126. restart = input("Would you like to try again? (y/n): ")
  127. if restart == "y":
  128. hacking_attempts = 4
  129. hacking()
  130. else:
  131. main()
  132. break
  133.  
  134.  
  135. def browser():
  136. # Clear the screen
  137. os.system('cls' if os.name == 'nt' else 'clear')
  138. print("WeaslCo Industries Browser v0.0.2")
  139. print("Enter a URL to visit.")
  140.  
  141. allowed_urls = {
  142. # No URLs yet
  143. }
  144.  
  145. user_input = input("URL: > ")
  146.  
  147. # Check if the entered URL is in the whitelist
  148. if user_input in allowed_urls:
  149. response = requests.get(user_input)
  150. print(response.text)
  151. user_input = input("Press enter to return to the URL select.")
  152. browser()
  153. else:
  154. print("Access to this URL is restricted.")
  155.  
  156.  
  157. def password():
  158. os.system('cls' if os.name == 'nt' else 'clear')
  159. line("WeaslCo Industries Security Identification System v1.2.1")
  160. print("Enter your password to continue.")
  161. user_password = input("Password: ")
  162.  
  163. # Read password from file
  164. with open(password_path, 'r') as file:
  165. stored_password = file.read().strip() # .strip() to remove any extraneous whitespace/newlines
  166.  
  167. if user_password == stored_password:
  168. print("Password accepted.")
  169. time.sleep(1)
  170. os.system('cls' if os.name == 'nt' else 'clear')
  171. else:
  172. print("Password incorrect.")
  173. time.sleep(1)
  174. os.system('cls' if os.name == 'nt' else 'clear')
  175. password() # Recursively retrying the password input
  176.  
  177.  
  178. def error():
  179. os.system('cls' if os.name == 'nt' else 'clear')
  180. sound = pygame.mixer.Sound(project_root + "/sounds/bad.wav")
  181. sound.play()
  182. while pygame.mixer.get_busy():
  183. pygame.time.delay(100)
  184. time.sleep(.2)
  185. line("Memory Check Failed. Please restart your computer.")
  186. line("Automatically restarting in 5 seconds...")
  187. time.sleep(5)
  188. os.system('cls' if os.name == 'nt' else 'clear')
  189. line("Restarting...")
  190. time.sleep(2)
  191. os.system('cls' if os.name == 'nt' else 'clear')
  192. os.system('python ' + project_root + '/app.py')
  193.  
  194.  
  195. # Programs
  196. def word():
  197. project_root = os.path.dirname(os.path.abspath(__file__))
  198. print("WeaslCo Word Processor v1.0.0")
  199. print("Commands: type, exit")
  200. print("Type 'exit' to return to the main menu.")
  201. while True:
  202. user_input = input("W:\ > ")
  203. if user_input == "exit":
  204. print("Exiting Word Processor...")
  205. main()
  206. break
  207. elif user_input == "type":
  208. user_input = input("Enter file name: ")
  209. name = user_input
  210. print("Start typing your text. Press enter on an empty line to save and exit.")
  211. text_to_save = ""
  212. while True:
  213. line = input()
  214. if line.strip() == "":
  215. break
  216. text_to_save += line + "\n"
  217.  
  218. file_path = os.path.join(project_root, name + '.txt')
  219. with open(file_path, 'w') as file:
  220. file.write(text_to_save)
  221. else:
  222. print(f"Command '{user_input}' not recognized.")
  223.  
  224.  
  225. def mail():
  226. project_root = os.path.dirname(os.path.abspath(__file__))
  227. print("WeaslCo Mail v1.0.0")
  228. print("Commands: send, read, exit")
  229. print("Type 'exit' to return to the main menu.")
  230.  
  231. while True:
  232. user_input = input("M:\ > ")
  233. if user_input == "exit":
  234. print("Exiting Mail...")
  235. main()
  236. break
  237. elif user_input == "send":
  238. pop.play()
  239. user_input = input("Enter recipient: ")
  240. recipient = user_input
  241. user_input = input("Enter subject: ")
  242. subject = user_input
  243. print("Start typing your email. Press enter on an empty line to send.")
  244. text_to_send = ""
  245. while True:
  246. line = input()
  247. if line.strip() == "":
  248. break
  249. text_to_send += line + "\n"
  250.  
  251. file_path = os.path.join(project_root, 'outbox.txt')
  252. with open(file_path, 'a') as file:
  253. file.write(f"To: {recipient}\n")
  254. file.write(f"Subject: {subject}\n")
  255. file.write(text_to_send)
  256. file.write("\n")
  257. elif user_input == "read":
  258. pop.play()
  259. print("Read inbox or outbox?")
  260. user_input = input("Enter inbox or outbox: ")
  261. if user_input == "inbox":
  262. pop.play()
  263. file_path = os.path.join(project_root, 'inbox.txt')
  264. with open(file_path, 'r') as file:
  265. print(file.read())
  266. elif user_input == "outbox":
  267. pop.play()
  268. file_path = os.path.join(project_root, 'outbox.txt')
  269. with open(file_path, 'r') as file:
  270. print(file.read())
  271. else:
  272. print(f"Command '{user_input}' not recognized.")
  273.  
  274.  
  275. home = ["exit", "word", "mail", "browser"]
  276.  
  277. os.system('cls' if os.name == 'nt' else 'clear')
  278. pygame.mixer.music.load(project_root + "/sounds/fan.wav")
  279. pygame.mixer.music.set_volume(0.3)
  280. pygame.mixer.music.play(-1)
  281. sound = pygame.mixer.Sound(project_root + "/sounds/buttonstart.wav")
  282. sound.play()
  283. while pygame.mixer.get_busy():
  284. pygame.time.delay(100)
  285. time.sleep(1.5)
  286. sound = pygame.mixer.Sound(project_root + "/sounds/bad.wav")
  287. sound.play()
  288. while pygame.mixer.get_busy():
  289. pygame.time.delay(100)
  290.  
  291.  
  292. def main():
  293. os.system('cls' if os.name == 'nt' else 'clear')
  294. print("__ __ _ ____ ")
  295. print("\ \ / /__ __ _ ___| |/ ___|___ ")
  296. print(" \ \ /\ / / _ \/ _` / __| | | / _ \ ")
  297. print(" \ V V / __/ (_| \__ \ | |__| (_) |")
  298. print(" \_/\_/ \___|\__,_|___/_|\____\___/ ")
  299. time.sleep(2)
  300. os.system('cls' if os.name == 'nt' else 'clear')
  301.  
  302. line("=============================================================================")
  303. line("====================(c) Copyright 2045 WeaslCo Industries====================")
  304. line("=============================================================================")
  305. line("Loading WeaslCo Industries OS v1.3.6...")
  306. line("Memory Check: 0%")
  307. line("Memory Check: 10%")
  308. line("Memory Check: 67%")
  309. line("Memory Check: 100%")
  310. if random.random() < 0.85:
  311. line("Memory Check Found 8192KB of RAM")
  312. line("Loading Kernel...")
  313. time.sleep(random.uniform(1.5, 5.5))
  314. line("Kernel Loaded Successfully")
  315. line("Loading User Interface...")
  316. time.sleep(random.uniform(1.5, 5.5))
  317. line("User Interface Loaded Successfully")
  318. line("Connecting to servers...")
  319. time.sleep(random.uniform(1.5, 5.5))
  320. line("Connected to servers.")
  321. time.sleep(random.uniform(1.5, 5.5))
  322. sound = pygame.mixer.Sound(project_root + "/sounds/good.wav")
  323. sound.play()
  324. while pygame.mixer.get_busy():
  325. pygame.time.delay(100)
  326.  
  327. os.system('cls' if os.name == 'nt' else 'clear')
  328.  
  329. password()
  330.  
  331. line("====================(c) Copyright 2045 WeaslCo Industries====================")
  332. line("=============================================================================")
  333. line("Welcome to WeaslCo Industries OS v1.3.6 - Connected to servers.")
  334. line("Current commands: word, mail, browser, hp (hackpractice), exit")
  335. while True:
  336. user_input = input("A:\ > ")
  337. if user_input not in home:
  338. enter.play()
  339. print(f"Command '{user_input}' not recognized.")
  340. if user_input == "exit":
  341. print("Closing Operating System. Goodbye!")
  342. break
  343. elif user_input == "word":
  344. enter.play()
  345. print("Opening Word Processor...")
  346. time.sleep(2.35)
  347. word()
  348. elif user_input == "mail":
  349. enter.play()
  350. print("Opening Mail...")
  351. mail()
  352. elif user_input == "browser":
  353. enter.play()
  354. print("Opening Browser...")
  355. time.sleep(7.352)
  356. browser()
  357. elif user_input == "hp" or user_input == "hackpractice":
  358. enter.play()
  359. hacking()
  360.  
  361. else:
  362. error()
  363.  
  364.  
  365. main()
  366.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement