_s8

survival game PT1

_s8
Oct 17th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.11 KB | None | 0 0
  1. # Survival game
  2. import random
  3. # Add more recipes if needed
  4. Recipes = {'club':['wood', 'stick'], 'clothes':['leather', 'leather', 'leather']}
  5.  
  6. health = 100
  7. days = 0
  8. inventory = {}
  9. while health > 0:
  10.     update = {}
  11.     # to remove items that have less stock or equal stock to 0
  12.     for item in inventory:
  13.         if inventory[item] <= 0:
  14.             for item_ in inventory:
  15.                 if item_ != item:
  16.                     update[item_] = inventory[item_]
  17.                 else:
  18.                     pass
  19.     # print the days and show their inventory
  20.     print("Day {}".format(days))
  21.     for item in inventory:
  22.         print(item,"x"+str(inventory[item]))
  23.     # Print the available actions
  24.     action = input('(craft): ')
  25.     if 'craft' in action:
  26.         # The item equals the craft statement without the craft or the space
  27.         item = action.replace('craft ', '')
  28.         if item not in Recipes:
  29.             print("{} is not a real item!".format(item))
  30.         else:
  31.             # Initialization of materials and the materials the user tried to use
  32.             materials = 0
  33.             user_materials = []
  34.             # Keep looping and asking for materials until the user says end
  35.             while materials != 'end':
  36.                 materials = input("What will you use to craft {}?".format(item))
  37.                 # If the user says end, don't add it to the crafting list
  38.                 if materials == 'end':
  39.                     pass
  40.                 # If the user doesn't have the material it's using, then tell them so.
  41.                 else:
  42.                     if materials not in inventory or inventory[materials] <= 0:
  43.                         print(inventory.keys())
  44.                         print("You don't have {}!".format(materials))
  45.                     else:
  46.                         # If it does, then subtract said material from its inventory.
  47.                         inventory[materials] -= 1
  48.                         user_materials.append(materials)
  49.             # If the list of materials the user requested equals the list of materials needed to craft the item, then print a statement saying so.
  50.             if user_materials == Recipes[item]:
  51.                 print("You crafted {}!".format(item))
  52.                 print("{} was added to your inventory, and {} was removed from your inventory.".format(item, user_materials))
  53.                 if item not in inventory:
  54.                     inventory[item] = 1
  55.                 else:
  56.                     inventory[item] += 1
  57.             else:
  58.                 # If the materials aren't correct, tell them so and return the materials to their inventory.
  59.                 print("You weren't able to craft {}!".format(item))
  60.                 days += 1
  61.                 for item in user_materials:
  62.                     inventory[item] = user_materials.count(item)
  63.     # For the dev to cheat items in:
  64.     if 'get item' in action:
  65.         cheated = action.replace('get item ', '')
  66.         if cheated in inventory:
  67.             inventory[cheated] += 1
  68.         else:
  69.             inventory[cheated] = 1
  70.         print("{} was cheated into the game.".format(cheated))
Advertisement
Add Comment
Please, Sign In to add comment