To start with, we think about which bits of code we'd like to use more than once. In our case, we might want so code to deal with the fighting. Here's a cut down version of our current code...
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()
We're going to pull out all the fighting code and put it somewhere separate...
[Home > Part 3 > Next]