Advertisement
mattamadda

Untitled

Oct 16th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.24 KB | None | 0 0
  1. #text rpg
  2. # Matthew Clarke
  3. #terminal game (no flask)
  4.  
  5. import cmd #uses command line
  6. import textwrap #wraps text on console
  7. import sys #system funtions
  8. import os #os related functions
  9. import time #time functions
  10. import random #random gen (rolling a dice)
  11.  
  12. screen_width = 100 #define console screensize
  13.  
  14. #### Create your Player ####
  15. class player:
  16. def __init__(self): #initialse function as itself
  17. self.name = ''
  18. self.job = ''
  19. self.hp = 0
  20. self.mp = 0
  21. self.status_effects = [] #this will all be used to store values for the players character
  22. self.location = 'start' #stored string, where the player is currently
  23. self.game_over = False
  24. myPlayer = player() #call the function 'player' inside the class
  25.  
  26. #### Title screen ####
  27. #play help or quit commands#
  28. def title_screen_selections():
  29. option = input("-> ") #something someone will type into the comand prompt
  30. if option.lower() == ("play"):
  31. setup_game() #placeholder until written
  32. elif option.lower() ==("help"):
  33. help_menu()
  34. elif option.lower() ==("quit"):
  35. sys.exit() #imported from import sys
  36. while option.lower() not in ['play', 'help', 'quit']: #if the person doesnt type one of these command cycle through to promt them to type an acceptable value
  37. print("please enter a valid command.(play, help or quit)")
  38. option = input("-> ")
  39. if option.lower() == ("play"):
  40. setup_game() #placeholder until written
  41. elif option.lower() ==("help"):
  42. help_menu()
  43. elif option.lower() ==("quit"):
  44. sys.exit()
  45. def title_screen():
  46. os.system('clear')
  47. print('################################')
  48. print('# Welcome to my text game! #')
  49. print('################################')
  50. print(' #-PLAY-# ')
  51. print(' #-HELP-# ')
  52. print(' #-QUIT-# ')
  53. title_screen_selections() #call the player options after printing the home screen ( use () so the function is called to run)
  54.  
  55. def help_menu():
  56. print('################################')
  57. print('# Welcome to my text game! #')
  58. print('################################')
  59. print('-type: up, down, left and right to move-')
  60. print('- type all commands to do them-')
  61. print('-Use "look" to inspect something-')
  62. print('################################')
  63. print(' -Good luck- ')
  64. print('################################')
  65. title_screen_selections() #once again, call the title screen selections option
  66.  
  67. ####### MAP #######
  68. #a1 a2 a3 a4 visualising the map for myself, player starts at b2
  69. #-------------
  70. #| | | | | a4
  71. #-------------
  72. #| | x| | | b4
  73. #-------------
  74. #| | | | | c4
  75. #-------------
  76. #| | | | | e4
  77. #-------------
  78. ZONENAME = '' #The name of the currect players zone
  79. DESCRIPTION = 'description' # user will type description for a description of their current location
  80. EXAMINATION = 'examine' #examine command examines something in the world
  81. SOLVED = False
  82. UP = 'up', 'north'
  83. DOWN = 'down', 'south'
  84. RIGHT = 'right', 'east'
  85. LEFT = 'left', 'west'
  86. #now we create our grid system
  87. solved_places = {'a1': False, 'a2': False, 'a3': False, 'a4': False,
  88. 'b1': False, 'b2': False, 'b3': False, 'b4': False,
  89. 'c1': False, 'c2': False, 'c3': False, 'c4': False,
  90. 'd1': False, 'd2': False, 'd3': False, 'd4': False,
  91. } #{} in python adds to a dictionary, a1 is the key for the value False
  92. #now we code each zone, again adding them into a dictionary and another dictionary within that dictionary. Like a terminal based database ( research how to convert to SQL later?)
  93. zonemap = {
  94. #A section
  95. 'a1': { #each zone will have differant attributes to make the game feel more alive
  96. ZONENAME: "Trade district",
  97. DESCRIPTION: 'description',
  98. EXAMINATION: 'examine',
  99. SOLVED: False,
  100. UP: '',
  101. DOWN: 'b1',
  102. RIGHT: 'a1',
  103. LEFT: '',
  104. },
  105. 'a2': {
  106. ZONENAME: 'City Gates',
  107. DESCRIPTION: 'description',
  108. EXAMINATION: 'examine',
  109. SOLVED: False,
  110. UP: '',
  111. DOWN: 'b2',
  112. RIGHT: 'a3',
  113. LEFT: 'a1',
  114. },
  115. 'a3': {
  116. ZONENAME: 'City Square',
  117. DESCRIPTION: 'description',
  118. EXAMINATION: 'examine',
  119. SOLVED: False,
  120. UP: '',
  121. DOWN: 'b3',
  122. RIGHT: 'a4',
  123. LEFT: 'a2',
  124. },
  125. 'a4': {
  126. ZONENAME: 'City Dungeons',
  127. DESCRIPTION: 'description',
  128. EXAMINATION: 'examine',
  129. SOLVED: False,
  130. UP: '',
  131. DOWN: 'b4',
  132. RIGHT: '',
  133. LEFT: 'a3',
  134. },
  135. 'b1': { #B section
  136. ZONENAME: 'Yellow Feather Town',
  137. DESCRIPTION: 'Yellow feather Town is a small bundle of houses located outside Altdorf, It is mainly used by travellers who visit the inn',
  138. EXAMINATION: 'As you wander around the small town you catch people staring at you, You feel out of place',
  139. SOLVED: False,
  140. UP: 'a2',
  141. DOWN: 'c1',
  142. RIGHT: 'b2',
  143. LEFT: '',
  144. },
  145. 'b2': {
  146. ZONENAME: 'Yellow Feather Inn',
  147. DESCRIPTION: 'The Yellow Feather Inn is a safe spot for you, The inn keeper has provided you with a room, It is located just south of the City of Altdorf',
  148. EXAMINATION: 'This inn is filled with shadey looking people, Best not cause any trouble here',
  149. SOLVED: False,
  150. UP: 'a2',
  151. DOWN: 'c2',
  152. RIGHT: 'b3',
  153. LEFT: 'b1',
  154. },
  155. 'b3': {
  156. ZONENAME: '',
  157. DESCRIPTION: 'description',
  158. EXAMINATION: 'examine',
  159. SOLVED: False,
  160. UP: 'up',
  161. DOWN: 'down',
  162. RIGHT: 'right',
  163. LEFT: 'left',
  164. },
  165. 'b4': {
  166. ZONENAME: '',
  167. DESCRIPTION: 'description',
  168. EXAMINATION: 'examine',
  169. SOLVED: False,
  170. UP: 'up',
  171. DOWN: 'down',
  172. RIGHT: 'right',
  173. LEFT: 'left',
  174. },
  175. 'c1': { #c section
  176. ZONENAME: '',
  177. DESCRIPTION: 'description',
  178. EXAMINATION: 'examine',
  179. SOLVED: False,
  180. UP: 'up',
  181. DOWN: 'down',
  182. RIGHT: 'right',
  183. LEFT: 'left',
  184. },
  185. 'c2': {
  186. ZONENAME: '',
  187. DESCRIPTION: 'description',
  188. EXAMINATION: 'examine',
  189. SOLVED: False,
  190. UP: 'up',
  191. DOWN: 'down',
  192. RIGHT: 'right',
  193. LEFT: 'left',
  194. },
  195. 'c3': {
  196. ZONENAME: '',
  197. DESCRIPTION: 'description',
  198. EXAMINATION: 'examine',
  199. SOLVED: False,
  200. UP: 'up',
  201. DOWN: 'down',
  202. RIGHT: 'right',
  203. LEFT: 'left',
  204. },
  205. 'c4': {
  206. ZONENAME: '',
  207. DESCRIPTION: 'description',
  208. EXAMINATION: 'examine',
  209. SOLVED: False,
  210. UP: 'up',
  211. DOWN: 'down',
  212. RIGHT: 'right',
  213. LEFT: 'left',
  214. },
  215. 'd1': { #d section
  216. ZONENAME: '',
  217. DESCRIPTION: 'description',
  218. EXAMINATION: 'examine',
  219. SOLVED: False,
  220. UP: 'up',
  221. DOWN: 'down',
  222. RIGHT: 'right',
  223. LEFT: 'left',
  224. },
  225. 'd2': {
  226. ZONENAME: '',
  227. DESCRIPTION: 'description',
  228. EXAMINATION: 'examine',
  229. SOLVED: False,
  230. UP: 'up',
  231. DOWN: 'down',
  232. RIGHT: 'right',
  233. LEFT: 'left',
  234. },
  235. 'd3': {
  236. ZONENAME: '',
  237. DESCRIPTION: 'description',
  238. EXAMINATION: 'examine',
  239. SOLVED: False,
  240. UP: 'up',
  241. DOWN: 'down',
  242. RIGHT: 'right',
  243. LEFT: 'left',
  244. },
  245. 'd4': {
  246. ZONENAME: '',
  247. DESCRIPTION: 'description',
  248. EXAMINATION: 'examine',
  249. SOLVED: False,
  250. UP: 'up',
  251. DOWN: 'down',
  252. RIGHT: 'right',
  253. LEFT: 'left',
  254. }
  255. }
  256.  
  257.  
  258. ####### GAME INTERACTIVITY ######
  259. def print_location(): #print location statement
  260. print('\n' + ('#' * (4 + len(myPlayer.location))))#\n makes it print on a new line
  261. print('# ' + myPlayer.location.upper() + ' #')
  262. print('# ' + zonemap[myPlayer.position] [DESCRIPTION] + ' #')
  263. print('\n' + ('#' * (4 + len(myPlayer.location)))) #this line adds padding of the word * 4 in hastags to improve console visuals
  264.  
  265. def prompt():
  266. print("\n" + "======================")
  267. print("What would you like to do?")
  268. action = input("-> ") #ask for the users input
  269. acceptable_actions = ['move', 'go', 'travel', 'walk', 'quit', 'examine', 'inspect', 'interact', 'look'] #determine acceptable user inputs
  270. while action.lower() not in acceptable_actions: #if the entered action is not acceptable
  271. print("Unknown action, try again.\n")
  272. action = input("-> ")
  273. if action.lower() == 'quit':
  274. sys.exit()
  275. elif action.lower() in ['move', 'go', 'travel', 'walk']:
  276. player_move(action.lower())
  277. elif action.lower() in ['examine', 'inspect', 'interact', 'look']:
  278. player_examine(action.lower())
  279.  
  280. def player_move(myAction):
  281. ask = "where would you like to go?\n" #defining where the user is travelling to
  282. destination = input(ask)
  283. if dest in ['up', 'north']:
  284. destination = zonemap[myPlayer.location][UP]
  285. movement_handler(destination)
  286. elif dest in ['down', 'south']:
  287. destination = zonemap[myPlayer.location][DOWN]
  288. movement_handler(destination)
  289. elif dest in ['right', 'east']:
  290. destination = zonemap[myPlayer.location][RIGHT]
  291. movement_handler(destination)
  292. elif dest in ['left', 'west']:
  293. destination = zonemap[myPlayer.location][LEFT]
  294. movement_handler(destination)
  295.  
  296. def movement_handler(destination):
  297. print("\n" + "You have moved to " + destination + ".")
  298. myPlayer.location = destination
  299. print_location()
  300.  
  301. def player_examine(action):
  302. if zonemap[myPlayer.location] [SOLVED]:
  303. print("This Zone is safe.... For now.")
  304. else:
  305. print("") #trigger a puzzle here
  306.  
  307. ####### Game functions ##########
  308. def main_game_loop():
  309. while myPlayer.game_over is False:
  310. prompt()
  311. # here handle if puzzles have been solved, boss defeated, explored everything, ect.
  312.  
  313. def setup_game():
  314. os.system('clear')
  315. #naming the character
  316. question1 = "What is your characters name?\n"
  317. for character in question1:
  318. sys.stdout.write(character)
  319. sys.stdout.flush()
  320. time.sleep(0.05) #add delay to the text being presented to the user
  321. player_name = input ("-> ")
  322. myPlayer.name = player_name
  323. ##picking player class
  324. question2 = "What's your combat style?\n"
  325. question2added = "(type: warrior, wizard or archer)\n" # assigning second line of text
  326. for character in question2:
  327. sys.stdout.write(character)
  328. sys.stdout.flush()
  329. for character in question2added:
  330. sys.stdout.write(character)
  331. sys.stdout.flush()
  332. time.sleep(0.01) #sped this section up as it is a command and not 'npc' text
  333. player_job = input ("-> ")
  334. valid_jobs = ['warrior', 'wizard', 'archer'] #assigning valid game classes
  335. if player_job.lower() in valid_jobs:
  336. myPlayer.job = player_job
  337. print(player_job + " is your selected class!\n")
  338. else:
  339. while player_job.lower() not in valid_jobs:
  340. player_job = input("-> ")
  341. if player_job.lower() in valid_jobs:
  342. myPlayer.job = player_job
  343. print(player_job + " is your selected class!\n")
  344.  
  345. #player stats
  346. if myPlayer.job is 'warrior':
  347. self.hp = 120
  348. self.mp = 10
  349. elif myPlayer.job is 'wizard':
  350. self.hp = 50
  351. self.mp = 100
  352. elif myPlayer.job is 'archer':
  353. self.hp = 75
  354. self.mp = 30
  355.  
  356. ##inroduction
  357. question3 = "Welcome to the Yellow Feather Inn, " + myPlayer.name + " the " + player_job + ".\n"
  358. for character in question3:
  359. sys.stdout.write(character)
  360. sys.stdout.flush()
  361. time.sleep(0.05) #add delay to the text being presented to the user
  362. player_name = input ("-> ")
  363. myPlayer.name = player_name
  364.  
  365. speech1 = "Welcome to the Yellow Feather inn Adventurer"
  366. speech2 = "head North into the city of Altdorf or stick around here a while"
  367. speech3 = "Just make sure you dont wander too far off the road"
  368. speech4 = "Can never be too careful round these parts...."
  369. print("The innkeeper leaves your room while glaring over his shoulder \n")
  370. for character in speech1:
  371. sys.stdout.write(character)
  372. sys.stdout.flush()
  373. time.sleep(0.03)
  374. for character in speech2:
  375. sys.stdout.write(character)
  376. sys.stdout.flush()
  377. time.sleep(0.03)
  378. for character in speech3:
  379. sys.stdout.write(character)
  380. sys.stdout.flush()
  381. time.sleep(0.1)
  382. for character in speech4:
  383. sys.stdout.write(character)
  384. sys.stdout.flush()
  385. time.sleep(0.2)
  386.  
  387. os.system('clear')
  388. print("###########################")
  389. print("# begin your adventure #")
  390. print("###########################")
  391. main_game_loop()
  392.  
  393. title_screen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement