mirror of
https://github.com/lov3b/Schack.git
synced 2025-01-18 21:00:11 +01:00
Breaked out code into func that is inhereited
This commit is contained in:
parent
8a72456334
commit
16afa5dc8c
@ -19,108 +19,42 @@ public class Bishop extends Piece {
|
|||||||
|
|
||||||
// Upp vänster
|
// Upp vänster
|
||||||
for (int bishopX = this.position.x - 1, bishopY = this.position.y - 1; bishopX >= 0 && bishopY >= 0; bishopX--, bishopY--) {
|
for (int bishopX = this.position.x - 1, bishopY = this.position.y - 1; bishopX >= 0 && bishopY >= 0; bishopX--, bishopY--) {
|
||||||
|
boolean shouldBreak = checkMove(bishopX, bishopY, movable, pieces);
|
||||||
Point pos = new Point(bishopX, bishopY);
|
if (shouldBreak) {
|
||||||
|
|
||||||
// Instead of checking index and null, try-catch
|
|
||||||
try {
|
|
||||||
Piece p = pieces[pos.x][pos.y];
|
|
||||||
System.out.println(p);
|
|
||||||
// If this piece is the same team as ours, skip
|
|
||||||
if (p.isWhite == this.isWhite) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
movable.add(pos);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
// This is an empty spot
|
|
||||||
movable.add(pos);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// This means that the player is at the edge
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upp höger
|
// Upp höger
|
||||||
for (int bishopX = this.position.x + 1, bishopY = this.position.y - 1; bishopX <= 7 && bishopY >= 0; bishopX++, bishopY--) {
|
for (int bishopX = this.position.x + 1, bishopY = this.position.y - 1; bishopX <= 7 && bishopY >= 0; bishopX++, bishopY--) {
|
||||||
|
boolean shouldBreak = checkMove(bishopX, bishopY, movable, pieces);
|
||||||
Point pos = new Point(bishopX, bishopY);
|
if (shouldBreak) {
|
||||||
|
|
||||||
// Instead of checking index and null, try-catch
|
|
||||||
try {
|
|
||||||
Piece p = pieces[pos.x][pos.y];
|
|
||||||
System.out.println(p);
|
|
||||||
// If this piece is the same team as ours, skip
|
|
||||||
if (p.isWhite == this.isWhite) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
movable.add(pos);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
// This is an empty spot
|
|
||||||
movable.add(pos);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// This means that the player is at the edge
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// Ner höger
|
// Ner höger
|
||||||
for (int bishopX = this.position.x + 1, bishopY = this.position.y + 1; bishopX <= 7 && bishopY <= 7; bishopX++, bishopY++) {
|
for (int bishopX = this.position.x + 1, bishopY = this.position.y + 1; bishopX <= 7 && bishopY <= 7; bishopX++, bishopY++) {
|
||||||
|
boolean shouldBreak = checkMove(bishopX, bishopY, movable, pieces);
|
||||||
Point pos = new Point(bishopX, bishopY);
|
if (shouldBreak) {
|
||||||
|
|
||||||
// Instead of checking index and null, try-catch
|
|
||||||
try {
|
|
||||||
Piece p = pieces[pos.x][pos.y];
|
|
||||||
System.out.println(p);
|
|
||||||
// If this piece is the same team as ours, skip
|
|
||||||
if (p.isWhite == this.isWhite) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
movable.add(pos);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
// This is an empty spot
|
|
||||||
movable.add(pos);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// This means that the player is at the edge
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// Ner vänster
|
// Ner vänster
|
||||||
for (int bishopX = this.position.x - 1, bishopY = this.position.y + 1; bishopX >= 0 && bishopY <= 7; bishopX--, bishopY++) {
|
for (int bishopX = this.position.x - 1, bishopY = this.position.y + 1; bishopX >= 0 && bishopY <= 7; bishopX--, bishopY++) {
|
||||||
|
boolean shouldBreak = checkMove(bishopX, bishopY, movable, pieces);
|
||||||
Point pos = new Point(bishopX, bishopY);
|
if (shouldBreak) {
|
||||||
|
|
||||||
// Instead of checking index and null, try-catch
|
|
||||||
try {
|
|
||||||
Piece p = pieces[pos.x][pos.y];
|
|
||||||
System.out.println(p);
|
|
||||||
// If this piece is the same team as ours, skip
|
|
||||||
if (p.isWhite == this.isWhite) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
movable.add(pos);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
// This is an empty spot
|
|
||||||
movable.add(pos);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// This means that the player is at the edge
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return movable;
|
return movable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Bishop{" + "position=" + position + ", isWhite=" + isWhite + '}';
|
return "Bishop{" + "position=" + position + ", isWhite=" + isWhite + '}';
|
||||||
|
@ -51,21 +51,41 @@ public abstract class Piece extends Component {
|
|||||||
public void move(Piece[][] pieces, Point toMove, Point selected) {
|
public void move(Piece[][] pieces, Point toMove, Point selected) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
System.out.println("toMove: " + toMove);
|
|
||||||
|
|
||||||
pieces[toMove.x][toMove.y] = this; //new Rook(true,new Point(toMove));
|
pieces[toMove.x][toMove.y] = this; //new Rook(true,new Point(toMove));
|
||||||
pieces[selected.x][selected.y] = null;
|
pieces[selected.x][selected.y] = null;
|
||||||
// varför funkar det nu? det borde inte funka nu.
|
|
||||||
System.out.println("equals: " + selected.equals(this.position));
|
|
||||||
|
|
||||||
this.position = new Point(toMove);
|
this.position = new Point(toMove);
|
||||||
Board.printPieces(pieces);
|
Board.printPieces(pieces);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("jmgfmhyfhm");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean checkMove(int x, int y, LinkedHashSet movable, Piece[][] pieces) {
|
||||||
|
Point pos = new Point(x, y);
|
||||||
|
|
||||||
|
// Instead of checking index and null, try-catch
|
||||||
|
try {
|
||||||
|
Piece p = pieces[pos.x][pos.y];
|
||||||
|
System.out.println(p);
|
||||||
|
// If this piece is the same team as ours, skip
|
||||||
|
if (p.isWhite == this.isWhite) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
movable.add(pos);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} catch (NullPointerException npe) {
|
||||||
|
// This is an empty spot
|
||||||
|
movable.add(pos);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// This means that the player is at the edge
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Piece{" + "position=" + position + ", isWhite=" + isWhite + '}';
|
return "Piece{" + "position=" + position + ", isWhite=" + isWhite + '}';
|
||||||
|
@ -9,215 +9,77 @@ public class Queen extends Piece {
|
|||||||
public Queen(boolean isWhite, Point point) throws IOException {
|
public Queen(boolean isWhite, Point point) throws IOException {
|
||||||
super(isWhite, point);
|
super(isWhite, point);
|
||||||
setPieceIcon("Queen");
|
setPieceIcon("Queen");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LinkedHashSet<Point> validMoves(Piece[][] pieces) {
|
public LinkedHashSet<Point> validMoves(Piece[][] pieces) {
|
||||||
LinkedHashSet<Point> movable = new LinkedHashSet<>();
|
LinkedHashSet<Point> movable = new LinkedHashSet<>();
|
||||||
|
|
||||||
// Upp vänster
|
// Vänster
|
||||||
for (int bishopX = this.position.x - 1, bishopY = this.position.y - 1; bishopX >= 0 && bishopY >= 0; bishopX--, bishopY--) {
|
for (int rookX = this.position.x - 1; rookX >= 0; rookX--) {
|
||||||
|
boolean shouldBreak = checkMove(rookX, this.position.y, movable, pieces);
|
||||||
Point pos = new Point(bishopX, bishopY);
|
if (shouldBreak) {
|
||||||
|
|
||||||
// Instead of checking index and null, try-catch
|
|
||||||
try {
|
|
||||||
Piece p = pieces[pos.x][pos.y];
|
|
||||||
System.out.println(p);
|
|
||||||
// If this piece is the same team as ours, skip
|
|
||||||
if (p.isWhite == this.isWhite) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
movable.add(pos);
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} catch (NullPointerException npe) {
|
// Höger
|
||||||
// This is an empty spot
|
for (int rookX = this.position.x + 1; rookX <= 7; rookX++) {
|
||||||
movable.add(pos);
|
boolean shouldBreak = checkMove(rookX, this.position.y, movable, pieces);
|
||||||
} catch (Exception e) {
|
if (shouldBreak) {
|
||||||
// This means that the player is at the edge
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ner
|
||||||
|
for (int rookY = this.position.y + 1; rookY <= 7; rookY++) {
|
||||||
|
boolean shouldBreak = checkMove(this.position.x, rookY, movable, pieces);
|
||||||
|
if (shouldBreak) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Upp
|
||||||
|
for (int rookY = this.position.y - 1; rookY >= 0; rookY--) {
|
||||||
|
boolean shouldBreak = checkMove(this.position.x, rookY, movable, pieces);
|
||||||
|
if (shouldBreak) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Upp vänster
|
||||||
|
for (int bishopX = this.position.x - 1, bishopY = this.position.y - 1; bishopX >= 0 && bishopY >= 0; bishopX--, bishopY--) {
|
||||||
|
boolean shouldBreak = checkMove(bishopX, bishopY, movable, pieces);
|
||||||
|
if (shouldBreak) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upp höger
|
// Upp höger
|
||||||
for (int bishopX = this.position.x + 1, bishopY = this.position.y - 1; bishopX <= 7 && bishopY >= 0; bishopX++, bishopY--) {
|
for (int bishopX = this.position.x + 1, bishopY = this.position.y - 1; bishopX <= 7 && bishopY >= 0; bishopX++, bishopY--) {
|
||||||
|
boolean shouldBreak = checkMove(bishopX, bishopY, movable, pieces);
|
||||||
Point pos = new Point(bishopX, bishopY);
|
if (shouldBreak) {
|
||||||
|
|
||||||
// Instead of checking index and null, try-catch
|
|
||||||
try {
|
|
||||||
Piece p = pieces[pos.x][pos.y];
|
|
||||||
System.out.println(p);
|
|
||||||
// If this piece is the same team as ours, skip
|
|
||||||
if (p.isWhite == this.isWhite) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
movable.add(pos);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
// This is an empty spot
|
|
||||||
movable.add(pos);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// This means that the player is at the edge
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// Ner höger
|
// Ner höger
|
||||||
for (int bishopX = this.position.x + 1, bishopY = this.position.y + 1; bishopX <= 7 && bishopY <= 7; bishopX++, bishopY++) {
|
for (int bishopX = this.position.x + 1, bishopY = this.position.y + 1; bishopX <= 7 && bishopY <= 7; bishopX++, bishopY++) {
|
||||||
|
boolean shouldBreak = checkMove(bishopX, bishopY, movable, pieces);
|
||||||
Point pos = new Point(bishopX, bishopY);
|
if (shouldBreak) {
|
||||||
|
|
||||||
// Instead of checking index and null, try-catch
|
|
||||||
try {
|
|
||||||
Piece p = pieces[pos.x][pos.y];
|
|
||||||
System.out.println(p);
|
|
||||||
// If this piece is the same team as ours, skip
|
|
||||||
if (p.isWhite == this.isWhite) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
movable.add(pos);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
// This is an empty spot
|
|
||||||
movable.add(pos);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// This means that the player is at the edge
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// Ner vänster
|
// Ner vänster
|
||||||
for (int bishopX = this.position.x - 1, bishopY = this.position.y + 1; bishopX >= 0 && bishopY <= 7; bishopX--, bishopY++) {
|
for (int bishopX = this.position.x - 1, bishopY = this.position.y + 1; bishopX >= 0 && bishopY <= 7; bishopX--, bishopY++) {
|
||||||
|
boolean shouldBreak = checkMove(bishopX, bishopY, movable, pieces);
|
||||||
Point pos = new Point(bishopX, bishopY);
|
if (shouldBreak) {
|
||||||
|
|
||||||
// Instead of checking index and null, try-catch
|
|
||||||
try {
|
|
||||||
Piece p = pieces[pos.x][pos.y];
|
|
||||||
System.out.println(p);
|
|
||||||
// If this piece is the same team as ours, skip
|
|
||||||
if (p.isWhite == this.isWhite) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
movable.add(pos);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
// This is an empty spot
|
|
||||||
movable.add(pos);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// This means that the player is at the edge
|
|
||||||
}
|
|
||||||
|
|
||||||
}// Vänster
|
|
||||||
for (int rookX = this.position.x - 1; rookX >= 0; rookX--) {
|
|
||||||
|
|
||||||
Point pos = new Point(rookX, this.position.y);
|
|
||||||
|
|
||||||
// Instead of checking index and null, try-catch
|
|
||||||
try {
|
|
||||||
Piece p = pieces[pos.x][pos.y];
|
|
||||||
System.out.println(p);
|
|
||||||
// If this piece is the same team as ours, skip
|
|
||||||
if (p.isWhite == this.isWhite) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
movable.add(pos);
|
|
||||||
break;
|
|
||||||
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
// This is an empty spot
|
|
||||||
movable.add(pos);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// This means that the player is at the edge
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Höger
|
|
||||||
for (int rookX = this.position.x + 1; rookX <= 7; rookX++) {
|
|
||||||
|
|
||||||
Point pos = new Point(rookX, this.position.y);
|
|
||||||
|
|
||||||
// Instead of checking index and null, try-catch
|
|
||||||
try {
|
|
||||||
Piece p = pieces[pos.x][pos.y];
|
|
||||||
System.out.println(p);
|
|
||||||
// If this piece is the same team as ours, skip
|
|
||||||
if (p.isWhite == this.isWhite) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
movable.add(pos);
|
|
||||||
break;
|
|
||||||
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
// This is an empty spot
|
|
||||||
movable.add(pos);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// This means that the player is at the edge
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ner
|
|
||||||
for (int rookY = this.position.y + 1; rookY <= 7; rookY++) {
|
|
||||||
|
|
||||||
Point pos = new Point(this.position.x, rookY);
|
|
||||||
|
|
||||||
// Instead of checking index and null, try-catch
|
|
||||||
try {
|
|
||||||
Piece p = pieces[pos.x][pos.y];
|
|
||||||
System.out.println(p);
|
|
||||||
// If this piece is the same team as ours, skip
|
|
||||||
if (p.isWhite == this.isWhite) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
movable.add(pos);
|
|
||||||
break;
|
|
||||||
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
// This is an empty spot
|
|
||||||
movable.add(pos);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// This means that the player is at the edge
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Upp
|
|
||||||
for (int rookY = this.position.y - 1; rookY >= 0; rookY--) {
|
|
||||||
|
|
||||||
Point pos = new Point(this.position.x, rookY);
|
|
||||||
|
|
||||||
// Instead of checking index and null, try-catch
|
|
||||||
try {
|
|
||||||
Piece p = pieces[pos.x][pos.y];
|
|
||||||
System.out.println(p);
|
|
||||||
// If this piece is the same team as ours, skip
|
|
||||||
if (p.isWhite == this.isWhite) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
movable.add(pos);
|
|
||||||
break;
|
|
||||||
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
// This is an empty spot
|
|
||||||
movable.add(pos);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// This means that the player is at the edge
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return movable;
|
return movable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,115 +20,41 @@ public class Rook extends Piece {
|
|||||||
//men jag är trög och har spenderat alldles förmycket tid på att vara trög :^)
|
//men jag är trög och har spenderat alldles förmycket tid på att vara trög :^)
|
||||||
|
|
||||||
// Vänster
|
// Vänster
|
||||||
for (int rookX = this.position.x-1; rookX >= 0; rookX--) {
|
for (int rookX = this.position.x - 1; rookX >= 0; rookX--) {
|
||||||
|
boolean shouldBreak = checkMove(rookX, this.position.y, movable, pieces);
|
||||||
Point pos = new Point(rookX,this.position.y);
|
if (shouldBreak) {
|
||||||
|
|
||||||
|
|
||||||
// Instead of checking index and null, try-catch
|
|
||||||
try {
|
|
||||||
Piece p = pieces[pos.x][pos.y];
|
|
||||||
System.out.println(p);
|
|
||||||
// If this piece is the same team as ours, skip
|
|
||||||
if (p.isWhite == this.isWhite) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
movable.add(pos);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
// This is an empty spot
|
|
||||||
movable.add(pos);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// This means that the player is at the edge
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Höger
|
// Höger
|
||||||
for (int rookX = this.position.x+1; rookX <= 7; rookX++) {
|
for (int rookX = this.position.x + 1; rookX <= 7; rookX++) {
|
||||||
|
boolean shouldBreak = checkMove(rookX, this.position.y, movable, pieces);
|
||||||
Point pos = new Point(rookX,this.position.y);
|
if (shouldBreak) {
|
||||||
|
|
||||||
|
|
||||||
// Instead of checking index and null, try-catch
|
|
||||||
try {
|
|
||||||
Piece p = pieces[pos.x][pos.y];
|
|
||||||
System.out.println(p);
|
|
||||||
// If this piece is the same team as ours, skip
|
|
||||||
if (p.isWhite == this.isWhite) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
movable.add(pos);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
// This is an empty spot
|
|
||||||
movable.add(pos);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// This means that the player is at the edge
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ner
|
// Ner
|
||||||
for (int rookY = this.position.y+1; rookY <= 7; rookY++) {
|
for (int rookY = this.position.y + 1; rookY <= 7; rookY++) {
|
||||||
|
boolean shouldBreak = checkMove(this.position.x, rookY, movable, pieces);
|
||||||
Point pos = new Point(this.position.x,rookY);
|
if (shouldBreak) {
|
||||||
|
|
||||||
|
|
||||||
// Instead of checking index and null, try-catch
|
|
||||||
try {
|
|
||||||
Piece p = pieces[pos.x][pos.y];
|
|
||||||
System.out.println(p);
|
|
||||||
// If this piece is the same team as ours, skip
|
|
||||||
if (p.isWhite == this.isWhite) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
movable.add(pos);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
// This is an empty spot
|
|
||||||
movable.add(pos);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// This means that the player is at the edge
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upp
|
// Upp
|
||||||
for (int rookY = this.position.y-1; rookY >= 0; rookY--) {
|
for (int rookY = this.position.y - 1; rookY >= 0; rookY--) {
|
||||||
|
boolean shouldBreak = checkMove(this.position.x, rookY, movable, pieces);
|
||||||
Point pos = new Point(this.position.x,rookY);
|
if (shouldBreak) {
|
||||||
|
|
||||||
|
|
||||||
// Instead of checking index and null, try-catch
|
|
||||||
try {
|
|
||||||
Piece p = pieces[pos.x][pos.y];
|
|
||||||
System.out.println(p);
|
|
||||||
// If this piece is the same team as ours, skip
|
|
||||||
if (p.isWhite == this.isWhite) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
movable.add(pos);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
// This is an empty spot
|
|
||||||
movable.add(pos);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// This means that the player is at the edge
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
System.out.println("Len of movable: " + movable.size());
|
System.out.println("Len of movable: " + movable.size());
|
||||||
return movable;
|
return movable;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user