Answered step by step
Verified Expert Solution
Question
1 Approved Answer
How would I get this text based game to print Congratulations, You have collected all the items and defeated The Overseer! at the end of
How would I get this text based game to print "Congratulations, You have collected all the items and defeated The Overseer!" at the end of the game? Everytime, whether I collect all items or not I always get the output "You are in the Artifact Vault
Battling The Overseer..................................................
GAME OVER!
Thanks for playing!" How would i get the correct winning output? Here is my code.
# Sample function showing the goal of the game and move commands
def showInstructions:
# Print main menu and commands
printCosmic Explorer Adventure"
printCollect items to win the game, or be destroyed by The Overseer."
printMove commands: go South, go North, go East, go West"
printAdd to Inventory: get 'item name'"
print
showInstructions
def showstateinventory rooms, state:
# Display player's inventory and current room's item
printInventory: inventory
printYou see a roomsstate
print
moveinput inputEnter your move:
moveparts moveinput.splitmaxsplit
cmd movepartslower
direction moveparts if lenmoveparts else "return"
return cmd direction
# Corrected room definitions
rooms
'Launch Pad': HoloMap', East: 'Control Room'
'Control Room': Quantum Key', South: 'Engineering Bay'
'Engineering Bay': Nano Drone', East: 'Research Lab'
'Research Lab': AntiGravity Boots', South: 'ZeroGravity Chamber'
'ZeroGravity Chamber': Plasma Blaster', South: 'Teleportation Hub'
'Teleportation Hub': Energy Shield', South: 'Storage Bay'
'Storage Bay': ExoArmor', West: 'Artifact Vault'
'Artifact Vault': The Overseer'
state 'Launch Pad'
inventory
def getnewstatestate direction:
# Function to get the new state based on the direction
newstate state
for i in rooms:
if i state and direction in roomsi:
newstate roomsidirection
break
return newstate
while True:
printYou are in the', state
if state 'Artifact Vault':
printBattling The Overseer', end
for i in range:
for j in range:
pass
print end flushTrue"
print
if leninventory:
printCongratulations You have collected all items and defeated The Overseer!"
else:
printGAME OVER!
printThanks for playing!"
break
cmd direction showstateinventory rooms, state
if cmd 'get':
# Check if the item is in the current room
if direction.lower roomsstatelower:
if roomsstate not in inventory:
inventory.appendroomsstate
printfYou obtained roomsstate
else:
printfroomsstate has already been collected!
else:
printNo such item. Try again!
elif cmd go:
newstate getnewstatestate direction
if newstate state:
printCannot go that way. Choose another direction.
else:
state newstate
elif cmd 'exit':
printThanks for playing!
break
else:
printInvalid command! Please enter a valid command.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started