Question: I need help inserting the def main ( ) : function into my text based game code. If i delete def main ( )

I need help inserting the "def main():" function into my text based game code. If i delete def main():, my code runs fine, but I need it for points. I've attached the errors in the screenshots.
Here is my code.
import os
def show_instructions():
print("Welcome to my game")
print('You must collect all five items before fighting the boss to escape the island.')
print('Move Commands: go {direction} travel north, south, east, or west')
print('get {item} to add nearby item to inventory')
input("Press any key to continue...")
# Clear screen
def clear():
os.system('cls' if os.name =='nt' else 'clear')
def main():
rooms ={
'Shore': {'East': 'Grass Area'},
'Grass Area': {'South': 'Passenger2', 'East': 'Path To Bunker', 'North': 'Passenger1', 'Item': 'Pineapple'},
'Passenger1': {'East': 'Wreckage', 'Item': 'Pistol', 'South': 'Grass Area'},
'Passenger2': {'North': 'Grass Area', 'East': 'The Strong Tree', 'Item': 'Shield'},
'The Strong Tree': {'West': 'Passenger2', 'Item': 'Flare Gun'},
'Path To Bunker': {'West': 'Grass Area', 'North': 'Bunker'},
'Bunker': {'Boss': 'Villain', 'South': 'Path To Bunker'},
'Wreckage': {'West': 'Passenger1', 'Item': 'Dynamite'}
}
# List to track inventory
inventory =[]
# Tracks current room
current_room = "Shore"
# Tracks last move
msg =""
clear()
show_instructions()
# Gameplay loop
while True:
clear()
# Display player info
print(f"You are in the {current_room}
Inventory : {inventory}
{'-'*27}")
# Display msg
print(msg)
# Item indicator
if "Item" in rooms[current_room].keys():
nearby_item = rooms[current_room]["Item"]
if nearby_item not in inventory:
print(f"You see {nearby_item}")
# Boss encounter
if "Boss" in rooms[current_room].keys():
if len(inventory)5:
print(f"Better luck next time. You lost a fight with {rooms[current_room]['Boss']}.")
break
else:
print(f"You beat {rooms[current_room]['Boss']}, and escaped the island!")
break
# Accepts player's move as input
user_input = input("Enter your move:
")
# Splits move into words
next_move = user_input.split('')
# First word is action
action = next_move[0].title()
# Reset item and direction
item = "Item"
direction = "null"
# Second word is object or direction
if len(next_move)>1:
item = next_move[1:]
direction = next_move[1].title()
item ="".join(item).title()
# Moving between rooms
if action =="Go":
try:
current_room = rooms[current_room][direction]
msg = f"You travel {direction}"
except:
msg = "You can't go that way."
# Picking up items
elif action == "Get":
try:
if item == rooms[current_room]["Item"]:
if item not in inventory:
inventory.append(rooms[current_room]["Item"])
msg = f"{item} retrieved!"
else:
msg = f"You already have the {item}"
else:
msg = f"Can't find {item}"
except:
msg = f"Can't find {item}"
# Exit program
elif action == "Exit":
break
# Any other commands invalid
else:
msg = "Invalid command"
if__name__=='__main__'
Run
text game xx
"E:\PYCHARM\ChrisR - pycharm intro assignment.venv \Scripts\python.exe" "E:\PYCHARM\ChrisR - pycharm intro assignment \text game.py"
File "E:\PYCHARM\ChrisR - pycharm intro assignment \text game.py", line 17
rooms ={
IndentationError: expected an indented block after function definition on line 15
Process finished with exit code 1
I need help inserting the "def main ( ) : "

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!