Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a new Java project called P4 and import P4-starter.jar. Download here: http://www.cs.colostate.edu/~cs165/.Spring18/assignments/P4/archive/P4-starter.jar DO NOT USE YOUR OWN CODE USE THE JAR FILE PROVIDED IMPORT

Create a new Java project called P4 and import P4-starter.jar.

Download here: http://www.cs.colostate.edu/~cs165/.Spring18/assignments/P4/archive/P4-starter.jar

DO NOT USE YOUR OWN CODE USE THE JAR FILE PROVIDED IMPORT IT INTO AN EMPTY PROJECT FOLDER!!!!

Your directory should look like this:

P4/  resources   images    iconFence.png    iconGrass.png    iconMunch.png    iconSquirrel.png    iconTerrier.png    iconTree.png   mazes   SimpleGame.txt   SquirrelEscape.txt   SquirrelFence.txt   SquirrelNightmare.txt   TwoSquirrels.txt   TwoTerriers.txt  src  Animal.java  GameEngine.java  Squirrel.java  Terrier.java  UserInterface.java 

Run the GameEngine class with resources/mazes/SimpleGame.txt. The playing field will appear but not be updated correctly. If GameEngine is not running or has compile errors, get some help in the lab.

Description

The purpose of the assignment is to finish three Java classes that implement the behavior of:

Squirrels that are trying to evade terriers

Terriers that feel compelled to chase squirrels.

You will code the behavior of both animals. The game is played on a field, with some number of terriers and squirrels whose placement is determined by a file. The field is a two-dimensional array, with 'S' for Squirrel, 'D' for Terrier, 'T' for Tree, 'F' for Fence, and '-' for empty squares with Grass. Here is a description of the classes involved in this assignment:

The GameEngine class has the main method. It reads the file specified on the command line, and instantiates the UserInterface object to put up the playing field. Approximately every couple of seconds it asks each squirrel and terrier which way they want to move, then updates the playing field accordingly. You should NOT change this class.

The UserInterface class provides the graphics for the game. When instantiated by the GameEngine, it displays a window with the playing field and a counter. After each set of moves, the GameEngine asks the UserInterface object to redraw itself. The playing field array is passed to the UserInterface object in its constructor. You should NOT change this class.

The Animal class is an abstract class that has code that is shared between the Terrier and Squirrel class. You must complete several methods in this class, as described below. The GameEngine continually asks the terriers and squirrels to move, and this class helps with that, but defers parts of the task that are specific to a particular animal to the Terrier and Squirrel classes. The Animal class has code to figure out the closest terrier to a squirrel, and the closest squirrel to a terrier.

Squirrel behavior is defined in Squirrel.java. Squirrels look for the closest terrier and always move in the opposite direction. Squirrel must avoid running into other squirrels or terriers, but they can pass through fences or climb trees. If they make it to a tree, they are safe and disappear from the field.

Terrier behavior is defined in Terrier.java. Terriers always try to chase after the nearest squirrel and eat it. Terriers must avoid running into other terriers or going off the field, and they cannot climb trees or pass through fences.

The game continues until all squirrels are safe or eaten, or for 30 iterations, whichever comes first. None of the supplied fields require that many iterations. The GameEngine reports all movements and significant events. A UML diagram of the classes in the Terriers and Squirrels is shown below:

Testing

You must setup a run configuration for the project with the name of the text file containing the game. Start by testing the individual methods you have written, using "SimpleGame.txt", field, and make sure the Squirrel locates the closest Terrier, and moves in the opposite direction, and avoids going off the field. Then make sure the Terrier locates the closet Squirrel and chases it, and avoids going off the field. The simplest game has only one of each animal. Then proceed to the more difficult fields.

Instructions

Use the javadocs to read implementation details about each method

Javadocs Here: http://www.cs.colostate.edu/~cs165/.Spring18/assignments/P4/doc/javadoc

Here are the complete list of methods you must implement to complete the game, in the optimal order:

makeMove() in Animal.java

computeDistance() in Animal.java

findClosest() in Animal.java

findMove() in Terrier.java

findMove() in Squirrel.java

isValid() in Terrier.java

isValid() in Squirrel.java

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions