Question: The code to start the text adventure game in Python is attached. Your task is to create a more complex game with at least 8

The code to start the text adventure game in Python is attached. Your task is to create a more complex game with at least 8 rooms and 6 items. I recommend drawing out your rooms and how they connect before starting to modify the code. The rooms and items are to be listed in the rooms dictionary. A direction is used to connect to another room and item is used to show what items are available in that room. One room should have a "monster" or some sort of item that ends the game.

There should be 2 possible endings to the game. Either you win by collecting the necessary items and entering the right room or you lose by entering a room where the "monster" is. You will need to write the code to end the game in both ways. If statements should be used for this.

Have fun with it.

#!/bin/python3

def showInstructions(): #print a main menu and the commands print(''' Text Adventure Game ======== Commands: go [direction] get [item] ''')

def showStatus(): #print the player's current status print('---------------------------') print('You are in the ' + currentRoom) #print the current inventory print('Inventory : ' + str(inventory)) #print an item if there is one if "item" in rooms[currentRoom]: print('You see a ' + rooms[currentRoom]['item']) print("---------------------------")

#an inventory, which is initially empty inventory = []

#a dictionary linking a room to other rooms rooms = {

'Hall' : { 'south' : 'Kitchen' },

'Kitchen' : { 'north' : 'Hall' }

}

#start the player in the Hall currentRoom = 'Hall'

showInstructions()

#loop forever while True:

showStatus()

#get the player's next 'move' #.split() breaks it up into an list array #eg typing 'go east' would give the list: #['go','east'] move = '' while move == '': move = input('>') move = move.lower().split()

#if they type 'go' first if move[0] == 'go': #check that they are allowed wherever they want to go if move[1] in rooms[currentRoom]: #set the current room to the new room currentRoom = rooms[currentRoom][move[1]] #there is no door (link) to the new room else: print('You can\'t go that way!')

#if they type 'get' first if move[0] == 'get' : #if the room contains an item, and the item is the one they want to get if "item" in rooms[currentRoom] and move[1] in rooms[currentRoom]['item']: #add the item to their inventory inventory += [move[1]] #display a helpful message print(move[1] + ' got!') #delete the item from the room del rooms[currentRoom]['item'] #otherwise, if the item isn't there to get else: #tell them they can't get it print('Can\'t get ' + move[1] + '!')

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 Databases Questions!