Game Development Reference
In-Depth Information
The Soldier Game makes use of two classes. The first is the Soldier class that represents an
individual soldier. In this case, the data model for the soldier is quite simple. The class declares
fields that represent the x- and y-location of the soldier and the speed that the soldier is running.
The Soldier class constructor sets the fields to default values. The field values are accessed or
changed by a series of standard get/set methods. The Soldier class code listing is shown next.
public class Soldier
{
private double xLocation;
private double yLocation;
private double speed;
public Soldier() {
xLocation = 0.0;
yLocation = 0.0;
speed = 0.0;
}
// These methods return the value of
// the fields declared in the class.
public double getXLocation() {
return xLocation;
}
public double getYLocation() {
return yLocation;
}
public double getSpeed() {
return speed;
}
// These methods change the value of
// the fields declared in the class.
public void setXLocation(double value) {
xLocation = value;
}
public void setYLocation(double value) {
yLocation = value;
}
public void setSpeed(double value) {
speed = value;
}
}
Search WWH ::




Custom Search