repl.it
@MatthewWellingt/

Adventure 2

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import random

characterName =""
characterHealth = 100
gameOver = False

def getCharacterName():
  global characterName
  print("Hello player!\nWelcome")
  characterName = input("Please enter your Character name:")

def greetCharacter():
  global characterName
  global characterHealth
  print(characterName, "you currently have ",characterHealth , " health points.\n")  

def SceneOne():
   global characterHealth
   print("Scene 1")
   Successful = False
   while (not Successful) and (characterHealth>0) :
     print("You enter the courtyard and look around. ")
     print("You are surrounded by a high wall and there is a door at the end of the yard. ")
     print("A man guards the door. ")
     print("You must answer a question correctly to beat the man.")
     playerAnswer = input("What is the capital of France?")
     if playerAnswer == "Paris":
      print("The man is beaten and runs away")
      Successful = True
     else:
      print("You try to fight the man but he is too strong.")
      print("The answer is Paris")
      characterHealth = characterHealth - 20
 


def SceneTwo():
   global characterHealth
   print("Scene 2")
   question = ["Plymouth","Reading", "Norwich"]
   answer   = ["Devon", "Berkshire", "Norfolk"]
   Successful = False
   while (not Successful) and (characterHealth>0) :
     print("You go through a door which leads you into a hallway in a run down old house. ")
     print("The stairs seem unsafe to climb but there is a lift to get to the first floor. ")
     option = input("Press ‘S’ to take your chances on the stairs or ‘L’ to use the lift.")
     if option == "L":
       print("You get into the lift, but half way up it malfunctions. ")
       print("You must answer a question correctly to prevent the lift from dropping with you in it.")
       rD = random.randint(0, 2)
       playerAnswer = input("In which county is " + question[rD]+"?")
       if playerAnswer == answer[rD]:
         print("Correct answer")
         print("The lift door opens and you step out onto the first floor.")
         Successful = True
       else:
         print("The lift falls back down to the ground floor and you lose 30 health points.")
         characterHealth = characterHealth - 30
         print("The answer to stop the lift from crashing was ", answer[rD])
         gameOver = True
     elif option == "S":
        if random.randint(0,1) == 1:
         characterHealth = characterHealth - 10
         print("The you fall through a hole in a rotten stair and lose 10 health points")
        else:
         print("Somehow you manage to scramble to the top of the stairs without falling through the rotten stairs.")
         Successful = True
   if Successful:
     print("You go through the door on to the next challenge")
   else:
     print("You fail to complete this task")
         
def checkResult():
  global characterHealth
  if characterHealth<0:
    print("Lose : Sorry - You did not complete the adventure")
  else:
    print("Win : Well done!")

# main program
getCharacterName();
greetCharacter()
SceneOne()
greetCharacter()
SceneTwo()
checkResult()
?