Guest User

Untitled

a guest
Jan 19th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. #ufirat117
  2. #1/10/18
  3.  
  4. import random
  5.  
  6. enemy= {"health":10000, "attack":200, "name":"Guldan"}
  7. hero= {"health":1000, "attack":500, "name":"Durotan", "money":1000}
  8.  
  9. fightingMove= { "attack":"a",
  10. "back": "b"}
  11.  
  12. decisionMove= { "fight": "f",
  13. "inventory": "i",
  14. "shop": "s",
  15. "quit": "q"}
  16.  
  17. shop= { "axe":{"price": 400, "attack": 1000},
  18. "potion":{"price": 200, "health": 1000}}
  19.  
  20. inventory= {}
  21.  
  22.  
  23. def buyItem():
  24. axeCounter=0
  25. potionCounter=0
  26. while True:
  27.  
  28. itemChoice= input(",".join(shop.keys()) + ",back ")
  29. if itemChoice in shop:
  30. if hero["money"] >= shop[itemChoice]["price"]:
  31. if itemChoice == "axe":
  32. axeCounter+=1
  33. inventory[itemChoice]= axeCounter
  34. hero["money"]-= shop[itemChoice]["price"]
  35. print("item: {} quantity: {} money left: {}"\
  36. .format("Axe",inventory["axe"],hero["money"]))
  37. print()
  38.  
  39. else:
  40. potionCounter+=1
  41. inventory[itemChoice]= potionCounter
  42. hero["money"]-= shop[itemChoice]["price"]
  43. print("item: {} quantity: {} money left: {}"\
  44. .format("Potion",inventory["potion"],hero["money"]))
  45. print()
  46.  
  47. else:
  48. print("you dont have enough money!")
  49. else:
  50. break
  51.  
  52. return inventory
  53.  
  54. def fightAlongside():
  55.  
  56. dmkey= decisionMove.keys()
  57. while True:
  58. decision= input(",".join(dmkey)+ " ")
  59.  
  60. if decision == "shop":
  61. buyItem()
  62.  
  63. elif decision == "inventory":
  64. while True:
  65. for item in inventory:
  66. print("item: {} quantity: {}".format(item,inventory[item]))
  67. print()
  68.  
  69. ikey= inventory.keys()
  70. use= input(",".join(ikey)+",back ")
  71. if use in inventory:
  72. if use == "axe":
  73. while inventory["axe"] > 0:
  74. hero["attack"]+= shop["axe"]["attack"]
  75. inventory["axe"]-= 1
  76. break
  77. else:
  78. while inventory["potion"] > 0:
  79. hero["health"]+= shop["potion"]["health"]
  80. inventory["potion"]-= 1
  81. break
  82.  
  83. print("attack: {} health: {}"\
  84. .format(hero["attack"],hero["health"]))
  85. print()
  86.  
  87. elif use == "back":
  88. break
  89. else:
  90. continue
  91.  
  92. elif decision == "fight":
  93. while hero["health"] > 0 and enemy["health"] > 0:
  94. move= input(",".join(fightingMove)+" ")
  95. if move == "attack":
  96. hero["health"]-= random.randint(enemy["attack"]/2,enemy["attack"])
  97. enemy["health"]-= random.randint(hero["attack"]/2,hero["attack"])
  98. print("hero`s name: {} health: {} attack: {}"\
  99. .format(hero["name"],hero["health"],hero["attack"]))
  100. print("enemy`s name: {} health: {} attack: {}"\
  101. .format(enemy["name"],enemy["health"],enemy["attack"]))
  102. else:
  103. break
  104. if enemy["health"] <= 0:
  105. print("Winner is {}".format(hero["name"]))
  106. if hero["health"] <= 0:
  107. print("Winner is {}".format(enemy["name"]))
  108. else:
  109. break
  110.  
  111. fightAlongside()
Add Comment
Please, Sign In to add comment