Advertisement
Guest User

Survival Island

a guest
May 17th, 2016
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.09 KB | None | 0 0
  1. import random
  2.  
  3. class game:
  4. def __init__(self):
  5. self.line_break = "-" * 50
  6. self.craft_items1 = {'campfire':'wood flint rock', 'stone axe':'stick rock', 'wooden shelter':'wood','medicine':'herb waterbottle','bandage':'cotton vine','stone hoe':'stick rock','fishing rod':'stick string'}
  7. self.player_inventory = ['stick','stick','rock','rock']
  8. self.forest_items = ["apple","string","rock","vine","flint", "stick"]
  9. self.sand_items = ["seashell","string","waterbottle","nothing"]
  10. self.pond_items = ["coin","nothing"]
  11. self.grassland_items = ["herb","silk","nothing","cotton seed"]
  12. self.weathers = ["rainy","sunny","cloudy","stormy"]
  13. self.timeofday = ['morning','noon','evening','night','midnight']
  14. self.random_location = ['on sand','in a forest','at a pond','on grassland']
  15. self.energy = 100
  16. self.current_time = ""
  17. self.current_day = 1
  18. self.minute = 30
  19. self.timer = 0
  20. self.hour = 12
  21. self.tt = "AM"
  22. self.timeadd = 30
  23. self.health = 'Healthy'
  24. self.weather = random.choice(self.weathers)
  25. self.blp = "O"
  26. self.bp = "O"
  27. self.brp = "O"
  28. self.mlp = "O"
  29. self.base = "X"
  30. self.mrp = "O"
  31. self.tlp = "O"
  32. self.tp = "O"
  33. self.trp = "O"
  34. self.blploc = random.choice(self.random_location)
  35. self.bploc = random.choice(self.random_location)
  36. self.brploc = random.choice(self.random_location)
  37. self.mlploc = random.choice(self.random_location)
  38. self.baseloc = "at base."
  39. self.mrploc = random.choice(self.random_location)
  40. self.tlploc = random.choice(self.random_location)
  41. self.tploc = random.choice(self.random_location)
  42. self.trploc = random.choice(self.random_location)
  43. self.current_location = ""
  44. self.inventory = {}
  45. self.play_game()
  46. def page1(self):
  47. print "SURVIVAL CRAFT BOOK"
  48. print self.line_break
  49. print "Name : Required Materials"
  50. print self.line_break
  51. print "(1) Campfire : 5x Wood + Flint + Rock"
  52. print "Description: Used to cook food, provide heat, & light"
  53. print self.line_break
  54. print "(2) Stone Axe : Stick + Rock"
  55. print "Description: Used to collect wood"
  56. print self.line_break
  57. print "(3) Wooden Shelter : 10x Wood"
  58. print "Description: Keeps you safe"
  59. print self.line_break
  60. print "PAGE 1 / 10"
  61. def page2(self):
  62. print "(4) Medicine : 2x Herbs + Water"
  63. print "Description: Cures sickness"
  64. print self.line_break
  65. print "(5) Bandage : Cotton + Vine"
  66. print "Description: Prevent infection on wounds"
  67. print self.line_break
  68. print "(6) Stone Hoe : Stick + Rock"
  69. print "Description: Used for farming"
  70. print self.line_break
  71. print "PAGE 2 / 10"
  72. def page3(self):
  73. print "(7) Fishing Rod : 3x Sticks + 2x Strings"
  74. print "Description: Perfect for obtaining food."
  75. print self.line_break
  76. print "(8) Food: Food + campfire"
  77. print "Description: Always cook raw food before eating."
  78. print self.line_break
  79. print "(9)"
  80. def craft_book(self):
  81. finished = False
  82. page = 1
  83. self.page1()
  84. while not finished:
  85. bookinput = raw_input(">").lower()
  86. if bookinput in ("next","n"):
  87. if page == 3:
  88. print "The rest of the pages have been ripped out."
  89. elif page == 1:
  90. page += 1
  91. self.page2()
  92. elif page == 2:
  93. page += 1
  94. self.page3()
  95. elif bookinput in ("close", "c"):
  96. finished = True
  97. elif bookinput in ("back", "b"):
  98. if page == 1:
  99. print "You are at the first page"
  100. elif page == 2:
  101. page -= 1
  102. self.page1()
  103. elif page == 3:
  104. page -= 1
  105. self.page2()
  106. else:
  107. print "Type (n)ext, (c)lose, or (b)ack."
  108. def GameMap(self):
  109. print "MAP"
  110. print "{} {} {}".format(self.tlp,self.tp,self.trp)
  111. print "{} {} {}".format(self.mlp,self.base,self.mrp)
  112. print "{} {} {}".format(self.blp,self.bp,self.brp)
  113. print "--------"
  114. print "X = You"
  115. def discard_item(self):
  116. for item in self.player_inventory:
  117. print item
  118. discardinput = raw_input("What do you want to trash?").lower()
  119. if discardinput in self.player_inventory:
  120. self.player_inventory.remove(discardinput)
  121. elif discardinput in ("cancel", "c"):
  122. print ""
  123. else:
  124. print "{} not in inventory.".format(discardinput)
  125. def skip_day(self):
  126. if self.base == "X":
  127. self.energy = 100
  128. self.current_time = ""
  129. self.current_day += 1
  130. self.minute = "00"
  131. self.timer = 0
  132. self.hour = 6
  133. self.tt = "AM"
  134. else:
  135. print "You have to be at base to sleep!"
  136. def craft(self):
  137. craftinput = raw_input("Craft: ").lower()
  138. if craftinput not in self.craft_items1 and craftinput not in ("cancel", "c"):
  139. print "{} is not a valid item!".format(craftinput)
  140. elif craftinput in ("cancel", "c"):
  141. print ""
  142. elif craftinput in self.craft_items1 and self.energy >= 20:
  143. result = 0
  144. quantity = raw_input("How much {} do you want to make?".format(craftinput))
  145. if quantity.isdigit():
  146. for times in range(int(quantity)):
  147. for material in self.craft_items1[craftinput].split():
  148. if material in self.player_inventory:
  149. result += 1
  150. if result == len(self.craft_items1[craftinput].split() * int(quantity)):
  151. print "Successfully crafted {} {}(s)".format(quantity,craftinput)
  152. for times in range(int(quantity)):
  153. for material in self.craft_items1[craftinput].split():
  154. if material in self.player_inventory:
  155. self.player_inventory.remove(material)
  156. else:
  157. return ""
  158. for times in range(int(quantity)):
  159. self.player_inventory.append(craftinput)
  160. self.energy -= 20
  161. self.timer += 10
  162. else:
  163. print "You do not have enough materials to craft {} {}!".format(quantity,craftinput)
  164. else:
  165. print "{} is not a valid number.".format(quantity)
  166. else:
  167. print "You are too tired to craft anything."
  168. def update_position(self):
  169. if self.base == "X":
  170. self.current_location = self.baseloc
  171. elif self.tlp == "X":
  172. self.current_location = self.tlploc
  173. elif self.tp == "X":
  174. self.current_location = self.tploc
  175. elif self.trp == "X":
  176. self.current_location = self.trploc
  177. elif self.mrp == "X":
  178. self.current_location = self.mrploc
  179. elif self.mlp == "X":
  180. self.current_location = self.mlploc
  181. elif self.trp == "X":
  182. self.current_location = self.trploc
  183. elif self.tp == "X":
  184. self.current_location = self.tploc
  185. elif self.tlp == "X":
  186. self.current_location = self.tlploc
  187. def scavenge(self):
  188. if self.energy >= 10 and len(self.player_inventory) <= 10:
  189. if self.current_location == "on sand":
  190. self.random_item = random.choice(self.sand_items)
  191. if self.random_item == "nothing":
  192. print "You found nothing"
  193. self.energy -= 10
  194. self.timer += 5
  195. else:
  196. self.player_inventory.append(self.random_item)
  197. print "You found a {}".format(self.random_item)
  198. self.energy -= 10
  199. self.timer += 5
  200.  
  201. elif self.current_location == "in a forest":
  202. self.random_item = random.choice(self.forest_items)
  203. if self.random_item == "nothing":
  204. print "You found nothing"
  205. self.energy -= 10
  206. self.timer += 5
  207. else:
  208. self.player_inventory.append(self.random_item)
  209. print "You found a {}".format(self.random_item)
  210. self.energy -= 10
  211. self.timer += 5
  212.  
  213. elif self.current_location == "at a pond":
  214. self.random_item = random.choice(self.pond_items)
  215. if self.random_item == "nothing":
  216. print "You found nothing"
  217. self.energy -= 10
  218. self.timer += 5
  219. else:
  220. self.player_inventory.append(self.random_item)
  221. print "You found a {}".format(self.random_item)
  222. self.energy -= 10
  223. self.timer += 5
  224.  
  225. elif self.current_location == "on grassland":
  226. self.random_item = random.choice(self.grassland_items)
  227. if self.random_item == "nothing":
  228. print "You found nothing"
  229. self.energy -= 10
  230. self.timer += 5
  231. else:
  232. self.player_inventory.append(self.random_item)
  233. print "You found a {}".format(self.random_item)
  234. sel.energy -= 10
  235. self.timer += 5
  236. else:
  237. print "You cannot scavenge at base."
  238. elif len(self.player_inventory) > 25:
  239. print "You cannot carry anymore items."
  240. else:
  241. print "You are too tired to scavenge."
  242. def update_time(self):
  243. self.current_time = "{}:{} {}".format(self.hour,self.minute,self.tt)
  244. if self.timer == 30:
  245. if self.minute == "00":
  246. self.minute = 0
  247. self.minute += self.timeadd
  248. self.current_time = "{}:{} {}".format(self.hour,self.minute,self.tt)
  249. self.timer -= 30
  250. if self.minute == 60:
  251. self.minute = 0
  252. self.hour += 1
  253. self.current_time = "{}:{} {}".format(self.hour,self.minute,self.tt)
  254. if self.current_time == "12:30 AM":
  255. self.hour = 1
  256. self.minute = "00"
  257. self.tt = "PM"
  258. self.current_time = "{}:{} {}".format(self.hour,self.minute,self.tt)
  259. def move(self):
  260. moveinput = raw_input("Move (r)ight, (l)eft, (d)own, or (u)p?").lower()
  261. if moveinput in ("r", "right"):
  262. if self.base == "X":
  263. self.base = "O"
  264. self.mrp = "X"
  265. self.timer += 5
  266. elif self.mrp == "X":
  267. print "Can't move into the ocean"
  268. elif self.mlp == "X":
  269. self.timer += 5
  270. self.mlp = "O"
  271. self.base = "X"
  272. elif self.trp == "X":
  273. print "Can't move into the ocean"
  274. elif self.tlp == "X":
  275. self.tlp = "O"
  276. self.tp = "X"
  277. self.timer += 5
  278. elif self.tp == "X":
  279. self.tp = "O"
  280. self.trp = "X"
  281. self.timer += 5
  282. elif self.blp == "X":
  283. self.blp = "O"
  284. self.bp = "X"
  285. self.timer += 5
  286. elif self.bp == "X":
  287. self.bp = "O"
  288. self.brp = "X"
  289. self.timer += 5
  290. elif self.brp == "X":
  291. print "Can't move into the ocean"
  292. elif moveinput in ("l", "left"):
  293. if self.base == "X":
  294. self.base = "O"
  295. self.mlp = "X"
  296. self.timer += 5
  297. elif self.mrp == "X":
  298. self.mrp = "O"
  299. self.base = "X"
  300. self.timer += 5
  301. elif self.mlp == "X":
  302. print "Can't move into the ocean"
  303. elif self.trp == "X":
  304. self.trp = "O"
  305. self.tp = "X"
  306. self.timer += 5
  307. elif self.tlp == "X":
  308. print "Can't move into the ocean"
  309. elif self.tp == "X":
  310. self.tp = "O"
  311. self.tlp = "X"
  312. self.timer += 5
  313. elif self.blp == "X":
  314. print "Can't move into the ocean"
  315. elif self.bp == "X":
  316. self.bp = "O"
  317. self.blp = "X"
  318. self.timer += 5
  319. elif self.brp == "X":
  320. self.brp = "O"
  321. self.bp = "X"
  322. self.timer += 5
  323. elif moveinput in ("u", "up"):
  324. if self.base == "X":
  325. self.base = "O"
  326. self.tp = "X"
  327. self.timer += 5
  328. elif self.mrp == "X":
  329. self.mrp = "O"
  330. self.trp = "X"
  331. self.timer += 5
  332. elif self.mlp == "X":
  333. self.mlp = "O"
  334. self.tlp = "X"
  335. self.timer += 5
  336. elif self.trp == "X":
  337. print "Can't move into the ocean"
  338. elif self.tlp == "X":
  339. print "Can't move into the ocean"
  340. elif self.tp == "X":
  341. print "Can't move into the ocean"
  342. elif self.blp == "X":
  343. self.blp = "O"
  344. self.mlp = "X"
  345. elif self.bp == "X":
  346. self.bp = "O"
  347. self.base = "X"
  348. self.timer += 5
  349. elif self.brp == "X":
  350. self.brp = "O"
  351. self.mrp = "X"
  352. self.timer += 5
  353. elif moveinput in ("d", "down"):
  354. if self.base == "X":
  355. self.base = "O"
  356. self.bp = "X"
  357. self.timer += 5
  358. elif self.mrp == "X":
  359. self.mrp = "O"
  360. self.brp = "X"
  361. self.timer += 5
  362. elif self.mlp == "X":
  363. self.mlp = "O"
  364. self.blp = "X"
  365. self.timer += 5
  366. elif self.trp == "X":
  367. self.trp = "O"
  368. self.mrp = "X"
  369. self.timer += 5
  370. elif self.tlp == "X":
  371. self.tlp = "O"
  372. self.mlp = "X"
  373. self.timer += 5
  374. elif self.tp == "X":
  375. self.tp = "O"
  376. self.base = "X"
  377. self.timer += 5
  378. elif self.blp == "X":
  379. print "Can't move into the ocean."
  380. elif self.bp == "X":
  381. print "Can't move into the ocean."
  382. elif self.brp == "X":
  383. print "Can't move into the ocean."
  384. def play_game(self):
  385. print "ISLAND SURVIVAL (IN DEV)"
  386. desc = """You are stranded on an island with limited resources, try to stay alive as long as possible because you cannot escape the island. More features will come out soon, as this game is still in dev."""
  387. print self.line_break
  388. print desc
  389. dead = False
  390. while not dead:
  391. self.update_time()
  392. self.update_position()
  393. print "Day {}".format(self.current_day)
  394. print "Time: {}".format(self.current_time)
  395. print "You are {}".format(self.current_location)
  396. print "Energy: {}".format(self.energy)
  397. gameinput = raw_input("Action: ").lower()
  398. if gameinput in ("craft","c"):
  399. self.craft()
  400. elif gameinput in ("craftbook", "craft book", "book", "cb"):
  401. self.craft_book()
  402. elif gameinput in ("move", "m"):
  403. self.move()
  404. elif gameinput == "map":
  405. self.GameMap()
  406. elif gameinput in ("discard","d","trash","t"):
  407. self.discard_item()
  408. elif gameinput in ("inventory","i","check inventory","ci"):
  409. print "Inventory"
  410. print self.line_break
  411. linenumber = 1
  412. for item in self.player_inventory:
  413. print "({}) {}".format(linenumber,item)
  414. linenumber += 1
  415. elif gameinput == "sleep":
  416. self.skip_day()
  417. elif gameinput == "quit":
  418. dead = True
  419. elif gameinput in ("scavenge","s"):
  420. self.scavenge()
  421. elif gameinput == "check":
  422. print self.timer
  423. else:
  424. print "Type (c)raft, (m)ove, map, craft book, (s)cavenge, (i)nventory, sleep"
  425.  
  426. game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement