Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- class game:
- def __init__(self):
- self.line_break = "-" * 50
- 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'}
- self.player_inventory = ['stick','stick','rock','rock']
- self.forest_items = ["apple","string","rock","vine","flint", "stick"]
- self.sand_items = ["seashell","string","waterbottle","nothing"]
- self.pond_items = ["coin","nothing"]
- self.grassland_items = ["herb","silk","nothing","cotton seed"]
- self.weathers = ["rainy","sunny","cloudy","stormy"]
- self.timeofday = ['morning','noon','evening','night','midnight']
- self.random_location = ['on sand','in a forest','at a pond','on grassland']
- self.energy = 100
- self.current_time = ""
- self.current_day = 1
- self.minute = 30
- self.timer = 0
- self.hour = 12
- self.tt = "AM"
- self.timeadd = 30
- self.health = 'Healthy'
- self.weather = random.choice(self.weathers)
- self.blp = "O"
- self.bp = "O"
- self.brp = "O"
- self.mlp = "O"
- self.base = "X"
- self.mrp = "O"
- self.tlp = "O"
- self.tp = "O"
- self.trp = "O"
- self.blploc = random.choice(self.random_location)
- self.bploc = random.choice(self.random_location)
- self.brploc = random.choice(self.random_location)
- self.mlploc = random.choice(self.random_location)
- self.baseloc = "at base."
- self.mrploc = random.choice(self.random_location)
- self.tlploc = random.choice(self.random_location)
- self.tploc = random.choice(self.random_location)
- self.trploc = random.choice(self.random_location)
- self.current_location = ""
- self.inventory = {}
- self.play_game()
- def page1(self):
- print "SURVIVAL CRAFT BOOK"
- print self.line_break
- print "Name : Required Materials"
- print self.line_break
- print "(1) Campfire : 5x Wood + Flint + Rock"
- print "Description: Used to cook food, provide heat, & light"
- print self.line_break
- print "(2) Stone Axe : Stick + Rock"
- print "Description: Used to collect wood"
- print self.line_break
- print "(3) Wooden Shelter : 10x Wood"
- print "Description: Keeps you safe"
- print self.line_break
- print "PAGE 1 / 10"
- def page2(self):
- print "(4) Medicine : 2x Herbs + Water"
- print "Description: Cures sickness"
- print self.line_break
- print "(5) Bandage : Cotton + Vine"
- print "Description: Prevent infection on wounds"
- print self.line_break
- print "(6) Stone Hoe : Stick + Rock"
- print "Description: Used for farming"
- print self.line_break
- print "PAGE 2 / 10"
- def page3(self):
- print "(7) Fishing Rod : 3x Sticks + 2x Strings"
- print "Description: Perfect for obtaining food."
- print self.line_break
- print "(8) Food: Food + campfire"
- print "Description: Always cook raw food before eating."
- print self.line_break
- print "(9)"
- def craft_book(self):
- finished = False
- page = 1
- self.page1()
- while not finished:
- bookinput = raw_input(">").lower()
- if bookinput in ("next","n"):
- if page == 3:
- print "The rest of the pages have been ripped out."
- elif page == 1:
- page += 1
- self.page2()
- elif page == 2:
- page += 1
- self.page3()
- elif bookinput in ("close", "c"):
- finished = True
- elif bookinput in ("back", "b"):
- if page == 1:
- print "You are at the first page"
- elif page == 2:
- page -= 1
- self.page1()
- elif page == 3:
- page -= 1
- self.page2()
- else:
- print "Type (n)ext, (c)lose, or (b)ack."
- def GameMap(self):
- print "MAP"
- print "{} {} {}".format(self.tlp,self.tp,self.trp)
- print "{} {} {}".format(self.mlp,self.base,self.mrp)
- print "{} {} {}".format(self.blp,self.bp,self.brp)
- print "--------"
- print "X = You"
- def discard_item(self):
- for item in self.player_inventory:
- print item
- discardinput = raw_input("What do you want to trash?").lower()
- if discardinput in self.player_inventory:
- self.player_inventory.remove(discardinput)
- elif discardinput in ("cancel", "c"):
- print ""
- else:
- print "{} not in inventory.".format(discardinput)
- def skip_day(self):
- if self.base == "X":
- self.energy = 100
- self.current_time = ""
- self.current_day += 1
- self.minute = "00"
- self.timer = 0
- self.hour = 6
- self.tt = "AM"
- else:
- print "You have to be at base to sleep!"
- def craft(self):
- craftinput = raw_input("Craft: ").lower()
- if craftinput not in self.craft_items1 and craftinput not in ("cancel", "c"):
- print "{} is not a valid item!".format(craftinput)
- elif craftinput in ("cancel", "c"):
- print ""
- elif craftinput in self.craft_items1 and self.energy >= 20:
- result = 0
- quantity = raw_input("How much {} do you want to make?".format(craftinput))
- if quantity.isdigit():
- for times in range(int(quantity)):
- for material in self.craft_items1[craftinput].split():
- if material in self.player_inventory:
- result += 1
- if result == len(self.craft_items1[craftinput].split() * int(quantity)):
- print "Successfully crafted {} {}(s)".format(quantity,craftinput)
- for times in range(int(quantity)):
- for material in self.craft_items1[craftinput].split():
- if material in self.player_inventory:
- self.player_inventory.remove(material)
- else:
- return ""
- for times in range(int(quantity)):
- self.player_inventory.append(craftinput)
- self.energy -= 20
- self.timer += 10
- else:
- print "You do not have enough materials to craft {} {}!".format(quantity,craftinput)
- else:
- print "{} is not a valid number.".format(quantity)
- else:
- print "You are too tired to craft anything."
- def update_position(self):
- if self.base == "X":
- self.current_location = self.baseloc
- elif self.tlp == "X":
- self.current_location = self.tlploc
- elif self.tp == "X":
- self.current_location = self.tploc
- elif self.trp == "X":
- self.current_location = self.trploc
- elif self.mrp == "X":
- self.current_location = self.mrploc
- elif self.mlp == "X":
- self.current_location = self.mlploc
- elif self.trp == "X":
- self.current_location = self.trploc
- elif self.tp == "X":
- self.current_location = self.tploc
- elif self.tlp == "X":
- self.current_location = self.tlploc
- def scavenge(self):
- if self.energy >= 10 and len(self.player_inventory) <= 10:
- if self.current_location == "on sand":
- self.random_item = random.choice(self.sand_items)
- if self.random_item == "nothing":
- print "You found nothing"
- self.energy -= 10
- self.timer += 5
- else:
- self.player_inventory.append(self.random_item)
- print "You found a {}".format(self.random_item)
- self.energy -= 10
- self.timer += 5
- elif self.current_location == "in a forest":
- self.random_item = random.choice(self.forest_items)
- if self.random_item == "nothing":
- print "You found nothing"
- self.energy -= 10
- self.timer += 5
- else:
- self.player_inventory.append(self.random_item)
- print "You found a {}".format(self.random_item)
- self.energy -= 10
- self.timer += 5
- elif self.current_location == "at a pond":
- self.random_item = random.choice(self.pond_items)
- if self.random_item == "nothing":
- print "You found nothing"
- self.energy -= 10
- self.timer += 5
- else:
- self.player_inventory.append(self.random_item)
- print "You found a {}".format(self.random_item)
- self.energy -= 10
- self.timer += 5
- elif self.current_location == "on grassland":
- self.random_item = random.choice(self.grassland_items)
- if self.random_item == "nothing":
- print "You found nothing"
- self.energy -= 10
- self.timer += 5
- else:
- self.player_inventory.append(self.random_item)
- print "You found a {}".format(self.random_item)
- sel.energy -= 10
- self.timer += 5
- else:
- print "You cannot scavenge at base."
- elif len(self.player_inventory) > 25:
- print "You cannot carry anymore items."
- else:
- print "You are too tired to scavenge."
- def update_time(self):
- self.current_time = "{}:{} {}".format(self.hour,self.minute,self.tt)
- if self.timer == 30:
- if self.minute == "00":
- self.minute = 0
- self.minute += self.timeadd
- self.current_time = "{}:{} {}".format(self.hour,self.minute,self.tt)
- self.timer -= 30
- if self.minute == 60:
- self.minute = 0
- self.hour += 1
- self.current_time = "{}:{} {}".format(self.hour,self.minute,self.tt)
- if self.current_time == "12:30 AM":
- self.hour = 1
- self.minute = "00"
- self.tt = "PM"
- self.current_time = "{}:{} {}".format(self.hour,self.minute,self.tt)
- def move(self):
- moveinput = raw_input("Move (r)ight, (l)eft, (d)own, or (u)p?").lower()
- if moveinput in ("r", "right"):
- if self.base == "X":
- self.base = "O"
- self.mrp = "X"
- self.timer += 5
- elif self.mrp == "X":
- print "Can't move into the ocean"
- elif self.mlp == "X":
- self.timer += 5
- self.mlp = "O"
- self.base = "X"
- elif self.trp == "X":
- print "Can't move into the ocean"
- elif self.tlp == "X":
- self.tlp = "O"
- self.tp = "X"
- self.timer += 5
- elif self.tp == "X":
- self.tp = "O"
- self.trp = "X"
- self.timer += 5
- elif self.blp == "X":
- self.blp = "O"
- self.bp = "X"
- self.timer += 5
- elif self.bp == "X":
- self.bp = "O"
- self.brp = "X"
- self.timer += 5
- elif self.brp == "X":
- print "Can't move into the ocean"
- elif moveinput in ("l", "left"):
- if self.base == "X":
- self.base = "O"
- self.mlp = "X"
- self.timer += 5
- elif self.mrp == "X":
- self.mrp = "O"
- self.base = "X"
- self.timer += 5
- elif self.mlp == "X":
- print "Can't move into the ocean"
- elif self.trp == "X":
- self.trp = "O"
- self.tp = "X"
- self.timer += 5
- elif self.tlp == "X":
- print "Can't move into the ocean"
- elif self.tp == "X":
- self.tp = "O"
- self.tlp = "X"
- self.timer += 5
- elif self.blp == "X":
- print "Can't move into the ocean"
- elif self.bp == "X":
- self.bp = "O"
- self.blp = "X"
- self.timer += 5
- elif self.brp == "X":
- self.brp = "O"
- self.bp = "X"
- self.timer += 5
- elif moveinput in ("u", "up"):
- if self.base == "X":
- self.base = "O"
- self.tp = "X"
- self.timer += 5
- elif self.mrp == "X":
- self.mrp = "O"
- self.trp = "X"
- self.timer += 5
- elif self.mlp == "X":
- self.mlp = "O"
- self.tlp = "X"
- self.timer += 5
- elif self.trp == "X":
- print "Can't move into the ocean"
- elif self.tlp == "X":
- print "Can't move into the ocean"
- elif self.tp == "X":
- print "Can't move into the ocean"
- elif self.blp == "X":
- self.blp = "O"
- self.mlp = "X"
- elif self.bp == "X":
- self.bp = "O"
- self.base = "X"
- self.timer += 5
- elif self.brp == "X":
- self.brp = "O"
- self.mrp = "X"
- self.timer += 5
- elif moveinput in ("d", "down"):
- if self.base == "X":
- self.base = "O"
- self.bp = "X"
- self.timer += 5
- elif self.mrp == "X":
- self.mrp = "O"
- self.brp = "X"
- self.timer += 5
- elif self.mlp == "X":
- self.mlp = "O"
- self.blp = "X"
- self.timer += 5
- elif self.trp == "X":
- self.trp = "O"
- self.mrp = "X"
- self.timer += 5
- elif self.tlp == "X":
- self.tlp = "O"
- self.mlp = "X"
- self.timer += 5
- elif self.tp == "X":
- self.tp = "O"
- self.base = "X"
- self.timer += 5
- elif self.blp == "X":
- print "Can't move into the ocean."
- elif self.bp == "X":
- print "Can't move into the ocean."
- elif self.brp == "X":
- print "Can't move into the ocean."
- def play_game(self):
- print "ISLAND SURVIVAL (IN DEV)"
- 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."""
- print self.line_break
- print desc
- dead = False
- while not dead:
- self.update_time()
- self.update_position()
- print "Day {}".format(self.current_day)
- print "Time: {}".format(self.current_time)
- print "You are {}".format(self.current_location)
- print "Energy: {}".format(self.energy)
- gameinput = raw_input("Action: ").lower()
- if gameinput in ("craft","c"):
- self.craft()
- elif gameinput in ("craftbook", "craft book", "book", "cb"):
- self.craft_book()
- elif gameinput in ("move", "m"):
- self.move()
- elif gameinput == "map":
- self.GameMap()
- elif gameinput in ("discard","d","trash","t"):
- self.discard_item()
- elif gameinput in ("inventory","i","check inventory","ci"):
- print "Inventory"
- print self.line_break
- linenumber = 1
- for item in self.player_inventory:
- print "({}) {}".format(linenumber,item)
- linenumber += 1
- elif gameinput == "sleep":
- self.skip_day()
- elif gameinput == "quit":
- dead = True
- elif gameinput in ("scavenge","s"):
- self.scavenge()
- elif gameinput == "check":
- print self.timer
- else:
- print "Type (c)raft, (m)ove, map, craft book, (s)cavenge, (i)nventory, sleep"
- game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement