Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am having trouble meeting the win condition of this text based game. It always ends just after getting to the overseer, if i have

I am having trouble meeting the win condition of this text based game. It always ends just after getting to the overseer, if i have all items or not. here is my python code that i have. # Sample function showing the goal of the game and move commands
def show_Instructions():
# Print main menu and commands
print("Cosmic Explorer Adventure")
print("Collect 7 items to win the game, or be destroyed by The Overseer.")
print("Move commands: go South, go North, go East, go West")
print("Add to Inventory: get 'item name'")
print("-----------------------------------")
show_Instructions()
def show_state(inventory, rooms, state):
# Display player's inventory and current room's item
print('Inventory: ', inventory)
print('You see a ', rooms[state][0])
print("--------------------------------")
move_input = input('Enter your move: ')
# Split the input into cmd and direction
move_parts = move_input.split(maxsplit=1)
cmd = move_parts[0].lower()
direction = move_parts[1] if len(move_parts)>1 else ''
return cmd, direction
# A dictionary for the simplified Realm of the Queen Mahal Game
# The dictionary links a room to other rooms.
rooms ={
'Launch Pad': ['Holo-Map', {'East': 'Control Room'}],
'Control Room': ['Quantum Key', {'South': 'Engineering Bay'}],
'Engineering Bay': ['Nano Drone', {'East': 'Research Lab'}],
'Research Lab': ['Anti-Gravity Boots', {'South': 'Zero-Gravity Chamber'}],
'Zero-Gravity Chamber': ['Plasma Blaster', {'South': 'Teleportation Hub'}],
'Teleportation Hub': ['Energy Shield', {'South': 'Storage Bay'}],
'Storage Bay': ['Exo-Armor', {'West': 'Artifact Vault'}],
'Artifact Vault': ['The Overseer']
}
state = 'Launch Pad'
inventory =[]
def get_new_state(state, direction):
# Function to get the new state based on the direction
new_state = state
for i in rooms:
if i == state:
if direction in rooms[i][1]:
new_state = rooms[i][1][direction]
return new_state
while True:
print('You are in the ', state)
if state == 'Artifact Vault':
print('Battling The Overseer', end='')
for i in range(50):
for j in range(1000000):
pass
print(".", end='', flush=True)
print()
if len(inventory)==6:
print("Congratulations! You have collected all items and defeated The Overseer!")
else:
print('GAME OVER!')
print("Thanks for playing!")
break
cmd, direction = show_state(inventory, rooms, state)
if cmd == 'get':
# Check if the item is in the current room
if direction.lower()== rooms[state][0].lower():
if rooms[state][0] not in inventory:
inventory.append(rooms[state][0])
print(f'You obtained {rooms[state][0]}!')
else:
print(f'{rooms[state][0]} has already been collected!')
else:
print('No such item. Try again!')
elif cmd =='go':
new_state = get_new_state(state, direction)
if new_state == state:
print('Cannot go that way. Choose another direction.')
else:
state = new_state
elif cmd == 'exit':
print('Thanks for playing!')
break
else:
print('Invalid command! Please enter a valid command.')

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

Define and explain the goals of employee orientation/onboarding

Answered: 1 week ago