7-3 Project Two
docx
keyboard_arrow_up
School
Southern New Hampshire University *
*We aren’t endorsed by this school
Course
-140-X2476
Subject
Industrial Engineering
Date
Jan 9, 2024
Type
docx
Pages
2
Uploaded by langillem
# Michael Langille
# Function to display instructions
def
game_instructions
():
# Display introductory instructions
print
(
"You've just acquired the ancient artifact you were after!!!"
)
print
(
"Collect all 6 items to access the plane and take out the guard to
make your getaway!"
)
print
(
"If you come across security before collecting all 6 items, you will
be captured and fail your mission."
)
print
(
'Move Commands: North, South, East, and West.'
)
print
(
"Add to inventory: Get 'item name'"
)
print
(
"QUIT GAME: EXIT"
)
print
(
"---------
\n
"
)
# Call the instruction function to display the initial information
game_instructions()
# Define rooms and items in a dictionary
rooms = {
'Office'
: {
'East'
:
'Security'
,
'South'
:
'Hanger Bay'
}
,
'Security'
: {
'West'
:
'Office'
,
'item'
:
'Map'
}
,
'Hanger Bay'
: {
'North'
:
'Office'
,
'East'
:
'Storage'
,
'West'
:
'Utilities'
,
'South'
:
'Loft'
,
'item'
:
'Ear Plugs'
}
,
'Utilities'
: {
'East'
:
'Hanger Bay'
,
'item'
:
'Fuel'
}
,
'Bathroom'
: {
'South'
:
'Storage'
,
'item'
:
'Guard'
}
,
'Storage'
: {
'North'
:
'Bathroom'
,
'West'
:
'Hanger Bay'
,
'item'
:
'Club'
}
,
'Loft'
: {
'North'
:
'Hanger Bay'
,
'East'
:
'Locker Room'
,
'item'
:
'Parachute'
}
,
'Locker Room'
: {
'West'
:
'Loft'
,
'item'
:
'Ignition Key'
}
,
}
# Set the initial player position and create an empty inventory
current_room =
'Office'
inventory = []
# Function to get the new room based on the current room and player direction
def
get_new_room
(current_room
,
direction):
new_room = current_room
for
i
in
rooms:
if
i == current_room:
if
direction
in
rooms[i]:
new_room = rooms[i][direction]
return
new_room
# Function to get the item in the current room
def
get_item
(current_room):
if
'item'
in
rooms[current_room]:
return
rooms[current_room][
'item'
]
if
'item'
not in
rooms[current_room]:
return
'This room has no item!'
# Main game loop
while
current_room:
# Display current room and inventory
print
(
'You are in the'
,
current_room)
print
(
'Inventory:'
,
inventory)
# Get the item in the current room
item = get_item(current_room)
if
item !=
'Guard'
:
if
current_room ==
'Office'
:
print
(
"There's no item in this room!"
)
if
current_room !=
'Office'
:
if
item
in
inventory:
print
(
'Item already collected!'
)
else
:
print
(
'You found'
,
item
,
'pick it up.'
)
pickup =
input
()
pickup = pickup.title()
if
pickup ==
str
(
'Get '
+ item):
inventory.append(item)
print
(
"You picked up "
+ item +
"!"
)
if
pickup ==
'EXIT'
:
print
(
'Goodbye.'
)
break
if
item ==
'Guard'
:
if
len
(inventory) ==
6
:
print
(
'Success! You have collected all the items and used the club
to take out the guard!'
)
break
if
len
(inventory) !=
6
:
print
(
'You do not have all the items to take out the guard and
make your escape. You failed your mission!'
)
break
# Get player input for the next direction
direction =
input
(
'Enter direction in which you would like to move >>> '
)
direction = direction.capitalize()
if
direction ==
'EXIT'
:
print
(
'Goodbye.'
)
break
if
direction ==
'North'
or
direction ==
'South'
or
direction ==
'East'
or
direction ==
'West'
:
# Get the new room based on the direction
new_room = get_new_room(current_room
,
direction)
if
new_room == current_room:
print
(
'You can
\'
t go that way!'
)
else
:
current_room = new_room
else
:
print
(
'You can
\'
t go that way!'
)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help