@DuncanVaughan5/

Project 2: Zork

Python

Zork-Texted base adventure game

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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
floor0 = ['blocked stairs', 'rusty sword', 'stairs up', 'broken pipe', 'nothing', 'good sword']
floor1 = ['health potion', 'monster', 'stairs down',  'nothing', 'stairs up', 'rusty sword',]
floor2 = ['door out', 'boss monster', 'nothing', 'monster', 'stairs down', 'body armor']
dungeon = [floor0, floor1, floor2]
items = []
user_room = 0
user_floor = 0
game_over = False
win = False
can_retreat = False
list_room = 0
list_floor = 0
"---------------------------------------------------------"
print("Here are the rules. You can move left or right by inputting left or right. If you cannot move left or right anymore, you will be told so.")
print("Also, ever time you move left or right you will move rooms. Some rooms contain nothing, some contain useful items, some contain monsters, and some are just staircase rooms.")
print("Items you pickup have different uses, from weapons, keys, and protective gear. There are two weapons in the game, a rusty broken pipe and sword. There is also one health potion, which is needed to beat the boss. You can only hold three items at a time,so think about what you really need to win.")
print("Finally, the monsters you fight will have different health levels. Sleeping ones can be killed by a sneak attack, resulting in critical damage. If you don't attack a monster, you can run from it, but you need to kill the monster before you can pass.")
print("The commands are as follows. left to move left, light to move right, up to go up stairs, down to go down stairs, grab to pick up items, fight to attack the monsters, run to run from the monsters, and help to view this list of commands again.")
start = input("Ready to start?(Yes or No)")

if start == 'No':
  print("Okay, please play again.")
    
if start == 'Yes':

  while game_over == False:
    print()
    print("You're on floor " + str(user_floor) + " in room " + str(user_room))
    print()
    print("There is / is a/ are " + dungeon[user_floor][user_room] + " in this room.")
    print()
    action = input("Type in a command.  ")

    #left movement
    if action == 'left':
    
      if dungeon[user_floor][user_room] == "monster" or dungeon[user_floor][user_room] == "boss monster":
        print("Use the commands 'fight' or 'retreat.")
        can_retreat = True

      if user_room - 1 >= 0:
        user_room = user_room - 1
      else:
        print("You cannot go left anymore.")

    #right movement
    if action == 'right':
    
      if dungeon[user_floor][user_room] == "monster" or dungeon[user_floor][user_room] == "boss monster":
        print("Use the commands 'fight' or 'retreat.")
      can_retreat = True
  
      if user_room < 5:
        user_room = user_room + 1
      else:
        print("You cannot go right anymore.")
    
    #up action
    elif action == "up":
      if dungeon[user_floor][user_room] == "stairs up":
        user_floor = user_floor + 1
        print("You found stairs that go up.")
      else:
        print("No stairs, you can't go up.")

    #down action
    elif action == "down":
      if dungeon[user_floor][user_room] == "stairs down":
        user_floor = user_floor - 1
        print("You found stairs that go down.")
      else:
        print("No stairs, you can't go down.")
   
    #fight action
    if action == 'fight':
      if dungeon[user_floor][user_room] == "monster":
        if "good sword" in items:
          print("You defeated the monster.")
          dungeon[user_floor][user_room] = "nothing"
       
        elif "rusty sword" in items:
          print("You defeated the monster but you lost your rusty sword.")
          items.remove("rusty sword")
          dungeon[user_floor][user_room] = "nothing"
        else: 
          print("You can't fight the monster without a sword.")

        if "broken pipe" in items:
          print("The pipe didn't work on the monster, and now you've alerted them all. You lose.")
          game_over = True

      if dungeon[user_floor][user_room] == "boss monster":
        if "good sword" in items and "body armor" in items and "health potion":
          print("Congrats on defeating the boss monster! Time to escape!")
          dungeon[user_floor][user_room] = "nothing"
          items.remove("good sword")
          items.remove("body armor")
          items.remove("health potion")
        else:
          print("You need a good sword, body armor, and a health potion to fight the boss monster.")
      else:
        print("Nothing to fight.")
    
    #grab action
    if action == "grab":
      if len(items) <= 3:
        if dungeon[user_floor][user_room] == "rusty sword":
          items.append("rusty sword")
          print("You got a rusty sword! It looks like it is going to break soon.")
          dungeon[user_floor][user_room] = "nothing"
        elif dungeon[user_floor][user_room] == "good sword":
          items.append("good sword")
          print("You got a good sword! It can beat all monsters.")
          dungeon[user_floor][user_room] = "nothing"
        elif dungeon[user_floor][user_room] == "broken pipe":
          items.append("broken pipe")
          print("You got a broken pipe. It probably can't kill the monsters.")
          dungeon[user_floor][user_room] = "nothing"
        elif dungeon[user_floor][user_room] == "health potion":
          items.append("health potion")
          print("You got a health potion, it can save you from death.")
          dungeon[user_floor][user_room] = "nothing"
        elif dungeon[user_floor][user_room] == "body armor":
          items.append("body armor")
          print("You got and put on body armor!")
          dungeon[user_floor][user_room] = "nothing"
        elif dungeon[user_floor][user_room] == "door out":
          items.append("door out")
          print("You escaped the dungeon! YOU WIN!")
          dungeon[user_floor][user_room] = "nothing"
          game_over = True
          
        else:
          print("No items in this room")
      else:
        print("You have already maxed out on items.")

    #help command
    elif action == "help":
      print("Type 'left' or 'right' to change rooms, or 'up' or 'down' to change floors. Type 'grab' to pick up items, if there are any. If you come across a monster, type 'fight.' To see the items you have, type 'inventory.' Remember to use all lowercase letters.")

    #inventory command
    elif action == "inventory":
      print(items)
    
    #retreat command
    elif action == "retreat":
      if can_retreat == True:
        if user_floor == 0 or user_floor == 1 or user_floor == 2:
          user_room = user_room - 1
          can_retreat = False
        else:
          user_room = user_room + 1
          can_retreat = False
      else:
        print("Nothing to retreat from.")