mirror of
https://github.com/lov3b/Schack.git
synced 2025-01-18 21:00:11 +01:00
små Nicklas ändringar
This commit is contained in:
parent
700647f7c2
commit
e545ca7902
@ -22,7 +22,7 @@ public class Board extends JPanel implements MouseListener {
|
||||
private ArrayList<Point> validDebugAttacksToDraw = new ArrayList<>();
|
||||
private Point selectedPiece = new Point();
|
||||
private Color moveableColor = new Color(255, 191, 0);
|
||||
public static boolean turn = true;
|
||||
public static boolean whiteToMove = true;
|
||||
public boolean developerMode = false;
|
||||
|
||||
public Board() throws IOException {
|
||||
@ -120,12 +120,13 @@ public class Board extends JPanel implements MouseListener {
|
||||
try {
|
||||
Piece p = pieces[selectedPiece.x][selectedPiece.y];
|
||||
p.move(pieces, clicked);
|
||||
turn = !turn;
|
||||
whiteToMove = !whiteToMove;
|
||||
|
||||
ArrayList<Point> allValidMoves = new ArrayList<>();
|
||||
for (Piece[] pieceArr : pieces) {
|
||||
for (Piece piece : pieceArr) {
|
||||
if (piece == null || turn != piece.white) {
|
||||
// || pieces[currentPlayer].contains(piece)
|
||||
if (piece == null || whiteToMove != piece.isWhite()) {
|
||||
continue;
|
||||
}
|
||||
// Kolla ifall vi är samma färg som får röra sig
|
||||
@ -134,7 +135,7 @@ public class Board extends JPanel implements MouseListener {
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<Point> opposingAttacks = checkAttacks(!turn);
|
||||
ArrayList<Point> opposingAttacks = checkAttacks(!whiteToMove);
|
||||
|
||||
// opposingAttacks.removeAll(allValidMoves);
|
||||
|
||||
@ -180,8 +181,8 @@ public class Board extends JPanel implements MouseListener {
|
||||
Piece selectedPiece = pieces[mouseCoordinateX][mouseCoordinateY];
|
||||
|
||||
// Kolla endast ifall vi kan röra på pjäsen om det är samma färg som den tur vi är på
|
||||
if (selectedPiece.isWhite() == turn || developerMode) {
|
||||
ArrayList<Point> attacks = checkAttacks(turn);
|
||||
if (selectedPiece.isWhite() == whiteToMove || developerMode) {
|
||||
ArrayList<Point> attacks = checkAttacks(whiteToMove);
|
||||
|
||||
ArrayList<Point> validMoves = selectedPiece.validMoves(pieces, true);
|
||||
// Kolla ifall vi kan röra oss
|
||||
@ -191,12 +192,12 @@ public class Board extends JPanel implements MouseListener {
|
||||
ArrayList<Point> allValidMoves = new ArrayList<>();
|
||||
for (Piece[] pieceArr : pieces) {
|
||||
for (Piece piece : pieceArr) {
|
||||
if (piece == null || turn != piece.white) {
|
||||
if (piece == null || whiteToMove != piece.isWhite) {
|
||||
continue;
|
||||
}
|
||||
// Kolla ifall vi är samma färg som får röra sig
|
||||
// Ifall en pjäs får röra sig sätt weCanMove till sant och sluta
|
||||
allValidMoves.addAll(piece.validMoves(pieces, turn));
|
||||
allValidMoves.addAll(piece.validMoves(pieces, whiteToMove));
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,7 +226,7 @@ public class Board extends JPanel implements MouseListener {
|
||||
for (Piece[] pieceArr : pieces) {
|
||||
for (Piece piece : pieceArr) {
|
||||
// Ifall det är tomrum skippa
|
||||
if (piece == null || preferedColor != piece.white) {
|
||||
if (piece == null || preferedColor != piece.isWhite) {
|
||||
continue;
|
||||
}
|
||||
// Lägg till alla attacker för respektive färg
|
||||
|
@ -17,12 +17,12 @@ public class Pawn extends PieceKnownIfMoved {
|
||||
// Kolla ifall vi kan ta någon
|
||||
for (int pawnX : new int[]{-1, 1}) {
|
||||
// Position vi kollar just nu, snett upp åt höger & vänster
|
||||
Point pos = new Point(this.position.x + pawnX, this.position.y + (this.white ? -1 : 1));
|
||||
Point pos = new Point(this.position.x + pawnX, this.position.y + (this.isWhite ? -1 : 1));
|
||||
if (pos.x < 0 || pos.x > 7 || pos.y < 0 || pos.y > 7) {
|
||||
continue;
|
||||
}
|
||||
Piece piece = pieces[pos.x][pos.y];
|
||||
if (piece == null || piece.white != piece.white) {
|
||||
if (piece == null || piece.isWhite != piece.isWhite) {
|
||||
movable.add(pos);
|
||||
}
|
||||
}
|
||||
@ -39,7 +39,7 @@ public class Pawn extends PieceKnownIfMoved {
|
||||
|
||||
// Kolla om man kan gå rakt frak
|
||||
for (int pawnDY = 1; pawnDY <= upTo; pawnDY++) {
|
||||
Point pos = new Point(this.position.x, this.position.y + (this.white ? -pawnDY : pawnDY));
|
||||
Point pos = new Point(this.position.x, this.position.y + (this.isWhite ? -pawnDY : pawnDY));
|
||||
boolean shouldBreak = addMovesIfCan(pos, movable, pieces, isSelected);
|
||||
if (shouldBreak) {
|
||||
System.out.println("should brkje!");
|
||||
@ -50,7 +50,7 @@ public class Pawn extends PieceKnownIfMoved {
|
||||
// Kolla ifall vi kan ta någon
|
||||
for (int pawnX : new int[]{-1, 1}) {
|
||||
// Position vi kollar just nu, snett upp åt höger & vänster
|
||||
Point pos = new Point(this.position.x + pawnX, this.position.y + (this.white ? -1 : 1));
|
||||
Point pos = new Point(this.position.x + pawnX, this.position.y + (this.isWhite ? -1 : 1));
|
||||
addAttackMovesIfCan(pos, movable, pieces);
|
||||
}
|
||||
System.out.println("len of movable: " + movable.size());
|
||||
|
@ -19,7 +19,7 @@ public abstract class Piece {
|
||||
/**
|
||||
* Sant ifall pjäsens färg är vit, falskt ifall den är svart
|
||||
*/
|
||||
public boolean white;
|
||||
public boolean isWhite;
|
||||
/**
|
||||
* SPECIAL RULÖES APPLY TO THE KING, (ITS GOOD TO BE THE KING:)
|
||||
*/
|
||||
@ -30,13 +30,13 @@ public abstract class Piece {
|
||||
protected BufferedImage icon;
|
||||
|
||||
public Piece(boolean white, Point startingPosition) throws IOException {
|
||||
this.white = white;
|
||||
this.isWhite = white;
|
||||
this.position = startingPosition;
|
||||
setPieceIcon();
|
||||
}
|
||||
|
||||
public Piece(boolean white) {
|
||||
this.white = white;
|
||||
this.isWhite = white;
|
||||
}
|
||||
|
||||
public void setPosition(Point p) {
|
||||
@ -51,7 +51,7 @@ public abstract class Piece {
|
||||
*/
|
||||
protected void setPieceIcon() throws IOException {
|
||||
String className = this.getClass().getSimpleName();
|
||||
String colorName = white ? "White" : "Black";
|
||||
String colorName = isWhite ? "White" : "Black";
|
||||
String fileName = colorName + className + ".png";
|
||||
InputStream is = getClass().getResourceAsStream("/img/" + fileName);
|
||||
icon = ImageIO.read(is);
|
||||
@ -134,7 +134,7 @@ public abstract class Piece {
|
||||
* längre Ifall det är samma färg som oss betyder det att vi inte kan
|
||||
* lägga till den
|
||||
*/
|
||||
if (pieceToCheck.isWhite() != this.white) {
|
||||
if (pieceToCheck.isWhite() != this.isWhite) {
|
||||
/**
|
||||
* Detta betyder att det är en motsatts pjäs här, vi kan ta men inte
|
||||
* gå längre
|
||||
@ -214,12 +214,12 @@ public abstract class Piece {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName() + "{" + "position=" + position + ", isWhite=" + white + '}';
|
||||
return this.getClass().getSimpleName() + "{" + "position=" + position + ", isWhite=" + isWhite + '}';
|
||||
// return "Piece{" + "position=" + position + ", isWhite=" + white + '}';
|
||||
}
|
||||
|
||||
public boolean isWhite() {
|
||||
return white;
|
||||
return isWhite;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user