These instructions tell you to Derive 3 types of Monsters. When you're told to "derive" some types, that usually means you're supposed to extend a base class. In this case, the base class is Monster. I'm not sure defining an enum really qualifies as a valid interpretation of those instructions. You might want to run this by your instructor to make sure you're on the right track with the enum, before you get too far along and it gets more and more difficult to switch gears and head in a different direction with your design.
Derive 3 types of Monsters (for example, Cyclops, King Kong, and Frankenstein) from
the Monster class, each with its own number of health points and its own amount of
damage it can inflict.
I didn't have any control over the class names. I simply named them what I was instructed to name them. The enum thing however, was my fault.Junilu Lacar wrote:Class names, for example, are normally singular, not plural. In the case of your Monsters class, it should be just Monster since an instance of this class represents only ONE monster, not several monsters. Same thing for Participants; it should be singular, not plural.
Exception in thread "main" java.lang.NullPointerException
at game.Monsters.toString(Monsters.java:104)
at game.Rooms.toString(Rooms.java:128)
at game.GameManager.toString(GameManager.java:216)
at java.lang.String.valueOf(Unknown Source)
at java.io.PrintStream.println(Unknown Source)
at game.Driver.main(Driver.java:50)
You're in an unfamiliar room.
To explore please type E to move east and W to move west.
Room 1 contains:
The room is empty
E
Room 1 contains:
The room is empty
E
Room 1 contains:
The room is empty
e
Room 1 contains:
The room is empty
Room 2 contains:
Mordac (26 health point(s) remaining)
Badger on a stick (+4 point(s) of damage)
Room 3 contains:
The room is empty
Room 4 contains:
Toaster (23 health point(s) remaining)
No weapons
Room 3 contains:
The room is empty
Room 4 contains:
Toaster (23 health point(s) remaining)
No weapons
Generally we can't make additional classes if they weren't specified as part of the assignment and we weren't told otherwise on this one, so I'm just sticking with what's specified.Junilu Lacar wrote:Why don't you have a room class?
The 50% chance isn't the problem, just setting up the rooms so they can contain both a monster and a weapon as well as a player, but since the player and monster are both derived from Participants class that's not as much of an issue I don't think...Also, the Random class has a nextBoolean() method that has about a 50-50 chance of being true (a boolean, after all, can only one of two values).
Use an array as a map? But how would that allow me to hold two totally different types of objects? I'm not sure I fully understand that. Would that require having another class specifically designed for Rooms? It's limitations like being required to work within very tight guidelines that make some of these projects a pain.A Map would be appropriate if you had a key that you mapped to a value. In this case, what would be the key that will uniquely identify a room? Note that you can use an array as a Map, if you consider the index of an element as its key.