mirror of
https://github.com/lov3b/Schack.git
synced 2025-01-18 12:50:10 +01:00
simons ändringar
This commit is contained in:
parent
3eb6c5f80c
commit
fa60ce0174
BIN
Schack-master.7z
BIN
Schack-master.7z
Binary file not shown.
@ -33,7 +33,7 @@ public class Board extends JPanel implements MouseListener {
|
||||
{new Rook(false, new Point(0, 0)), null, null, null, null, null, null, new Rook(true, new Point(0, 7))},
|
||||
{new Horse(false, true, new Point(1, 0)), null, null, null, null, null, null, new Horse(true, true, new Point(1, 7))},
|
||||
{new Bishop(false, new Point(2, 0)), null, null, null, null, null, null, new Bishop(true, new Point(2, 7))},
|
||||
{new Queen(false, new Point(3, 0)), null, null, null, null, null, null, new Queen(true, new Point(3, 7))},
|
||||
{new Queen(false, new Point(3, 0)), null, null, null, new Rook(false, new Point(3, 4)), null, null, new Queen(true, new Point(3, 7))},
|
||||
{new King(false), null, null, null, null, null, null, new King(true)},
|
||||
{null, null, null, null, null, null, null, new King(false, new Point(5, 7))},
|
||||
{null, null, null, null, null, null, null, null},
|
||||
|
@ -12,8 +12,40 @@ public class Rook extends Piece {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkedHashSet<Point> validMoves(Piece[][] pieces) {
|
||||
return new LinkedHashSet<>();
|
||||
public LinkedHashSet<Point> validMoves(Piece[][] pieces) {
|
||||
LinkedHashSet<Point> movable = new LinkedHashSet<>();
|
||||
//Behöver skriva att om rookX = this.position.x så ska vi istället loopa igenom
|
||||
//int rookY = 0-this.position.y; rookY < 8-this.position.Y; rookY++
|
||||
//men jag är trög och har spenderat alldles förmycket tid på att vara trög :^)
|
||||
for (int rookX = 0-this.position.x; rookX < 8-this.position.x; rookX++) {
|
||||
|
||||
if (this.position.y == 0 && rookX == 0) {
|
||||
continue;
|
||||
}
|
||||
Point pos = new Point(this.position.x + 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) {
|
||||
continue;
|
||||
}
|
||||
movable.add(pos);
|
||||
|
||||
} 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());
|
||||
return movable;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user