# Neurotoads Python RPG — занятие 33
# Сборка и расширение игры

state={"name":"Лея","hp":6,"coins":3,"location":"лагерь","inventory":["зелье"]}
locations={"лагерь":["лес"],"лес":["лагерь","башня"],"башня":["лес"]}
def move(state,target):
    if target in locations[state["location"]]: state["location"]=target
def use_potion(state):
    if "зелье" in state["inventory"] and state["hp"]<10:
        state["hp"]=min(10,state["hp"]+5); state["inventory"].remove("зелье")
def battle(state):
    enemy_hp=4
    while state["hp"]>0 and enemy_hp>0:
        enemy_hp=max(0,enemy_hp-3)
        if enemy_hp>0: state["hp"]=max(0,state["hp"]-2)
move(state,"лес"); use_potion(state); move(state,"башня"); battle(state)
with open("save.txt","w",encoding="utf-8") as f:
    f.write(state["name"]+"\n"+str(state["hp"])+"\n"+str(state["coins"])+"\n")
print(state)
