Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Survival game
- import random
- # Add more recipes if needed
- Recipes = {'club':['wood', 'stick'], 'clothes':['leather', 'leather', 'leather']}
- health = 100
- days = 0
- inventory = {}
- while health > 0:
- update = {}
- # to remove items that have less stock or equal stock to 0
- for item in inventory:
- if inventory[item] <= 0:
- for item_ in inventory:
- if item_ != item:
- update[item_] = inventory[item_]
- else:
- pass
- # print the days and show their inventory
- print("Day {}".format(days))
- for item in inventory:
- print(item,"x"+str(inventory[item]))
- # Print the available actions
- action = input('(craft): ')
- if 'craft' in action:
- # The item equals the craft statement without the craft or the space
- item = action.replace('craft ', '')
- if item not in Recipes:
- print("{} is not a real item!".format(item))
- else:
- # Initialization of materials and the materials the user tried to use
- materials = 0
- user_materials = []
- # Keep looping and asking for materials until the user says end
- while materials != 'end':
- materials = input("What will you use to craft {}?".format(item))
- # If the user says end, don't add it to the crafting list
- if materials == 'end':
- pass
- # If the user doesn't have the material it's using, then tell them so.
- else:
- if materials not in inventory or inventory[materials] <= 0:
- print(inventory.keys())
- print("You don't have {}!".format(materials))
- else:
- # If it does, then subtract said material from its inventory.
- inventory[materials] -= 1
- user_materials.append(materials)
- # If the list of materials the user requested equals the list of materials needed to craft the item, then print a statement saying so.
- if user_materials == Recipes[item]:
- print("You crafted {}!".format(item))
- print("{} was added to your inventory, and {} was removed from your inventory.".format(item, user_materials))
- if item not in inventory:
- inventory[item] = 1
- else:
- inventory[item] += 1
- else:
- # If the materials aren't correct, tell them so and return the materials to their inventory.
- print("You weren't able to craft {}!".format(item))
- days += 1
- for item in user_materials:
- inventory[item] = user_materials.count(item)
- # For the dev to cheat items in:
- if 'get item' in action:
- cheated = action.replace('get item ', '')
- if cheated in inventory:
- inventory[cheated] += 1
- else:
- inventory[cheated] = 1
- print("{} was cheated into the game.".format(cheated))
Advertisement
Add Comment
Please, Sign In to add comment