Hi, I wanted to program a board game with greenfoot and already finished one project. But it was coded very poorly and now I wanted to try the same game again in a better way.
In the game, there are 16 figures and I wanted to save them in an array:
To give out the object of the array, I wrote this method (also in the class "Figur"):
I want to use this method in the over class "Spiel" but it says that it cant find the method.
(I want to use it like this: "getFigur(5).command;")
Any ideas how this could happen? Or maybe a better suggestion for the management of the figures?
public class Figur extends Spiel
{
private int figurID;
private String color;
private Figur[] figuren = new Figur[16];
public void act(){
//Add the figures to the array
for(int i = 0; i < 4; i++){
figuren[i] = new Figur( i, "Gruen");
}
for(int j = 4; j < 8; j++){
figuren[j] = new Figur(j, "Rot");
}
for(int k = 8; k < 12; k++){
figuren[k] = new Figur(k, "Blau");
}
for(int l = 12; l < 16; l++){
figuren[l] = new Figur(l, "Gelb");
}
}
/**
* Constructor of Figur
* @param int yfigurID, String ycolor
*/
public Figur(int yfigurID, String ycolor){
this.figurID = yfigurID;
this.color = ycolor;
}
public Figur getFigur(int p){
return figuren[p];
}
