Trying to get you going without writing the whole thing for you:
For point 1, the goal is to initialize internal variables (that are already defined in the class) according to the parameters passed to the constructor:
public AbstractGamePiece(String name, String abbreviation, int playerType) {
myName = name;
// and so on
}
Then, a “getter” type function returns a value available in the current object, like this
public int getPlayerType() {
return myPlayerType;
}
Setters are the inverse, they set internal variables based on parameters passed:
public void setPosition(int col, int row) {
myRow = row;
myCol = col;
}
And so on.
Then, according to the instructions, you’ll have to use this abstract class as the base for several concrete classes:
public class Henchman extends AbstractGamePiece {
// the constructor - not sure what exactly should be passed in here
// but you get the idea - this constructor doesn't have to have the
// same "signature" as super's
public Henchman(String name) {
super(name, "hm", PLAYER_OUTLAWS);
}
// an an implementation of abstract method hasEscaped
@Override
public boolean hasEscaped() {
return false; // as per the instructions
}
}
A toString method returns a specific description of the current object as a (human-readable) string, and it can e.g be used to print a human-readable list of current pieces to help analyze/debug the game once you start developing the game engine. As the instructions say, what it does is up to you, make it return all interesting and identifying info. To get you started, for Henchman:
public toString() {
String.format("Henchman name=%s team=%d escaped=%",myName,myTeam,hasEscaped());
}
But there are 1000’s of variations on this that would be equally suitable.
This should get you started, do not hesitate to create a new question if you get stuck later on. Good luck!
2
solved Setting up Java game pieces [closed]