I'm trying to create a class that calculates for the next possible coordinate for a Bishop Piece for my chess program and I encountered this problem.
I used a JOptionPane to test for the results and I can't understand how it got that result.
The first JOptionPane shows false because I used the method for the first time.
FALSE MEANS THAT THE LIST IS NOT EMPTY
On the second and third JOptionPane I was expecting to see a false but it showed true.
Can someone explain to me how it became true.
I'm new to java but i have some experience in C#
import java.awt.Point;
import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Movement {
public final static int NORTH=-1;
public final static int SOUTH=1;
public final static int EAST=1;
public final static int WEST=-1;
public ArrayList<Point> getDiagonalPoints(Point origin){
ArrayList<Point> list =new ArrayList<Point>();
JOptionPane.showMessageDialog(null,getPointsOf(WEST,NORTH,origin).isEmpty()); //OUTPUTS FALSE
list.addAll(getPointsOf(WEST,NORTH,origin));
JOptionPane.showMessageDialog(null,getPointsOf(WEST,NORTH,origin).isEmpty());
//OUTPUTS TRUE
list.addAll(getPointsOf(WEST,SOUTH,origin));
JOptionPane.showMessageDialog(null,getPointsOf(WEST,SOUTH,origin).isEmpty());
JOptionPane.showMessageDialog(null,list.size());
//list.addAll(getPointsOf(EAST,SOUTH,origin));
//list.addAll(getPointsOf(EAST,NORTH,origin));
return list;
}
public ArrayList<Point> getPointsOf(int x,int y,Point origin){
ArrayList<Point> options =new ArrayList<Point>();
while(origin.x<8&&origin.x>=0&&origin.y<8&&origin.y>=0){
options.add(new Point(origin.x,origin.y));
origin.x+=x;
origin.y+=y;
}
return options;
}
}