Hi, I had another thread earlier on which I asked a few questions but was getting quite off topic.
1st question I have is, if you have a big line of code, can you enclose it all in brackets and use it again later?
I made this fight sequence for a text based rpg I am doing and what I basically want to do is write
fight_seq = (-insert huge chunk of code here...-)
so I can bring it in any time I want it in the game instead of writing the whole thing out?
here is my code:
# cb v5.0
# I just use the turn counter as a way of setting rounds for a fight.
# Not applicable here because it is huge and the fight will never last that long.
#The player presses the enter key to progress through the fight.
#You can press 1 to heal 5 health
turn_counter = 0
health = 25
creep_health = 10
health_potion = 1
while turn_counter < 100:
damage = random.randint(0,3)
creep_damage = random.randint(0,3)
health -= creep_damage
creep_health -= damage
turn_counter += 1
if health <= 0: health = 0
if creep_health <= 0: creep_health = 0
print("You swing your fist to hit [" + str(damage) +"] damage.")
print("The creep swipes to hit (" + str(creep_damage) + ") damage.")
print("Your HP is [" + str(health) + "] and creeps HP is (" + str(creep_health) + ").\n")
if health <= 0 or creep_health <= 0:
answer = input()
if answer == "1":
if health_potion >= 1:
health_potion -= 1
health += 5
print("\n-You drink a health potion. \n-Your HP is now",
str(health) + ". \n-You have", health_potion, "health potions left.\n")
print("\nYou are out of health potions!\n")
print("\n\nend of battle.")
input("Press Enter to exit....")
thanks in advance.