Scooby and the Mystery Inc. gang are in a real pickle, or more accurately, you’ll be putting them in one! You will set the stage for their newest adventure, a text-based command-line adventure game, in which the gang must escape a HauntedMansion. You will define several classes and hierarchies that take advantage of object-oriented concepts to handle the different events and scenarios in your mansion. This will include a set of Rooms, Monsters, and a Player. Rooms in the mansion are arranged into a two-dimensional square grid. HauntedMansion models the arrangement, or floorplan, of rooms. A Player always begins in the middlemost Room of the mansion. An exit room will be specially designated. The Player can move left, right, up, or down one step (Room) during each round of the game. The Player begins the game with a level of courage (integer value). The Player wins the game if they find exit room while still having a level of courage above 0. If the player’s courage level ever goes to zero or a negative value, they immediately lose the game. Unfortunately, some rooms in the Mansion contain some not-so-pleasant inhabitants! Whenever a Player enters a Room, they may encounter a Monster. A Monster encounter will take a toll on a Player’s courage. Monsters come in different varieties, and their respective effects on players will vary. You will have a base Monster class and some subclasses to create different types of Monsters. While the scary monsters are there to thwart you, fortunately there will be Scooby Snacks in a few rooms to help you along the way. Moving into a room with Scooby Snacks boosts the Player’s courage. The data members for your classes should be only accessible via appropriate setter and getter methods. You may create such getters and setters as needed, even if they are not explicitly specified. All explicitly described methods should be public unless otherwise stated, and you may create additional private helper methods wherever necessary. Similarly, all instance data should be private unless otherwise stated. You will have to write many constructors throughout this assignment, and they won’t be explicitly detailed in this document. Instance data that’s expected to be provided to constructors is underlined. If an autograder checks for constructor headers, it will anticipate that constructor arguments are listed in the same top to bottom order shared in this document. Player.java The Player class holds information on the player exploring the mansion and is a type of Character. A Player should have these attributes: A name A maximum courage value (constant), which should be a positive whole number and fixed to 150. A current courage value, which should be initialized to the maximum courage value. Row and column numbers corresponding to the player’s current location in a grid. These should always place the player in the middle of the grid. o The constructor should have a parameter for the mansion size (ex: a 10x10 grid would pass 10) o When there is no clear middle (even length), floor the middle calculation such that it elects for the smaller index Row and column numbers corresponding to the player's previous location in a grid. These should be initialized to the same as the current location. A Player should also support the following behaviors: getFrightened o Takes in a single integer, returns nothing. o This should decrease the Player’s current courage by the given amount. If the courage would go below 0, set it to 0 instead. o It should also print out something like: ▪ {name} got scared and lost some courage! {current courage}/{maximum courage} remaining... lookForSnacks o Takes in a single Room, returns nothing. o If the Room does not have Scooby Snacks, this should do nothing. o Otherwise, this should update the Room to no longer have Scooby Snacks and increase the Player’s current courage by 25. If the current courage would go above the maximum courage, set it to the maximum courage instead. o It should also print out something like: ▪ {name} ate a Scooby Snack they found in the room and felt a little more confident. Courage increased to {current courage}/{max courage}.
Scooby and the Mystery Inc. gang are in a real pickle, or more accurately, you’ll be putting them in one! You will set the stage for their newest adventure, a text-based command-line adventure game, in which the gang must escape a HauntedMansion.
You will define several classes and hierarchies that take advantage of object-oriented concepts to handle the different events and scenarios in your mansion. This will include a set of Rooms, Monsters, and a Player.
Rooms in the mansion are arranged into a two-dimensional square grid. HauntedMansion models the arrangement, or floorplan, of rooms. A Player always begins in the middlemost Room of the mansion. An exit room will be specially designated. The Player can move left, right, up, or down one step (Room) during each round of the game. The Player begins the game with a level of courage (integer value). The Player wins the game if they find exit room while still having a level of courage above 0. If the player’s courage level ever goes to zero or a negative value, they immediately lose the game.
Unfortunately, some rooms in the Mansion contain some not-so-pleasant inhabitants! Whenever a Player enters a Room, they may encounter a Monster. A Monster encounter will take a toll on a Player’s courage. Monsters come in different varieties, and their respective effects on players will vary. You will have a base Monster class and some subclasses to create different types of Monsters.
While the scary monsters are there to thwart you, fortunately there will be Scooby Snacks in a few rooms to help you along the way. Moving into a room with Scooby Snacks boosts the Player’s courage.
The data members for your classes should be only accessible via appropriate setter and getter methods. You may create such getters and setters as needed, even if they are not explicitly specified. All explicitly described methods should be public unless otherwise stated, and you may create additional private helper methods wherever necessary. Similarly, all instance data should be private unless otherwise stated.
You will have to write many constructors throughout this assignment, and they won’t be explicitly detailed in this document. Instance data that’s expected to be provided to constructors is underlined. If an autograder checks for constructor headers, it will anticipate that constructor arguments are listed in the same top to bottom order shared in this document.
Player.java
The Player class holds information on the player exploring the mansion and is a type of Character.
A Player should have these attributes:
- A name
- A maximum courage value (constant), which should be a positive whole number and fixed to 150.
- A current courage value, which should be initialized to the maximum courage value.
- Row and column numbers corresponding to the player’s current location in a grid. These should always place the player in the middle of the grid.
o The constructor should have a parameter for the mansion size (ex: a 10x10 grid would pass 10)
o When there is no clear middle (even length), floor the middle calculation such that it elects for the smaller index
- Row and column numbers corresponding to the player's previous location in a grid. These should be initialized to the same as the current location.
A Player should also support the following behaviors:
- getFrightened
o Takes in a single integer, returns nothing.
o This should decrease the Player’s current courage by the given amount. If the courage would go below 0, set it to 0 instead.
o It should also print out something like:
▪ {name} got scared and lost some courage! {current courage}/{maximum courage} remaining...
- lookForSnacks
o Takes in a single Room, returns nothing.
o If the Room does not have Scooby Snacks, this should do nothing.
o Otherwise, this should update the Room to no longer have Scooby Snacks and increase the Player’s current courage by 25. If the current courage would go above the maximum courage, set it to the maximum courage instead.
o It should also print out something like:
▪ {name} ate a Scooby Snack they found in the room and felt a little more confident. Courage increased to
{current courage}/{max courage}.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images