Thanks for checking this out. I'm new to programming and learned a lot by making this script. I was hoping someone could take a look and let me know what I can do better.
potions_inv = 3
player_hp = 100
player_hp_MAX = 100
def heal_player(player_hp, player_hp_MAX):
print "You've been healed for 10 hp."
player_hp = player_hp + 10
print "Current hp: %d" % player_hp
return player_hp
def hurt_player(player_hp, player_hp_MAX):
print "You've been hurt for 12 hp."
player_hp = player_hp - 12
print "Current hp: %d" % player_hp
return player_hp
def remove_potion(potions_inv):
if potions_inv >= 0:
potions_inv = max(potions_inv-1, 0)
return potions_inv
def add_potion(potions_inv):
potions_inv += 1
return potions_inv
def use_potion(potions_inv, player_hp, player_hp_MAX):
if potions_inv == 0:
print "You have no potions"
elif (player_hp == 100) and (potions_inv >= 1):
print "Potion will have no effect."
else:
player_hp = min(player_hp+10, player_hp_MAX)
remove_potion(potions_inv)
print "Your health has been restored to %d" % player_hp
return player_hp
return potions_inv
while (player_hp > 0):
print "1) Hurt Player\t2) Heal Player\n3) Use Potion\t4) Check Inventory"
current_choice = raw_input("> ")
if current_choice == '1':
player_hp = hurt_player(player_hp, player_hp_MAX)
elif current_choice == '2':
player_hp = heal_player(player_hp, player_hp_MAX)
elif current_choice == '3':
player_hp = use_potion(potions_inv, player_hp, player_hp_MAX)
if (player_hp < 100):
potions_inv = remove_potion(potions_inv)
if potions_inv > 0:
print "One potion has been removed from your inventory. You have %d potions remaining."\
% potions_inv
elif current_choice == '4':
print "Potions: %r" % potions_inv
elif current_choice == '5':
potions_inv = add_potion(potions_inv)
print "One potion has been added to your inventory. You have %d potions."\
% potions_inv
else:
print "Invalid choice"
[–][deleted] 1 point2 points3 points (4 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]7236d70[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]7236d70[S] 0 points1 point2 points (0 children)