Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ufirat117
- #1/10/18
- import random
- enemy= {"health":10000, "attack":200, "name":"Guldan"}
- hero= {"health":1000, "attack":500, "name":"Durotan", "money":1000}
- fightingMove= { "attack":"a",
- "back": "b"}
- decisionMove= { "fight": "f",
- "inventory": "i",
- "shop": "s",
- "quit": "q"}
- shop= { "axe":{"price": 400, "attack": 1000},
- "potion":{"price": 200, "health": 1000}}
- inventory= {}
- def buyItem():
- axeCounter=0
- potionCounter=0
- while True:
- itemChoice= input(",".join(shop.keys()) + ",back ")
- if itemChoice in shop:
- if hero["money"] >= shop[itemChoice]["price"]:
- if itemChoice == "axe":
- axeCounter+=1
- inventory[itemChoice]= axeCounter
- hero["money"]-= shop[itemChoice]["price"]
- print("item: {} quantity: {} money left: {}"\
- .format("Axe",inventory["axe"],hero["money"]))
- print()
- else:
- potionCounter+=1
- inventory[itemChoice]= potionCounter
- hero["money"]-= shop[itemChoice]["price"]
- print("item: {} quantity: {} money left: {}"\
- .format("Potion",inventory["potion"],hero["money"]))
- print()
- else:
- print("you dont have enough money!")
- else:
- break
- return inventory
- def fightAlongside():
- dmkey= decisionMove.keys()
- while True:
- decision= input(",".join(dmkey)+ " ")
- if decision == "shop":
- buyItem()
- elif decision == "inventory":
- while True:
- for item in inventory:
- print("item: {} quantity: {}".format(item,inventory[item]))
- print()
- ikey= inventory.keys()
- use= input(",".join(ikey)+",back ")
- if use in inventory:
- if use == "axe":
- while inventory["axe"] > 0:
- hero["attack"]+= shop["axe"]["attack"]
- inventory["axe"]-= 1
- break
- else:
- while inventory["potion"] > 0:
- hero["health"]+= shop["potion"]["health"]
- inventory["potion"]-= 1
- break
- print("attack: {} health: {}"\
- .format(hero["attack"],hero["health"]))
- print()
- elif use == "back":
- break
- else:
- continue
- elif decision == "fight":
- while hero["health"] > 0 and enemy["health"] > 0:
- move= input(",".join(fightingMove)+" ")
- if move == "attack":
- hero["health"]-= random.randint(enemy["attack"]/2,enemy["attack"])
- enemy["health"]-= random.randint(hero["attack"]/2,hero["attack"])
- print("hero`s name: {} health: {} attack: {}"\
- .format(hero["name"],hero["health"],hero["attack"]))
- print("enemy`s name: {} health: {} attack: {}"\
- .format(enemy["name"],enemy["health"],enemy["attack"]))
- else:
- break
- if enemy["health"] <= 0:
- print("Winner is {}".format(hero["name"]))
- if hero["health"] <= 0:
- print("Winner is {}".format(enemy["name"]))
- else:
- break
- fightAlongside()
Add Comment
Please, Sign In to add comment