There is a Squirrel in a maze looking for nuts. You will guide the squirrel to find and collect the nuts. There are two types of nuts available in the maze, Almonds and Peanuts. As the squirrel collects the nuts, it gains nutritional points. Once the squirrel finds all the nuts in the maze, the game is over. To implement this game, you will define 7 classes: Maze class, Entity class, Squirrel class, Nuts class, Almond class, Peanut class, and HungrySquirrelGame class. Each class is described in details in the following sections.

The following class diagram shows the relationship between the classes: See image.

In this document, you will find each class defined in details. There is enough information to help you build and implement this game. You are not required to implement the class attributes and methods exactly as specified here; feel free to add/remove attributes or methods as you see fit. However, you must define each class and do not make modifications to the class names.

1.The Maze Class

You must define the Maze class. The maze is a 20 x 50 rectangular area represented by a 2-dimensional character array. The walls in the maze are represented by * and available positions by blank space. The maze structure is read from a text file Maze.txt (The Maze.txt will be provided to you). A squirrel is able to freely move in blank spaces in the maze.

**************************************************
******************** **********************
******************** **********************
******************** **********************
*********** ***********
*********** ***********
* **
* **
* **
* ********************** **
* ********************** **
* ********************** **
* ********************** **
* **
* **
* **
***** ************** ********
************ *************
***** *********
**************************************************

The Maze class defines the following attributes:

  • Max_Maze_Row: This class variable is a constant variable that defines the maximum number of rows in the maze (it should be set to 20 rows).
  • Max Maze Column: This class variable is a constant variable that defines the maximum number of columns in the maze (it should be set to 50 columns).
  • maze[][] : This class variable is a 2-dimentional character array that contains the full maze and the entities.

The Maze class implements the following methods:

public static void create(String filename)

This method reads the file passed to the method (i.e. Maze.txt) and initializes the 2-dimentional array with the maze content provided in the file.

public static void display()

This method will display the maze structure and the containing entities.

public static boolean available(int row, int col)

This method takes a row and a column and determines if the location at the row and the column is blank space. If it is, it returns true; otherwise, it returns false.

2.Movable Interface

You must define the "Movable" interface. This interface is implemented by entities that are capable to move in the maze (e.g. Squirrel) This interface has a single method:

void move(char direction)

3.Entity Class

You must define an abstract Entity class. Two types of entities exist in the Maze: Nuts and Squirrel. Each entity has three attributes:

  • Symbol: This instance variable is a character symbol by which an entity is identified on the Maze. For example, a squirrel is represented by @. Each nut will be represented by the first character of its name (e.g. Almond will be represented by A).
  • rowPosition: This instance variable is the row position of the entity in the maze.
  • colPosition: This instance variable is the column position of the entity in the maze.

The abstract Entity class contains an abstract method:

public void create()

The Entity class contains the following concrete method:

public char put(int newRow, int newCol)

This method puts an entity at location (newRow, newCol) in the maze. You have to pay attention because the entity cannot move to a location already filled with a wall (i.e. *). This method returns a character that was replaced in the new location. This can be useful when moving the squirrel and figuring out what it stepped over.

4.Squirrel Class

You must define the Squirrel class. The squirrel is represented by the @ symbol in the maze. It is able to move up, down, left and right. The initial location of the squirrel is determined by the user. The program must prompt the user to enter the starting row and column of the squirrel. The squirrel cannot move to where there is a wall (i.e. *). Once the squirrel moves over a nut, it collects points. Each type of nut carries a different point.

You must define the Squirrel class which is inherited from the Entity abstract class and implements the Movable interface. The Squirrel class contains two attributes:

  • pointsCollected: This attribute provides the total points a squirrel object has accumulated as a result of gathering nuts.
  • Total number of nuts collected: This attribute provides the total number of nuts gathered thus far.

The Squirrel class defines the following methods:

public void create()

This method overrides the abstract method in the Entity superclass. This method asks the user to provide the initial location of the squirrel in the maze. You have to make sure the location provided by the user is valid and available. If the user provides an invalid or unavailable location, you will have to ask the user to input a new set of data. You must continue until the user provides a valid position. Keep in mind that a squirrel cannot be placed where there is a wall *.

public void move(char direction)

This method moves the squirrel one position to the direction specified.

5.Nuts Class

Nuts are entities that are placed in the maze for the squirrel to find. There are two types of nuts available: Almond and Peanut. When a squirrel moves over a nut, itll gain points. Once a nut is collected, it should disappear from the maze. There are total of 5 nuts created. The nuts locations are created randomly in the maze and have to be placed in a valid location in the maze, meaning that a nut cannot be put in a position occupied by a wall (*), a squirrel (@) or a previously created nut. The number of peanuts / almonds are based on a random 50% chance.

The Nuts class is inherited from the Entity abstract class. The Nuts class must contain the following attribute:

  • Total Nuts: This class variable is a constant variable that represents the total number of nuts that will be created for this game (For this project, we create 5 nuts).
  • NutritionPoints: This instance variable stores then nutrition points of the nut.

The Nuts class implements (or override when appropriate) the following methods:

void create()

This method overrides the abstract method in the Entity superclass. This method randomly creates the location of the nuts. You have to make sure the locations are valid and available. Keep in mind that a nut cannot be placed over a wall (*), a squirrel (@) or a previously created nut. In other words, it can only be placed where there is a blank space ( ).

6.Almond Class

Almond is a type of a Nut . An almond is represented by the character symbol A in the maze. An almond carries 5 nutritional points; therefore, when the squirrel eats an almond, it gains 5 points.

The Almond Class is inherited from the Nuts class. The Almond class must define the following attribute:

  • Nutrition Points: This class variable is a constant variable that represents the nutrition points an almond carries.

7.Peanut Class

Peanut is a type of a Nut. A peanut is represented by the character symbol P in the maze. A peanut carries 10 nutritional points; therefore, when the squirrel eats a peanut, it gains 10 points.

The Peanut Class is inherited from the Nuts class. The Peanut class must define the following attribute:

  • Nutrition Points: This class variable is a constant variable that represents the nutrition points a peanut carries.

8.HungrySquirrelGame Class

The HungrySquirrelGame class defines the main method. The flow of the main method can be something like this:

  • Call the create method of the Maze class to create the maze.
  • Instantiate a squirrel object. This creates the squirrel and puts the squirrel in the maze based on the user input.
  • Instantiate an array of Nuts objects and determine and create the type of nuts (almond or peanut).
  • Display the maze with all the entities created.
  • Accept user input to move the squirrel.
  • For every move the full maze with all the entities should be displayed.
  • Every time the squirrel collects a new nut, a message must be output displaying the points collected for the new nut and total points collected thus far. !!! Squirrel got 5 points (Total 15 points) !!!
  • Once the squirrel collects all the nuts, a message must be displayed and the game is over.
“Squirrel successfully collected all the nuts. Total points 30.”
“Thank you for playing this game”

**************************************************
******************** **********************
******************** **********************
******************** **********************
*********** ************
*********** ************
* **
* **
* **
* ********************** **
* ********************** **
* ********************** **
* ********************** **
* **
* **
* **
***** ************** ********
************ *************
***** *********
**************************************************

Enter the Squirrel position (row , column): 1,1

Position not available. Try again!

Enter the Squirrel position (row , column): 7,23

User input accepted.

Enter commands u,d,l,r to move Up, Down, Left, and Right:





**************************************************
******************** **********************
******************** **********************
******************** **********************
*********** ************
*********** ************
* @ **
* **
* A P **
* ********************** **
* ********************** **
* P ********************** **
* ********************** **
* A **
* **
* **
***** ************** ********
************ *************
***** P *********
**************************************************

Enter command: d
**************************************************
******************** **********************
******************** **********************
******************** **********************
*********** ************
*********** ************
* **
* @ **
* A P **
* ********************** **
* ********************** **
* P ********************** **
* ********************** **
* A **
* **
* **
***** ************** ********
************ *************
***** P *********
**************************************************





**************************************************
******************** **********************
******************** **********************
******************** **********************
*********** ************
*********** ************
* **
* **
* **
* ********************** **
* ********************** **
* ********************** **
* ********************** **
* **
* **
* **
***** ************** ********
************ *************
***** @ *********
**************************************************

Squirrel successfully collected all the nuts. Total points 40
Thank you for playing this game
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.