Lab 12: Abstract Classes and Polymorphism

due Monday, February 24 at 9:20am on Canvas

Pair Programming Required (or No Credit)
  • Both partners fill in, sign, date, and submit the pair programming contract
  • Upload the document along with your Lab code to Canvas.
  • Only ONE partner submits the Lab code on Canvas.
  • BOTH partners submit the contract.
  • Please make sure both your names are on all the files.
  • If you need help finding a partner, please contact me as soon as possible.

Pac-Cookie!

  • For this lab, you will write a simplified version of Pac-man called Pac-Cookie. 
  • During this assignment, you will:
    1. Write an abstract class to hold the data for a game character
    2. Write a subclass to store information about the player character
    3. Write a subclass to store information about a ghost character
    4. Extend the ghost class to create an additional sub-class for another Ghost character, named Spooky
    5. Write a game class
    6. Optionally, construct a class that uses static methods to test a class

Game Specifications:

  • Pac-Cookie is a simplified, turn-based version of the arcade game Pac-man.
  • In this game, the user plays as Pac-Cookie (represented with a P on the game board)
  • Pac-Cookie's goal is to consume 20 cookies (represented with *) without running into a Ghost (represented with a G on the game board).
  • Note that Ghosts should also consume cookies as they advance through the board
  • The board is represented as a 10X10 2D array initially filled with * (cookies) and H walls
  • After the initial introduction to the game, the player should be asked to enter one of four possible options to move the character along the game board:
      • u (up)
      • d (down)
      • l (left)
      • r (right)
  • After the player has entered a selection, the Ghosts should move and then the updated game board should be displayed.
    • Do not display the game board before the Ghosts have moved.
  • If the Player lands on a row and column in the board that contains a *, the Player should be given one point and the * should be replaced with a blank space for the remainder of the game.
    • Also, any cookies eaten by the Ghost (G) or Spooky (S) should replace *s with blank spaces on the board.
  • You must perform some error checking:
  • First, the Player character cannot go out of bounds of the 2D array.
    • Otherwise, the game prints a message "Ouch!" For example:
Welcome to Pac-Cookie!

Your goal is to eat all remaining cookies (at least 20) - before you escape!
But, beware the not-so-friendly ghosts...
They will eat the cookies... and YOU!

Ready to play? Let's go!

Score: 0
Remaining Cookies: 53

H H H H H H H H H H

H P * * * * * * * H

H * * * * * * * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * * * * * * G *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Ouch!
Score: 0
Remaining Cookies: 53

H H H H H H H H H H

H P * * * * * * * H

H * * * * * * * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * * * * * * G *

H H H H H H H H H H

How do you want to move? (u/d/l/r):
  • Similarly, the player cannot move through inner walls. For example:
How do you want to move? (u/d/l/r): r
Score: 3
Remaining Cookies: 47

H H H H H H H H H H

H   * * * * * * * H

H   * * * * * * * H

H   P H * * H * * H

H * * H * * H * * H

H * * H * * H * G H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Ouch!
Score: 3
Remaining Cookies: 47

H H H H H H H H H H

H   * * * * * * * H

H   * * * * * * * H

H   P H * * H * * H

H * * H * * H * * H

H * * H * * H * G H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Ouch!
Score: 3
Remaining Cookies: 47

H H H H H H H H H H

H   * * * * * * * H

H   * * * * * * * H

H   P H * * H * * H

H * * H * * H * * H

H * * H * * H * G H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r):

  • However, the Ghosts can move through inner (but not outer) walls. For example:
Score: 31
Remaining Cookies: 9

H H H H H H H H H H

H                 H

H                 H

H     H * * H     H

H     H * P H     H

H     H *   H     H

H     G *   H     H

H     H *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
  • Second, if the user enters incorrect input, the program must print "Invalid move!" and the game should not advance until the user types in correct input:
How do you want to move? (u/d/l/r): dd
Invalid move!
Score: 3
Remaining Cookies: 47

H H H H H H H H H H

H   * * * * * * * H

H   * * * * * * * H

H   P H * * H * * H

H * * H * * H * * H

H * * H * * H * G H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r):

  • The game should continue until one of the following events occurs:
    • The Player loses by getting eaten by one of the Ghosts (both Player and Ghost end up at the same row and col within the 2D array)
    • The Player loses because there are not enough cookies left on the game board for the Player to achieve 20 points.
    • The Player wins by scoring more than 20 points AND escaping out the lower right-side exit WITH no more cookies remaining on the board.
  • Required: You must implement the classes whose starter code is provided below.
    • In your implementation, you will be expected to read the comments for each method and implement the method based on the given description.
  • Pay particular attention to the algorithm followed by the Ghost:
    • The Ghost will start the game in the lower right corner.
    • It should follow a pattern of moving only in the upwards position until it reaches the top row of the maze.
    • From the top row, it should proceed moving only left until it reaches the upper left corner,
    • Once it arrives in the upper left corner, it should jump to the bottom right corner again
    • Its movements are complicated by the fact that every 10 turns, it should spawn to random position on the board.
    • From this random position, it should proceed to move all the way to the top, followed by all the way to the left.
    • This Ghost should eat cookies, as shown
    • For more information, please see the sample output located at the end of the lab directions.
  • Additionally, you must extend the Ghost class to write a Ghost sub-class (Spooky.java), representing a different Ghost character
    • Both Ghost characters should behave differently in the game.
    • Please use an S to represent Spooky on the board.
    • Both Ghost characters must be displayed on the game board at all times
    • You must implement the Ghost.java class provided, and then it is up to your own powers of invention to create the Spooky subclass and determine how the Ghosts behave in the game.
    • The name of the Ghost subclass must be Spooky.java and must extend Ghost.java
  • Below is the starter code for the required classes (except for Spooky.java).

Character.java Code:

  • The below abstract class must remain unchanged from what is provided, or you will receive no credit for this lab.
  • Note that you will not submit this file to Canvas
  • You will inherit from this class when you write Player.java and Ghost.java

/**
 * Character.java
 * @author
 * @author
 * CIS 36B, Lab 12
 */
public abstract class Character {
    private int xPos;
    private int yPos;
   
    /**
     * Sets the x (column) location of the character
     * @param x the x position of the character in the x-y plane
     */
    public void setXPos(int x) {
        xPos = x;
    }
   
    /**
     * Sets the y (row) location of the character
     * @param y the y position of the character in the x-y plane
     */
    public void setYPos(int y) {
        yPos = y;
    }
   
   
    /**
     * Returns the x position of the character
     * @return the x position of the character in the x-y plane
     */
    public int getXPos() {
        return xPos;
    }
   
    /**
     * Returns the y position of the character
     * @return the y position of the character in the x-y plane
     */
    public int getYPos() {
        return yPos;
    }
   
   
    /**
     * Moves the character one space to the left
     * by subtracting one from its x position
     * Or, prevents the player from going outside
     * the bounds of the board by leaving the
     * character in the same position.
     */
    public void moveLeft() {
        xPos-=1;
    }
   
    /**
     * Moves the character one space to the right
     * by adding one to its x position
     * Or, prevents the player from going outside
     * the bounds of the board by leaving the
     * character in the same position.
     */
    public void moveRight() {
        xPos+=1;
    }
   
    /**
     * Moves the character one space down
     * by adding one to its y position
     * Or, prevents the player from going outside
     * the bounds of the board by leaving the
     * character in the same position.
     */
    public void moveDown() {
        yPos+=1;
    }
   
    /**
     * Moves the character one space up
     * by subtracting one from its y position
     * Or, prevents the player from going outside
     * the bounds of the board by leaving the
     * character in the same position.
     */
    public void moveUp() {
        yPos-=1;
    }
}

Player.java
  • At a minimum, you must implement the below methods, but may also add any additional methods you would like.
  • Note that you are only allowed to add methods to this class, but no variables.
/**
 * Player.java
 * @author FILL IN HERE
 * @author
FILL IN HERE
 * CIS 36B, Lab 12
 */

public final class Player extends Character{
    private int score;
   
    /**
     * Player default constructor
     * Gives the player a starting
     * position of [1,1] on the board
     * and sets score to 0
     */
    public Player() {
    }
   
    /**
     * Returns the player's current score
     * @return the score
     */
    public int getScore() {
        return -1;
    }
   
    /**
     * Updates the player's score by 1
     */
    public void updateScore() {
        return;
    }
}


Ghost.java:
  • At a minimum, you must implement the below methods, but may also add any additional methods you would like.
  • Note that you can only add methods to this class, not variables.
  • You must then extend this class to create the Spooky.java class.
/**
 * Ghost.java
 * @author FILL IN HERE
 * @author FILL IN HERE
 * CIS 36B, Lab 12
 */

import java.util.Random;

public class Ghost extends Character{
    private int numMoves;
    int max;
   
    /**
     * One argument constructor
     * Calls setXPos() and setYPos()
     * to give the ghost its initial
     * placement at the bottom right
     * corner of the board [max-2, max-2]
     * Also initializes max (the max
     * x and y dimension on the board)
     * and numMove to 0
     * @param max the
     */
    public Ghost(int max) {
    }
   
    /**
     * Moves the Ghost according to an
     * algorithim:
     * If the number of moves it has made
     * is divisible by 10, it generates a
     * random move. Otherwise, it moves up
     * until it cannot go farther. Then,
     * it moves left until it can go no
     * farther.
     * Once it reaches the [1,1]
     * corner it jumps back to its starting
     * position. Updates numMoves.
     */
    public void move() {
       
    }
   
    /**
     * Places the ghost at a random
     * board position
     */
    public void generateRandomMove() {
    }
}



Game.java:
  • At a minimum, you must implement the below methods, but may also add any additional methods you would like to represent the game play as shown in the sample output below.
  • Also you should declare two new private variables of type Spooky(represented as an S on the board).
/**
 * Game.java
 * @author FILL IN HERE
 * @author FILL IN HERE
 * CIS 36B, Lab 12
 */

import java.util.Scanner;

public class Game {
    private int upperX;
    private int upperY;
    private int totalCookies;
   
    private Ghost g;
    private Player p;
    private String board[][];
   
    /**
    * Constructor for the Game class
    * Initializes private variables
    * Calls initialize board to intialize
    * the board. Places characters at their
    * starting positions.
    * Note that there are 53 cookies on
    * the board at the start of the game
    */
    public Game() {
       
    }
   
   /**
     * Initializes the board to *s for cookies
     * and Hs for walls
     * Called by the constructor
     */
    private void initializeBoard() {
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board[i].length; j++) {
                if( i == 0 || j == 0) {
                    board[i][j] = "H";
                } else if (j == board.length - 1 || i == board.length - 1) {
                    board[i][j] = "H";
                } else if (j == board.length / 3 && i > 2 && i < 8 ) {
                    board[i][j] = "H";
                } else if (j == (2 * board.length) / 3 && i > 2 && i < 8 ) {
                    board[i][j] = "H";
                } else {
                    board[i][j] = "*";
                }
            }
        }
    }
   
    /**
     * Places the player and ghost at a
     * new spot on the board
     */
    public void updateBoard() {
        return;
    }
   
    /**
     * Replaces the current location of the
     * player and ghost with two blank spaces
     * unless the ghost is walking through a wall
     * in which case, only the player's space
     * is cleared
     * Hint: See initializeBoard method for
     * placement of interior walls
     */
    public void clearSpace() {
        return;
    }
   
    /**
     * Prints out board as shown in sample output
     * including displaying the current score and
     * the number of remaining cookies
     */
    public void printBoard() {
        return;
    }
   
    /**
     * Determines whether the player has lost by either
     * being eaten by the ghost or because there
     * are not enough cookies left on the board to win
     * @return whether the player has lost
     */
    public boolean gameOverLose() {
        return false;
    }
   
    /**
     * Determines whether the player has won
     * the game by scoring at least 20 points,
     * eating all possible cookies, and
     * escaping from the hole in the leftside
     * wall
     * @return whether the player has won
     */
    public boolean gameOverWin() {
        return false;
    }
   
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String choice = "";
       
        System.out.println("Welcome to Pac-Cookie!\n");
        System.out.println("Your goal is to eat all remaining cookies (at least 20) - before you escape!");
        System.out.println("But, beware the not-so-friendly ghosts..."
                + "\nThey will eat the cookies... and YOU!");
        System.out.println("\nReady to play? Let's go!\n");
       
        Game game = new Game();
       
        //Add your code here!
      
        input.close();
       
    }
}



Base Game (Before Spooky Added) Sample Output:


Example 1: Winning the Game:

Welcome to Pac-Cookie!

Your goal is to eat all remaining cookies (at least 20) - before you escape!
But, beware the not-so-friendly ghosts...
They will eat the cookies... and YOU!

Ready to play? Let's go!

Score: 0
Remaining Cookies: 53

H H H H H H H H H H

H P * * * * * * * H

H * * * * * * * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * * * * * * G *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Ouch!
Score: 0
Remaining Cookies: 53

H H H H H H H H H H

H P * * * * * * * H

H * * * * * * * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * * * * * * G *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 1
Remaining Cookies: 51

H H H H H H H H H H

H   * * * * * * * H

H P * * * * * * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * G H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 2
Remaining Cookies: 49

H H H H H H H H H H

H   * * * * * * * H

H   * * * * * * * H

H P * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * G H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 3
Remaining Cookies: 47

H H H H H H H H H H

H   * * * * * * * H

H   * * * * * * * H

H   * H * * H * * H

H P * H * * H * * H

H * * H * * H * G H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 4
Remaining Cookies: 45

H H H H H H H H H H

H   * * * * * * * H

H   * * * * * * * H

H   * H * * H * * H

H   * H * * H * G H

H P * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 5
Remaining Cookies: 43

H H H H H H H H H H

H   * * * * * * * H

H   * * * * * * * H

H   * H * * H * G H

H   * H * * H *   H

H   * H * * H *   H

H P * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 6
Remaining Cookies: 41

H H H H H H H H H H

H   * * * * * * * H

H   * * * * * * G H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H P * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 7
Remaining Cookies: 39

H H H H H H H H H H

H   * * * * * * G H

H   * * * * * *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H P * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 8
Remaining Cookies: 37

H H H H H H H H H H

H   * * * * * G   H

H   * * * * * *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H   P * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 9
Remaining Cookies: 35

H H H H H H H H H H

H   * * * * G     H

H   * * * * * *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H   P H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 10
Remaining Cookies: 34

H H H H H H H H H H

H   * * * *     G H

H   * * * * * *   H

H   * H * * H *   H

H   * H * * H *   H

H   * H * * H *   H

H   P H * * H *   H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 11
Remaining Cookies: 33

H H H H H H H H H H

H   * * * *   G   H

H   * * * * * *   H

H   * H * * H *   H

H   * H * * H *   H

H   P H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 12
Remaining Cookies: 32

H H H H H H H H H H

H   * * * * G     H

H   * * * * * *   H

H   * H * * H *   H

H   P H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 13
Remaining Cookies: 30

H H H H H H H H H H

H   * * * G       H

H   * * * * * *   H

H   P H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 14
Remaining Cookies: 28

H H H H H H H H H H

H   * * G         H

H   P * * * * *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 15
Remaining Cookies: 26

H H H H H H H H H H

H   * G           H

H     P * * * *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 16
Remaining Cookies: 24

H H H H H H H H H H

H   G             H

H       P * * *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 17
Remaining Cookies: 23

H H H H H H H H H H

H G               H

H         P * *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 18
Remaining Cookies: 22

H H H H H H H H H H

H                 H

H           P *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     * * * * * G *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 19
Remaining Cookies: 21

H H H H H H H H H H

H                 H

H             P   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H * G H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 20
Remaining Cookies: 20

H H H H H H H H H H

H                 H

H                 H

H     H * * H P   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     H * * H *   H

H     * * * * * G *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 21
Remaining Cookies: 19

H H H H H H H H H H

H                 H

H                 H

H     H * * H     H

H     H * * H P   H

H     H * * H *   H

H     H * * H *   H

H     H * * H * G H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 22
Remaining Cookies: 18

H H H H H H H H H H

H                 H

H                 H

H     H * * H     H

H     H * * H     H

H     H * * H P   H

H     H * * H * G H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 23
Remaining Cookies: 17

H H H H H H H H H H

H                 H

H                 H

H     H * * H     H

H     H * * H     H

H     H * * H   G H

H     H * * H P   H

H     H * * H *   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 24
Remaining Cookies: 16

H H H H H H H H H H

H                 H

H                 H

H     H * * H     H

H     H * * H   G H

H     H * * H     H

H     H * * H     H

H     H * * H P   H

H     * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 25
Remaining Cookies: 15

H H H H H H H H H H

H                 H

H                 H

H     H * * H   G H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     * * * * P   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): l
Score: 26
Remaining Cookies: 14

H H H H H H H H H H

H                 H

H               G H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     * * * P     *

H H H H H H H H H H

How do you want to move? (u/d/l/r): l
Score: 27
Remaining Cookies: 13

H H H H H H H H H H

H               G H

H                 H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     * * P       *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 28
Remaining Cookies: 12

H H H H H H H H H H

H             G   H

H                 H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     H * P H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 29
Remaining Cookies: 11

H H H H H H H H H H

H           G     H

H                 H

H     H * * H     H

H     H * * H     H

H     H * * H     H

H     H * P H     H

H     H *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 30
Remaining Cookies: 10

H H H H H H H H H H

H                 H

H                 H

H     H * * H     H

H     H * * H     H

H     H * P H     H

H     H *   H     H

H     G *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 31
Remaining Cookies: 9

H H H H H H H H H H

H                 H

H                 H

H     H * * H     H

H     H * P H     H

H     H *   H     H

H     G *   H     H

H     H *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 32
Remaining Cookies: 8

H H H H H H H H H H

H                 H

H                 H

H     H * P H     H

H     H *   H     H

H     G *   H     H

H     H *   H     H

H     H *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Ouch!
Score: 32
Remaining Cookies: 8

H H H H H H H H H H

H                 H

H                 H

H     H * P H     H

H     H *   H     H

H     G *   H     H

H     H *   H     H

H     H *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): l
Score: 33
Remaining Cookies: 7

H H H H H H H H H H

H                 H

H                 H

H     H P   H     H

H     G *   H     H

H     H *   H     H

H     H *   H     H

H     H *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 34
Remaining Cookies: 6

H H H H H H H H H H

H                 H

H                 H

H     G     H     H

H     H P   H     H

H     H *   H     H

H     H *   H     H

H     H *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 35
Remaining Cookies: 5

H H H H H H H H H H

H                 H

H     G           H

H     H     H     H

H     H     H     H

H     H P   H     H

H     H *   H     H

H     H *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 36
Remaining Cookies: 4

H H H H H H H H H H

H     G           H

H                 H

H     H     H     H

H     H     H     H

H     H     H     H

H     H P   H     H

H     H *   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 37
Remaining Cookies: 3

H H H H H H H H H H

H   G             H

H                 H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     H P   H     H

H     * *         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): d
Score: 38
Remaining Cookies: 2

H H H H H H H H H H

H G               H

H                 H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     * P         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 38
Remaining Cookies: 2

H H H H H H H H H H

H                 H

H                 H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     *   P     G *

H H H H H H H H H H

How do you want to move? (u/d/l/r): l
Score: 38
Remaining Cookies: 2

H H H H H H H H H H

H                 H

H                 H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     G     H     H

H     * P         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): l
Score: 39
Remaining Cookies: 1

H H H H H H H H H H

H                 H

H                 H

H     H     H     H

H     H     H     H

H     H     H     H

H     G     H     H

H     H     H     H

H     P           *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 39
Remaining Cookies: 1

H H H H H H H H H H

H                 H

H                 H

H     H     H     H

H     H     H     H

H     G     H     H

H     H     H     H

H     H     H     H

H       P         *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 39
Remaining Cookies: 1

H H H H H H H H H H

H                 H

H                 H

H     H     H     H

H     G     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H         P       *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 39
Remaining Cookies: 1

H H H H H H H H H H

H                 H

H                 H

H     G     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H           P     *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 39
Remaining Cookies: 1

H H H H H H H H H H

H                 H

H     G           H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H             P   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 39
Remaining Cookies: 1

H H H H H H H H H H

H     G           H

H                 H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H               P *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 40
Remaining Cookies: 0

H H H H H H H H H H

H   G             H

H                 H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H     H     H     H

H                 P

H H H H H H H H H H

Congratulations! You win!
Final score: 40




Example 2: Losing the Game:



Welcome to Pac-Cookie!

Your goal is to eat all remaining cookies (at least 20) - before you escape!
But, beware the not-so-friendly ghosts...
They will eat the cookies... and YOU!

Ready to play? Let's go!

Score: 0
Remaining Cookies: 53

H H H H H H H H H H

H P * * * * * * * H

H * * * * * * * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * * * * * * G *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 1
Remaining Cookies: 51

H H H H H H H H H H

H   P * * * * * * H

H * * * * * * * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * G H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 2
Remaining Cookies: 49

H H H H H H H H H H

H     P * * * * * H

H * * * * * * * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * G H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 3
Remaining Cookies: 47

H H H H H H H H H H

H       P * * * * H

H * * * * * * * * H

H * * H * * H * * H

H * * H * * H * * H

H * * H * * H * G H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 4
Remaining Cookies: 45

H H H H H H H H H H

H         P * * * H

H * * * * * * * * H

H * * H * * H * * H

H * * H * * H * G H

H * * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 5
Remaining Cookies: 43

H H H H H H H H H H

H           P * * H

H * * * * * * * * H

H * * H * * H * G H

H * * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 6
Remaining Cookies: 41

H H H H H H H H H H

H             P * H

H * * * * * * * G H

H * * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

How do you want to move? (u/d/l/r): r
Score: 7
Remaining Cookies: 39

H H H H H H H H H H

H               G H

H * * * * * * *   H

H * * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * H * * H *   H

H * * * * * * *   *

H H H H H H H H H H

You lose!



Example 3: Losing the Game:

How do you want to move? (u/d/l/r): u
Score: 13
Remaining Cookies: 8

H H H H H H H H H H

H                 H

H   *             H

H   * H     H     H

H   G H     H     H

H     H   * H     H

H P * H   * H     H

H     H   * H     H

H           *     *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 13
Remaining Cookies: 7

H H H H H H H H H H

H                 H

H   *             H

H   G H     H     H

H     H     H     H

H P   H   * H     H

H   * H   * H     H

H     H   * H     H

H           *     *

H H H H H H H H H H

How do you want to move? (u/d/l/r): u
Score: 13
Remaining Cookies: 6

H H H H H H H H H H

H                 H

H   G             H

H     H     H     H

H P   H     H     H

H     H   * H     H

H   * H   * H     H

H     H   * H     H

H           *     *

H H H H H H H H H H

You lose!


What to Submit:

  • Submit your completed Player.java, Ghost.java, Spooky.java, and Game.java files (make sure your name(s) are on all files) to Canvas.
    • Note: Please do not submit Character.java
  • One partner submits Player.java, Ghost.java, Spooky.java, and Game.java and the pair programming contract.
    • The other other partner only submits the pair programming contract.

How You Will Be Graded:

  • 100 points: The assignment works as shown in the sample output plus you added Spooky to the game. All required features are implemented and implemented correctly. You correctly implemented Spooky.java, and both of the Ghosts are featured in your game
  • 80-100 points: The assignment works mostly as shown in the sample output. Most required features are implemented and implemented correctly.
  • 40-80 points: Some of the assignment works as shown in the sample output. Some required features are implemented and implemented correctly.
  • 10-40 points: Serious problems in implementation and little correspondence between sample output and what is shown. Few of the features implemented or implemented correctly.
  • 0 points: Code does not compile or outputs an error at runtime.
  • 0 points: You altered the Character.java class from the starter code.
  • 5 point deduction for missing pair programming contract.
  • 5 point deduction for code that is not properly formatted (Note: Go to Source->Format on Eclipse).
  • 5 point deduction for submitting a zip file.
  • 5 point deduction for any package statements on any file - please remove before submitting.