/** * The PacMan class contains code (or, at least, it *will* contain code) that * draws a simple scene from Pac-Man using the same techniques that we used in * class to draw the "face". You'll also add a method for changing the colors * of the objects, and moving the group of objects around the screen. * * @author David Chiu, Brad Richards and [YOUR NAME HERE] * @version 1.1 */ public class PacMan { // Fields to hold the objects. They should really be private too... Circle body; Circle eye; Circle powerball; Triangle mouth; /** * Constructor for objects of class PacMan. You'll copy the statements * that BlueJ prints out as you create the scene and past them here. */ public PacMan() { // Create all of the objects we'll need and store them in instance variables body = new Circle(); eye = new Circle(); powerball = new Circle(); mouth = new Triangle(); // Make all four objects visible body.makeVisible(); eye.makeVisible(); mouth.makeVisible(); powerball.makeVisible(); // Set up the body body.changeColor("yellow"); body.changeSize(75); body.moveUp(); body.moveUp(); // Get the eye set up eye.changeColor("black"); eye.changeSize(5); eye.slowMoveHorizontal(58); // Put the mouth in the right place mouth.changeSize(75,75); mouth.moveHorizontal(-150); mouth.moveVertical(-85); mouth.changeColor("white"); // Finally, set up the "powerball" powerball.changeColor("magenta"); powerball.changeSize(20); powerball.slowMoveHorizontal(30); powerball.moveDown(); powerball.moveDown(); } /** * This is the start of a method that would turn our lovely picture * to black and white after it's been drawn. We can only make it * work if the variables holding the objects (the circles and triangle) * are declared as fields instead of local variables in the constructor. * Then you could use changeColor() to turn some of them black. */ public void makeBlackAndWhite() { // Make the body black body.changeColor("black"); // Make the eye white eye.changeColor("white"); // Make the mouth white mouth.changeColor("white"); // Make the powerball black powerball.changeColor("black"); } /** * This is the start of a method that would hide our PacMan by making * the objects invisible. */ public void makeInvisible() { // Make the body invisible body.makeInvisible(); // Make the eye invisible eye.makeInvisible(); // Make the mouth invisible mouth.makeInvisible(); // Make the powerball invisible powerball.makeInvisible(); } /** * Here's a method that uses a *parameter*: It takes an input from the * caller, stores it in a local variable called distance, and then the * body of the method can refer to that variable when it wants to know * how far to move. */ public void moveHorizontal(int distance) { body.moveHorizontal(distance); eye.moveHorizontal(distance); mouth.moveHorizontal(distance); powerball.moveHorizontal(distance); } }