Question: Classes: 1 . Entity abstract class - describes a character in the game. a . _ _ init _ _ ( self , name, max

Classes:
1. Entity abstract class - describes a character in the game.
a.__init__(self, name, max_hp) initializes each of the instance variables
b. take_damage(self, dmg) subtracts the dmg from the hp, but does not allow the
hp to drop below 0.
c. heal(self) restores the entitys hp to max_hp.
d.__str__(self) returns a string in the format Name
HP: hp/max_hp.
e. attack(self, entity) abstract method (no code) that all entity subclasses will
override to attack and do damage to the opposing entity.
2. Hero extends entity - the users character
a.__init__(self, name) initializes the name and max_hp using super, sets the
heros starting location to row=0, col=0.
b. attack(self, entity) hero attacks the enemy randomize damage in the range 2-5,
the enemy should take the damage and the method should return a string
representing the event.
c. go_north/south/east/west(self) update the heros location by adding or
subtracting 1 to the row or column, but only if that location is within the bounds
of the map (between 0 and the len(map)-1). If it is, return the character at that
location, if it isnt, return an o to signify that the direction is out of bounds.
3. Enemy extends entity - monster character that the hero encounters in the maze.
a.__init__(self) randomizes a name from a list of names (ex.Goblin,Vampire,
Ghoul,Skeleton,Zombie, etc) and randomizes the monsters hp (4-8).
b. attack(self, entity) enemy attacks hero randomize damage in the range 1-4.
The hero should take the damage and the method should return a string
representing the event.
2024 Cleary
4. Map singleton the map of the dungeon maze.
a.__new__(cls) if the map hasnt been constructed, then construct it and store it in
the instance class variable and return it. If it has, then just return the instance.
b.__init__(self) create and fill the 2D map list from the file contents. Create and
fill the 2D revealed list with all False values. The map stores the contents of the
file and the revealed list is used to determine whether the contents of the map are
displayed or not (x if not displayed).
c.__getitem__(self, row) overloaded [] operator returns the specified row from
the map. (Note: this operator can be used to access a row (ex. m[r]) or can be
used to access a value at a row and column (ex. m[r][c]).
d.__len__(self) returns the number of rows in the map list. (Note: if you want to
know the number of rows, use len(m), if you need the number of columns, use
len(m[r])).
e. show_map(self, loc) returns the map as a string in the format of a 5x5 matrix of
characters where revealed locations are the characters from the map, unrevealed
locations are xs, and the heros location is a *.
f. reveal(self, loc) sets the value in the 2D revealed list at the specified location to
True.
g. remove_at_loc(self, loc) overwrites the character in the map list at the specified
location with an n.
5. Main prompt the user to enter their name, then construct the hero and a map object.
Create a loop that repeats until the hero dies, the hero finds the finish, or the user quits the
game. Present a menu that allows the user to choose a direction to move in (north, south,
east, west), move the hero in that direction, reveal that spot, and then present the
encounter at that location as follows:
a.m monster construct an enemy and display its information. Create a loop
that allows the user to either attack or run away. If they attack, the hero attacks
the monster, and if the monster has hp left, then the monster attacks back. If the
monster is dead, then display a message and remove the m from the map. If the
user chooses to run away, then choose a random direction to run in (reveal but
dont present the encounter for the new location)(m should remain on the map).
b.o invalid direction display a message stating that they cannot move that
direction.
c.n nothing display a message stating that this room is empty.
d.s start display a message that they wound up back at the start of the dungeon.
e.i' item room display a message stating that they found a health potion. Heal
the hero and remove the i' from the map so they cant get it again (not required,
but you can add a check to see if the hero has full hp, if they do, then you can
leave the i' on the map to save it for later).
f.f finish display a congratulatory message stating that they found the way out
of the maze and won the game.

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!