Hello I'm a university student and I'm taking a course on programming with Greenfoot. I'm trying to write a chess game, basically while clicking "run button" and clicking a chess object, it will flip(face up if they were originally facing down) and be controlled by arrow keys. Since someone has replied similar questions, thanks to him because I borrowed his idea while writing the following program :)
public void movement() {
if (Greenfoot.isKeyDown("left")) {
moveLeft();
state=0;
}
}
private int state=0;
public void act()
{
if (Greenfoot.mouseClicked(this)) {
flip();
if (state == 0) {
if (Greenfoot.mouseClicked(this)) {
state = 1; }
}
else if (state == 1) {
movement();
}
}
}
The problem is that when I click on all the objects to flip them, and click a specific object again, the chess that satisfies the movement condition will not move left, but strangely starts to move after I clicking again. The source code seems to work well if the first "if" condition is removed. Is there any way I can select one object to control after flipping some chesses and then clicking it? Thank you very much!