@DuncanVaughan5/

Project 2: Zork-1

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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#setup
floor0 = ['nothing', 'sword', 'monster', 'stairs up', 'sword']
floor1 = ['magic stones', 'stairs up', 'monster', 'stairs down', 'nothing']
floor2 = ['sword', 'stairs down', 'nothing', 'boss monster', 'prize']
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 
maplayout = ""
bar = "---------------------------------------------------------------------------------------"



# intro
print("This game takes place in a 3 floor dungeon with 5 rooms in each floor.\n\nYou want to collect items and fight monsters, while your ultimate goal is to find the prize and defeat the boss monster.\n\nYou will constantly be asked to input commands.\n\nTo move, you will type 'left' or 'right' to change rooms, or 'up' or 'down' to change floors.\n\nType 'grab' to pick up items, if there are any.\n\nIf you come across a monster, type 'fight.'\n\nTo retreat from a monster, type 'retreat.'\n\nIf you need assistance with controls, type 'help.'\n\nTo see a map of where you are, type 'map.'\n\nTo see the items you have, type 'inventory.'\n\nIf you give up, type 'quit.'\n\nRemember to use all lowercase letters.\n\nThe adventure starts now.\n\nGood luck.")


#game loop
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()
  command = input("Type in a command")
  
  #left command
  if command == "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
    else:
      if user_room - 1 >= 0:
        user_room = user_room - 1
      else:
        print("There is no room to the left.")
        
      
  #right command    
  elif command == "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
    else:
      if user_room < 4:
        user_room = user_room + 1
      else:
        print("There is no room to the right.")
      
  
  
  #retreat command
  elif command == "retreat":
    if can_retreat == True:
      if user_floor == 0 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.")
      
  #up command
  elif command == "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, can't go up.")
  
  #down command
  elif command == "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, can't go down.")
  
  
  #grab command
  elif command == "grab":
    if len(items) <= 3:
      if dungeon[user_floor][user_room] == "sword":
        items.append("sword")
        print("You got a sword!")
        dungeon[user_floor][user_room] = "nothing"
      elif dungeon[user_floor][user_room] == "magic stones":
        items.append("magic stones")
        print("You got magic stones!")
        dungeon[user_floor][user_room] = "nothing"
      elif dungeon[user_floor][user_room] == "prize":
        items.append("prize")
        print("You got the prize!")
        dungeon[user_floor][user_room] = "nothing"
        game_over = True
        win = True
      else:
        print("No items in this room")
    else:
      print("You have already maxed out on items.")
  
  
  
  #fight command
  elif command == "fight":
    if dungeon[user_floor][user_room] == "monster":
      if "sword" in items:
        print("You defeated the monster but you lost your sword")
        items.remove("sword")
        dungeon[user_floor][user_room] = "nothing"
      else: 
        print("You can't fight the monster without a sword.")
    elif dungeon[user_floor][user_room] == "boss monster":
      if "sword" in items and "magic stones" in items:
        print("Congrats on defeating the boss monster! The prize is yours for the taking!")
        dungeon[user_floor][user_room] = "nothing"
        items.remove("sword")
        items.remove("magic stones")
      else:
        print("You need a sword and magic stones to fight the boss monster")
    else:
      print("Nothing to fight.")
  
  
  
  #help command
  elif command == "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 a map of where you are, type 'map.' To see the items you have, type 'inventory.' Remember to use all lowercase letters.")
  
  
  #map command that looks nicer but only works for one case of lists
  # elif command == "map":
    # print("+------------+-----------+-------+------------+-------+")
    # print("|sword       |stairs down|nothing|boss monster|prize  |")
    # print("+------------+-----------+-------+------------+-------+")
    # print("|magic stones|stairs up  |monster|stairs down |nothing|")
    # print("+------------+-----------+-------+------------+-------+")
    # print("|nothing     |sword      |monster|stairs up   |sword  |")
    # print("+------------+-----------+-------+------------+-------+")
  
  
  
  #map command that looks ugly but works for all cases of lists  
  elif command == "map":
    while list_floor < len(dungeon):
      while list_room < len(floor0):
        maplayout = maplayout + str(dungeon[(len(dungeon)-1) - list_floor][list_room]) + "(" + str((len(dungeon)-1) - list_floor) + "," + str(list_room) + ")" + " | "
        list_room = list_room + 1
      list_floor = list_floor + 1
      list_room = 0
      if list_floor < 3:
        maplayout = maplayout + bar + "\n| "
    print(bar + "\n" + "| " + maplayout + "\n" + bar)
    print("Your coordinates are (" + str(user_floor) + "," + str(user_room)+ ")")  
  
  
  
  
  
  #inventory command
  elif command == "inventory":
    print(items)
  
  
  #quit command
  elif command == "quit":
    game_over = True
    win = False
  
  #error handling
  else:
    print("Not a valid command. Try again.")

#after while loop
if win == True:
  print("YOU WIN!")
else:
  print("You lose for quitting!")