We'll now put in the call to our code. Remember that the body of our fighting code still looks like this:
decision = input("You come to a junction. Turn left or right [L,R]: ")
if decision == "L" or decision == "l":
print("You turn left and see a terrible ogre!")
ogre_strength = 2
while player_strength > 0 and ogre_strength > 0:
print("You FIGHT!")
print("SMASH!")
time.sleep(500)
print("BASH!")
time.sleep(500)
print("Oo!")
time.sleep(500)
random_number = random.randint(10)
if player_strength > random_number:
print("You won! Gain one strength!")
player_strength = player_strength + 1
ogre_strength = ogre_strength - 1
else:
print("You lost! Lose one strength!")
player_strength = player_strength - 1
ogre_strength = ogre_strength + 1
if player_strength < 1:
print("Oh no! You died!")
sys.exit()
Change it to this:
decision = input("You come to a junction. Turn left or right [L,R]: ")
if decision == "L" or decision == "l":
print("You turn left and see a terrible ogre!")
ogre_strength = 2
fight()
You should now be able to run the code.
Where the code says "fight" (the call to the function) the computer will jump to our function, run it, and return to where the call is made.
[Home > Part 3 > Next]