Hi, im doing an assignment for uni and im currently stuck on my eat() method. The assignment is to program a pacman style game.
The specific step im stuck on is:
**•The eat() method takes an item and makes it disappear. This method also adds an amount N to the player's points, where N = 1000 - distanceTravelled, and N must be no smaller than 100. After eating, this method should print out the message "yum".**
This is my coding so far:
/**
* Write a description of class Player here.
*
* @Author: Ruth Duruchukwu
* @version 1.0
*/
public class Player
{
// instance variables
private World world;
private Body body;
private
String name;
private int points, distanceTravelled;
private boolean alive;
public static final int RADIUS = 20;
/**
* Constructor for objects of class Player
*/
public Player()
{
body = new Body();
alive = true;
}
//Setter
public void setWorld(World newWorld)
{
world = newWorld;
}
//Getter
public World getWorld()
{
return world;
}
//Setter
public void setBody(Body newBody)
{
body = newBody;
}
//Getter
public Body getBody()
{
return body;
}
//Accessor
public Player (String newName)
{
name = newName;
}
//Setter
public void
setName(String newName)
{
name = newName;
}
//Getter
public String getName()
{
return name;
}
//Setter
public void setPoints(int newPoints)
{
points = newPoints;
}
//Getter
public int getPoints()
{
return points;
}
//Setter
public void setDistanceTravelled(int newDistanceTravelled)
{
distanceTravelled = newDistanceTravelled;
}
//Getter
public int getDistanceTravelled()
{
return distanceTravelled;
}
//Getter
public boolean isAlive()
{
return alive;
}
//Setter
public void setAlive(boolean newAlive)
{
alive = newAlive;
}
//Methods
public void setInitialState(int x, int y, int radius)
{
body.setX(x);
body.setY(y);
body.setRadius(radius);
}
public void moveHorizontal(int distance)
{
body.move(distance,0);
distanceTravelled += Math.abs(distance);
System.out.println("wagga");
}
public void moveVertical(int distance)
{
body.move(0,distance);
distanceTravelled += Math.abs(distance);
System.out.println("wagga");
}
//system
}
}
im also using Bluej as my software, if that helps