I'm relatively new to programming and I'm trying to make a 2-player chess game, which, of course, needs turns. I have a Piece class which has six sub-classes (one for each piece). In the piece class, I have a move method, which is then called from each piece in their act methods, and the move method has 2 parameter, one for which piece it is, and the other for which color it is (b or w). The move method moves the pieces if they are dragged, and are supposed to set up turns, but the problem is that my turn variable only changes for individual pieces, so I can move each white piece only once and cannot move any black pieces. This is my code:
}
Any ideas?
public class Piece extends Actor
{
private int turn = 0;
private boolean moved = false;
public void move(Piece p, String color)
{
if (getTurn() == 0)
{
if (Greenfoot.mouseDragged(p) && color.equals("w"))
{
MouseInfo mouse = Greenfoot.getMouseInfo();
p.setLocation(mouse.getX(), mouse.getY());
moved = true;
}
if(Greenfoot.mouseDragEnded(p) && moved == true)
{
Actor a = getOneIntersectingObject(Piece.class);
if (a != null)
{
World world = getWorld();
world.removeObject(a);
}
moved = false;
setTurn(1);
}
}
if (getTurn() == 1)
{
if (Greenfoot.mouseDragged(p) && color.equals("b"))
{
MouseInfo mouse = Greenfoot.getMouseInfo();
p.setLocation(mouse.getX(), mouse.getY());
moved = true;
}
if(Greenfoot.mouseDragEnded(p) && moved == true)
{
Actor a = getOneIntersectingObject(Piece.class);
if (a != null)
{
World world = getWorld();
world.removeObject(a);
}
moved = false;
setTurn(0);
}
}
}
public int getTurn()
{
return turn;
}
public void setTurn(int t)
{
turn = t;
}
}

