View the step-by-step solution to:

# Lab 9 is for partially implementing this game. The goal of Lab 9 is to implement the game with a user-specifed number of zombies. Lab 9 does not...

Lab 9 is for partially implementing this game.

The goal of Lab 9 is to implement the game with a user-specifed number of zombies. Lab 9 does not require a chaser. Lab 9 also does not require user-specified values for box size, move size, and sleep time. You may implement these elements in Lab 9 if you wish, but credit for them will be given in your Project 3 score.

Lab 9 should prompt the user for the number of zombies as follows:

```Enter the number of zombies: 10

```

Suppose this value is stored in numZombies.

```Point[] zombies = new Point[numZombies];

```

Each element of the array needs to initialized to a Point object. If i is an int that is greater or equal to 0, and is less than numZombies, then the following initializes the array at index i to a Point with coordinates X=600 and Y=400:

```zombies[i] = new Point(600,400);

```

This needs to be done for every value of i from 0 to numZombies-1.

Rather than putting each zombie at the same location, the coordinates should be random. The X and Y coordinates for each zombie should be random values between 30 and 770.

In the starter code, the variable zombie appears four times in the while loop. Because there are numZombies zombies, each of these appearances need to be replaced with a loop over the zombies array:

```for (int i = 0; i < numZombies; i++) {
Point zombie = zombies[i];
// do stuff to zombie
}

```

In Lab 9, a collision between the runner and any zombie should result in setting gameOver to true. In Project 3, we will worry about making sure that all the zombies are eliminated before the game is over.

Rubric for Lab 9

Your program should compile without any errors. A program with more than one or two compile errors will likely get a zero for the whole assignment.

The following criteria will also be used to determine the grade for Lab 9.

• General [2 points]Your submission was a Zip file named lab9.zip containing at least the two files called SurvivorII.java and DrawingPanel.java.
• Your program contains a comment that describes what the program does and contains a descriptive comment for each method.
• Your program is indented properly.
• Creation of zombies [6 points][2 points] The user can enter the desired number of zombies.
• [2 points] The correct number of zombies appear in the game. The color of the zombies is different from the runner.
• [2 points] The zombies appear in locations that are randomly generated.
• Movement of the zombies [6 points][4 points] The zombies move in a random walk.
• [2 points] The zombies do not move out of the box.
• Movement of runner [4 points][2 points] The user can control the runner using the WASD keys.
• [2 points] The runner cannot move into the box boundary or move outside the box.
• End of the game [2 points][2 points] The game ends when the runner collides with any zombie.
Project 3

Project 3 will finish the game. As in Project 2, the game needs a chaser and user-specified values for box size, move size, and sleep time. Also, all the zombies must be eliminated for the user to win the game.

Chaser

As in Project 2, the chaser should be a Point object starting at a fixed location.

```Point chaser = new Point(600,200);

```

The chaser should be displayed using a different color from the runner and zombies.

```displayPlayer(chaser, Color.RED);

```

A move by the chaser means using the translate method to change the X or Y coordinate of the chaser, but not both. A single move of moveSize - 1 pixels must be up, down, left, or right. For example, chaser.translate(0, -(moveSize - 1)) would move the chaser up. The move of the chaser is determined by choosing the move (out of the four possible moves) that gets the chaser chosest to the runner.

User-Specified Values

The starter code currently has fixed values for the size of the box, the size of each move, and amount of sleep time each iteration. The user should be asked for these values as well as the number of zombies using a single prompt.

```Enter the number of zombies, box size, move size, and sleep time: 10 760 10 100

```

If the user enters a 0 or negative number, use the default value for that variable. Other magic numbers in the starter code might need to replaced with appropriate expressions to take the user's inputs into account. For the same reason, methods in the starter code might need more parameters.

There needs to be a chaser that always follows the runner. See the Project 2 description for how the chaser should work.

Eliminating Zombies

For each zombie, the program needs to remember whether it is eliminated or not. This can be done using a boolean array.

```boolean[] eliminated = new boolean[numZombies];

```

Java initializes each element of this array to false. When zombies[i] has been eliminated, then element i of the eliminated array needs to be set to true.

```eliminated[i] = true;

```

If zombies[i] has been eliminated, then that zombie should not be displayed on the window. This can be controlled with an if statement.

```if (! eliminated[i])
displayZombie(panel, zombies[i]);

```
End of the Game

The game should end if the chaser collides with the runner. In this case, the program should print YOU LOSE!

The game should also end if the runner eliminates all the zombies. This requires checking that every value in the eliminated array has been set to true. If any value in the eliminated array is false (and if the chaser does not collide with the runner), then the game should continue. If the runner eliminates all the zombies, then the program should print YOU WIN!.

Rubric for Project 3

Your program should compile without any errors. A program with more than one or two compile errors will likely get a zero for the whole assignment.

The following criteria will also be used to determine the grade for Project 2.

• The program satisfies the rubric for Lab 9 [10 points]See the Lab 9 rubric above.
• User-Specified Values [4 points][2 points] The speed of the runner and the chaser is determined by the move size and sleep time parameters entered by the user.
• [2 points]The size of the panel and the box and the initial positions of the runner and chaser are determined by the box size entered by the user. Also, all the zombies are in the box.
• Movement of the chaser [2 points][2 points] The chaser always moves toward the runner. The chaser is a different color from the runner and zombies. The chaser is slightly slower than the runner. If there is a collision between the runner and the chaser, the game immediately ends and results in a YOU LOSE!!! message.
• Eliminating zombies [4 points][2 points] When the runner collides with a zombie, the zombie is eliminated from the game.
• [2 points]When the runner has eliminated all the zombies, the game immediately ends with a YOU WIN!!! message.

i have my own code for this but it will not let me send for some reason

### Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

### -

Educational Resources
• ### -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents