Advertisement
ukesh

challange game

Feb 23rd, 2015
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. # 'Crafting Challenge' Game
  2. # More programs at UsingPython.com/programs
  3. #------------------------------------------------
  4. #------------------------------------------------
  5. # Challenge 1: Can you craft a tent and a firepit?
  6. # Challenge 2: Can you add more items?
  7. # Challenge 3: Can you create crafting rules
  8. # to make more items?
  9. # Challenge 4: Add comments to the code below!
  10. #------------------------------------------------
  11. commands = {
  12. "i" : "see inventory",
  13. "c" : "see crafting options",
  14. "craft [item]" : "craft something from inventory items",
  15. }
  16. #an inventory of items
  17. items = {
  18. "flint" : 50,
  19. "grass" : 100,
  20. "hay" : 0,
  21. "tree" : 100,
  22. "log" : 0,
  23. "sapling" : 100,
  24. "twig" : 0,
  25. "boulder" : 30,
  26. "rock" : 0,
  27. "pickaxe" : 0,
  28. "axe" : 0,
  29. "firepit" : 0,
  30. "tent" : 0,
  31. "torch" : 0,
  32. }
  33. #rules to make new objects
  34. craft = {
  35. "hay" : { "grass" : 1 },
  36. "twig" : { "sapling" : 1 },
  37. "log" : { "axe" : 1, "tree" : 1 },
  38. "axe" : { "twig" : 3, "flint" : 1 },
  39. "tent" : { "twig" : 10, "hay" : 15 },
  40. "firepit" : { "boulder" : 5, "log" : 3, "twig" : 1, "torch" : 1 },
  41. "torch" : { "flint" : 1, "grass" : 1, "twig" : 1 },
  42. "pickaxe" : { "flint" : 2, "twig" : 1 }
  43. }
  44. print("'Crafting Challenge' Game")
  45. print("More programs at UsingPython.com/programs")
  46. print("-----------------------------------------\n")
  47. print("TRY TO SURVIVE BY CRAFTING A TENT AND A FIREPIT!")
  48. print("type '?' for help")
  49. while True:
  50. command = input(">").split()
  51. if len(command) == 0:
  52. continue
  53. if len(command) > 0:
  54. verb = command[0].lower()
  55. if len(command) > 1:
  56. item = command[1].lower()
  57. if verb == "?":
  58. for key in commands:
  59. print(key + " : " + commands[key])
  60. print("\n")
  61. elif verb == "i":
  62. for key in items:
  63. print(key + " : " + str(items[key]))
  64. print("\n")
  65. elif verb == "c":
  66. for key in craft:
  67. print(key + " can be made with:")
  68. for i in craft[key]:
  69. print(str(craft[key][i]) + " " + i)
  70. print("\n")
  71. elif verb == "craft":
  72. print("making " + item + ":")
  73. if item in craft:
  74. for i in craft[item]:
  75. print(" you need : " + str(craft[item][i]) + " " + i + " and you have " + str(items[i]))
  76. canBeMade = True
  77. for i in craft[item]:
  78. if craft[item][i] > items[i]:
  79. print("item cannot be crafted\n")
  80. canBeMade = False
  81. break
  82. if canBeMade == True:
  83. for i in craft[item]:
  84. items[i] -= craft[item][i]
  85. items[item] += 1
  86. print("item crafted\n")
  87. if items["tent"] >= 1 and items["firepit"] >= 1:
  88. print("\n**YOU HAVE MANAGED TO SURVIVE!\nWELL DONE!")
  89. break
  90. else:
  91. print("you can't")
  92. else:
  93. print("you can't" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement