Advertisement
Guest User

mrss

a guest
Dec 13th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.26 KB | None | 0 0
  1. import mysql.connector as mariadb
  2. import sys
  3. import wave
  4. import pygame
  5. import time
  6. import msvcrt as m
  7. import re
  8.  
  9. #iskee pygamen tulille
  10. pygame.init()
  11.  
  12. #karsii pois turhat sanat
  13. def imp(inps):
  14. if 'at' in inps:
  15. inps.remove('at')
  16. if "and" in inps:
  17. inps.remove('and')
  18. if 'or' in inps :
  19. inps.remove('or')
  20. if 'with' in inps :
  21. inps.remove('with')
  22. if 'to' in inps:
  23. inps.remove('to')
  24. if 'into' in inps :
  25. inps.remove('into')
  26. return inps
  27.  
  28. #tulostaa tekstiä kirjain kerrallaan, ja odottaa painallusta
  29. def pri(str):
  30. string = (str)
  31. for char in string:
  32. sys.stdout.write(char)
  33. sys.stdout.flush()
  34. time.sleep(.02)
  35. m.getch()
  36. print("\n")
  37.  
  38. #intro. lataa taustapopin
  39. def intro():
  40.  
  41. music = "BGM"
  42. load_music(music)
  43. pri("You are 54 years old whitecollar worker Living in a highrise apartment located at Manhattan.")
  44. pri("Your career long ambition has been to become the Boss in place of the current Boss. And finally it's happening!")
  45. pri("The CEO announced his retirement and having brown nosed him for countless years, the job practically yours!")
  46. pri("You naturally spend your last sunday as a peon partying like it's 1984. In hindsight that might have been a mistake. As they say, don't count your snakes before they hatch.")
  47. pri("Can you make it without tanking your dreams? let's find out!")
  48. sound = "ALARM"
  49.  
  50. pri("You are woken up by the incessent beeping of your alarm clock. Your head feels like it's being raided by army of tax collectors and there is a faint taste of ass in your mouth.")
  51. pri("You also appear to have slept in your suit, which is badly rumbled and smells quite ripe.")
  52.  
  53.  
  54. #......
  55. def com_eat(target):
  56. cur = db.cursor(target)
  57. # esitellaan suoritettava sql-lause
  58. sql = "SELECT name , look FROM objects WHERE name='"+target+"'";
  59. # suoritetaan sql-lause
  60. cur.execute(sql)
  61. # jos saatiin dataa / file, niin ajetaan se
  62. if cur.rowcount >= 1 :
  63. for look in cur :
  64. cur = db.cursor(look)
  65. sql = "SELECT description FROM results WHERE resultid='"+look+"'";
  66. cur.execute(sql)
  67. for description in cur :
  68. pri(descruption)
  69.  
  70. #asettaa asian laukkuun
  71. def com_take(target):
  72. cur = db.cursor(target)
  73. # esitellaan suoritettava sql-lause
  74. sql = "SELECT name , look FROM objects WHERE name='"+target+"'";
  75. # suoritetaan sql-lause
  76. cur.execute(sql)
  77.  
  78. #duns no.
  79. def com_time():
  80. print("no")
  81.  
  82. #bob me olemme ongelma.
  83. def com_comb(target1, target2):
  84. cur1 = db.cursor(target1)
  85. # esitellaan suoritettava sql-lause
  86. sql = "SELECT name FROM objects WHERE name='"+target1+"'";
  87. cur1.execute(sql)
  88. cur2 = db.cursor(target2)
  89. sql = "SELECT name , look FROM rooms WHERE name='"+target+"'";
  90. cur2.execute(sql)
  91. # jos saatiin dataa / file, niin ajetaan se
  92. if cur1.rowcount >= 1 :
  93. print("no")
  94. if cur2.rowcount >= 1 :
  95. print("no")
  96.  
  97. #go lauseke. ei käytössä
  98. def com_go(target):
  99. cur = db.cursor(target)
  100. sql = "SELECT name , FROM rooms WHERE name='"+target+"'";
  101. cur.execute(sql)
  102. # jos saatiin dataa / file, niin ajetaan se
  103. if cur.rowcount >= 1 :
  104. print("no")
  105.  
  106. #... vaiheessa
  107. def com_wear(target):
  108. cur = db.cursor(target)
  109. # esitellaan suoritettava sql-lause
  110. sql = "SELECT name , look FROM objects WHERE name='"+target+"'";
  111. # suoritetaan sql-lause
  112. cur.execute(sql)
  113. # jos saatiin dataa / file, niin ajetaan se
  114. if cur.rowcount >= 1 :
  115. print("no")
  116.  
  117. #hakee tietokannasta esineen, joka katsonnan kohteena. sitten hakee asiaan kuuluvan replyn tietokannasta ja tulostaa sen.
  118. def com_look(target):
  119. cur = db.cursor()
  120. cur.execute("SELECT name , look FROM objects WHERE name='"+target+"'")
  121. for look in cur:
  122. cur.execute("SELECT description FROM results WHERE resultid='"+str(look[1])+"'")
  123. for col in cur.fetchall():
  124. pri(col[0])
  125.  
  126. #käyttölause... vaiheessa
  127. def com_use(obj):
  128. cur = db.cursor()
  129. cur.execute("SELECT state , use FROM objects WHERE name='"+obj+"'")
  130. # jos saatiin dataa / file, niin ajetaan se
  131. if cur.rowcount >= 1 :
  132. for col in cur :
  133. if col[2] == 1 :
  134. cur = db.cursor()
  135. sql = "UPDATE state FROM objects WHERE name='"+obj+"'";
  136. cur.execute(sql)
  137. if col[2] == 2:
  138. cur = db.cursor()
  139. sql = "UPDATE state FROM objects WHERE name='"+obj+"'";
  140. cur.execute(sql)
  141. if col[2] == 3:
  142. pri("can't do that anymore")
  143. break
  144. repl = col[3]
  145. cur = db.cursor()
  146. sql = "SELECT description FROM results WHERE resultid='"+repl+"'";
  147. cur.execute(sql)
  148. for col in cur:
  149. pri(col[0])
  150. return
  151.  
  152.  
  153.  
  154.  
  155. #hakee huoneen nimen ja sen sisältämät esineet ja tulostaa ne
  156. def load_room(loc):
  157. cur = db.cursor()
  158. cur.execute("SELECT name , ID , objects FROM rooms WHERE name='"+loc+"'")
  159. if cur.rowcount == 1 :
  160. for col in cur:
  161. pri("you are in " + col[0] + ".")
  162. cur.execute("SELECT name FROM objects WHERE location='"+col[1]+"'")
  163. for kek in cur.fetchall():
  164. temp.append(kek[0])
  165. pri("you see " + ' , '.join(temp) + " in the room.")
  166. else :
  167. print("DeprecationWarning")
  168. return
  169.  
  170. #hakee halutun esineen ja palauttaa sen nimen, statuksen
  171. def load_obj(target):
  172. cur = db.cursor()
  173. cur.execute("SELECT name , state FROM objects WHERE name='"+target+"'")
  174. if cur.rowcount >= 1 :
  175. for col in cur:
  176. obj = col[0]
  177. state = col[1]
  178. return obj , state
  179.  
  180. #hakee halutun komennon tietokannasta ja palauttaa sen
  181. def load_command(action):
  182. cur = db.cursor()
  183. cur.execute("SELECT id FROM commands WHERE name='"+action+"'")
  184. if cur.rowcount == 1 :
  185. for col in cur.fetchall() :
  186. command = col[0]
  187. return command
  188. else:
  189. print ("invalid command");
  190. return
  191.  
  192. #lataa aanen ja alkaa soittamaan
  193. def load_sound(sound):
  194. cur = db.cursor()
  195. cur.execute("SELECT ID , path , rep FROM sound WHERE sound='"+sound+"'")
  196. if cur.rowcount >= 1 :
  197. for col in cur :
  198. pygame.mixer.sound.load(col[1])
  199. pygame.mixer.sound.play(col[2])
  200.  
  201. #lopettaa soittamisen
  202. def unload_sound(sound):
  203. cur = db.cursor()
  204. cur.execute("SELECT ID , path , rep FROM sound WHERE sound='"+sound+"'")
  205. if cur.rowcount >= 1 :
  206. for col in cur :
  207. pygame.mixer.Sound.fadeout(col[2])
  208.  
  209. #lataa äänen ja alkaa soittamaan
  210. def load_music(music):
  211. cur = db.cursor()
  212. cur.execute("SELECT ID , file , rep FROM sound WHERE id='"+music+"'")
  213. # jos saatiin dataa / file, niin ajetaan se
  214. if cur.rowcount >= 1 :
  215. for col in cur :
  216. pygame.mixer.music.load(col[1])
  217. pygame.mixer.music.play(col[2])
  218.  
  219.  
  220. db = mariadb.connect(user='root', password='password', database='mrss', buffered=True)
  221.  
  222.  
  223. # Initialize gameplay
  224. temp = []
  225. action = ""
  226. row = ""
  227. obj = ""
  228. loc = "bedroom"
  229. command = ""
  230. inps = ""
  231. target1 = ""
  232. target2 = ""
  233. status = ""
  234. state = ""
  235. # Clear console
  236. print("\n"*100)
  237.  
  238. #lauch intro n room
  239. #~intro()
  240. load_room(loc)
  241.  
  242. #mainloop
  243. while action!="quit" and loc != "out":
  244. #pyytää komennon ja shaissea
  245. inps=input("wat you want to do? \n:").split()
  246. imp(inps)
  247.  
  248. #erittelee parserista komennon ja kohteen
  249. if len(inps)>=1:
  250. action = inps[0].lower()
  251. if action == "quit":
  252. pri("quitter, boo")
  253. break
  254. if len(inps)>=2:
  255. target = inps[1].lower()
  256. target1 = target
  257. print(target1)
  258. if len(inps)==3:
  259. target = inps[2].lower()
  260. target2 = target
  261. print(target2)
  262.  
  263. command = load_command(action)
  264.  
  265. #LOOK row 8
  266. if command == "LOOK":
  267. if len(inps) == 1:
  268. pri("you look around")
  269. load_room(loc)
  270. if len(inps) ==2:
  271. com_look(target)
  272. print("shit2")
  273. if len(inps) ==3:
  274. pri("you don't see shit")
  275.  
  276. #use row 12
  277. if command == "USE" :
  278. if len(inps) == 1:
  279. target = input("what would you like to use? \n:")
  280. load_obj(target)
  281. com_use(obj)
  282. if len(inps) == 2:
  283. load_obj(target)
  284. com_use(obj)
  285. if len(inps) >= 3:
  286. pri("can't do that")
  287.  
  288. #wear row13
  289. if command == "WEAR" :
  290. if len(inps) == 1:
  291. target = input("what would you like to wear? \n:")
  292. load_obj(target)
  293. com_wear(obj)
  294. if len(inps) == 2:
  295. load_obj(target)
  296. com_wear(obj)
  297.  
  298. #goto row 7
  299. if command == "GO" :
  300. if len(inps) == 1:
  301. loc = input("where would you like to go? \n:")
  302. load_room(loc)
  303. if len(inps) >=2:
  304. loc = target
  305. load_room(loc)
  306.  
  307. #time
  308. if command == "TIME" :
  309. com_time()
  310.  
  311. #Put/add/insert/combine row 9
  312. if command == "PUT" :
  313. if len(inps) == 1:
  314. inps=input("what would you like to combine? \n:").split()
  315. imp(inps)
  316. if len(input) ==1:
  317. target1 = input
  318. input("what would you like to combine " + target1 + " with? \n:").split()
  319. if len(input) ==1:
  320. target2 = input
  321. if len(input) > 1 :
  322. pri("can't do that")
  323. if len(input) ==2:
  324. target1 = input[1].lower()
  325. target2 = input[2].lower()
  326. pri("you attempt to combine " +target1 + target2 + ".")
  327. com_comb(target1 , target2)
  328. if len(inps) == 2:
  329. target1 = inps[1].lower()
  330. target2 = input(pri("what would you like to combine " + target1 + "with? \n:"))
  331. pri("you attempt to combine " + target1 + "and" + target2 + ".")
  332. com_comb(target1 , target2)
  333. if len(inps) ==3 :
  334. target1 = input[1].lower()
  335. target2 = input[2].lower()
  336. pri("you attempt to combine " + target1 + "and" + target2 + ".")
  337. com_comb(target1 , target2)
  338.  
  339. #help
  340. if command == "HELP" :
  341. pri("available commands are:")
  342. pri("help - prints command list")
  343. pri("look - look at stuff")
  344. pri("use - use or open stuff")
  345. pri("eat - eat stuff")
  346. pri("take - stuff into inv")
  347. pri("wear - equip stuff")
  348.  
  349. #take row 10
  350. if command == "TAKE" :
  351. if len(inps) == 1:
  352. target = input("what would you like to take \n:")
  353. load_obj(target)
  354. com_take(obj)
  355. if len(inps) == 2:
  356. load_obj(target)
  357. com_take(obj)
  358. if len(inps) >= 3:
  359. pri("can't do that")
  360.  
  361. #consume row 6
  362. if command =="CONSUME" :
  363. if len(inps) == 1:
  364. target = input("what would you like to eat? \n:")
  365. load_obj(target)
  366. com_eat(obj)
  367. if len(inps) == 2:
  368. load_obj(target)
  369. com_eat(obj)
  370. if len(inps) >= 3:
  371. pri("can't do that")
  372. else:
  373. print("")
  374.  
  375.  
  376.  
  377. db.rollback()
  378.  
  379.  
  380. # status row5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement