- 2nd Aug 2024
- 17:56 pm
In this assignment you will write a text adventure game. The idea of a text adventure game is that the player is in a virtual room in a “dungeon”, and each room has a text description associated with it, such as, “This room in big and brightly lit. It has doors on the north and west walls”. The player can move from room to room using compass directional commands. Your program will be a function called adventure() which takes no arguments and returns no values. Your function adventure() will allow the user to enter commands related to moving through the dungeon and interacting with objects. Your function should print out a prompt to indicate that the user can enter a command. Your prompt should be a ‘$ ’ character. At the prompt the user will type a command followed by a set of arguments for the command. Your function will perform whatever action is indicated by the command, and then your program will print a prompt on a new line in order to let the user know that he/she can type a new command. If the command is a compass command which moves the player into a new room, your program will print the description of the new room before printing the prompt on the next line.
Implementation Details
- For each function/method you should have a one-line docstring describing the function.
- You can assume that the file name given to the loaddungeon command is a file which exists, so you do not need to handle an error if the file is not found.
- All commands are case-sensitive.
- If the user types a command which does not exist then ignore the command.
Dungeon Explorer: Text Adventure Game - Get Assignment Solution
This sample Python assignment solution has been successfully completed by our team of Python programmers. The solutions provided are designed exclusively for research and reference purposes. If you find value in reviewing the reports and code, our Python tutors would be delighted.
-
For a comprehensive solution package including code, reports, and screenshots, please visit our Python Assignment Sample Solution page.
-
Contact our Python experts for personalized online tutoring sessions focused on clarifying any doubts related to this assignment.
-
Explore the partial solution for this assignment available in the blog above for further insights.
Free Assignment Solution - Dungeon Explorer: Text Adventure Game
import sys
class Room:
def __init__(self, rn, desc, north, south, east, west):
self.roomNumber = rn
self.description = desc
self.northRoom = north
self.southRoom = south
self.eastRoom = east
self.westRoom = west
""" – This method takes no arguments and returns the number of the room to the north
of this room, or -1 if there is no room in that direction."""
def getNorth(self):
return self.northRoom
""" This method takes no arguments and returns the number of the room to the south
of this room, or -1 if there is no room in that direction."""
def getSouth(self):
return self.southRoom
"""This method takes no arguments and returns the number of the room to the east of
this room, or -1 if there is no room in that direction. """
def getEast(self):
return self.eastRoom
"""This method takes no arguments and returns the number of the room to the west of
this room, or -1 if there is no room in that direction. """
def getWest(self):
return self.westRoom
""" This method takes no arguments and returns description of room"""
def getDesc(self):
return self.description
DungeonDict = {}
Loaded = False
Currentroom = None
"""this function will allow the user to enter commands related to moving through the
dungeon and interacting with objects. """
def adventure():
global DungeonDict
global Loaded
global Currentroom
comnd = input('$ ')
if 'loaddungeon' in comnd:
comnd,filename = comnd.split()
if comnd == 'loaddungeon' and Loaded == False:
itr = 0
file = open(filename)
for line in file:
part1,part2,part3 = line.split('+')
rn = int(part1.strip())
desc = part2.strip()
n,s,e,w = list(map(int,part3.split()))
newroom = Room(rn,desc,n,s,e,w)
DungeonDict[rn] = newroom
if itr == 0:
Currentroom = newroom
print(Currentroom.getDesc())
itr+=1
loaded = True
elif comnd == 'loaddungeon' and loaded == True:
print("Dungeon already loaded")
elif comnd == 'north':
rn = Currentroom.getNorth()
if rn != -1:
Currentroom = DungeonDict.get(rn)
print(Currentroom.getDesc())
else:
print('You can’t go there.')
elif comnd == 'south':
rn = Currentroom.getSouth()
if rn != -1:
Currentroom = DungeonDict.get(rn)
print(Currentroom.getDesc())
else:
print('You can’t go there.')
elif comnd == 'east':
rn = Currentroom.getEast()
if rn != -1:
Currentroom = DungeonDict.get(rn)
print(Currentroom.getDesc())
else:
print('You can’t go there.')
elif comnd == 'west':
rn = Currentroom.getWest()
if rn != -1:
Currentroom = DungeonDict.get(rn)
print(Currentroom.getDesc())
else:
print('You can’t go there.')
elif comnd == 'quit':
sys.exit(0)
else:
pass
while True:
adventure()
Get the best Dungeon Explorer: Text Adventure Game assignment help and tutoring services from our experts now!
About The Author -
Alex Johnson's text adventure game immerses players in a virtual dungeon. Navigate through rooms using compass directions with the adventure()
function, which manages user commands and room descriptions. Commands are case-sensitive, and invalid commands are ignored. Experience classic dungeon exploration and interactive storytelling!