mirror of
https://github.com/lov3b/Schack.git
synced 2024-11-09 22:50:15 +01:00
Små ändringar
This commit is contained in:
parent
1d86151951
commit
69f66e7542
@ -104,7 +104,7 @@ public class Board extends JPanel implements MouseListener {
|
||||
|
||||
// Ifall vi har tryckt på en pjäs och sedan ska gå dit
|
||||
if (validMovesToDraw.contains(clickedCoordinate)) {
|
||||
final Piece selectedPiece = pieces[previouslyClickedPoint.x][previouslyClickedPoint.y];
|
||||
Piece selectedPiece = pieces[previouslyClickedPoint.x][previouslyClickedPoint.y];
|
||||
if (selectedPiece == null) {
|
||||
validMovesToDraw.clear();
|
||||
return;
|
||||
@ -141,7 +141,7 @@ public class Board extends JPanel implements MouseListener {
|
||||
|
||||
// Om vi inte redan har valt en pjäs klickar vi på en pjäs
|
||||
if (!validMovesToDraw.contains(clickedCoordinate)) {
|
||||
final Piece selectedPiece = pieces[mouseCoordinateX][mouseCoordinateY];
|
||||
Piece selectedPiece = pieces[clickedCoordinate.x][clickedCoordinate.y];
|
||||
|
||||
if (selectedPiece != null && selectedPiece.isWhite() == whitesTurn) {
|
||||
validMovesToDraw.addAll(selectedPiece.validMoves(pieces, true));
|
||||
@ -161,9 +161,9 @@ public class Board extends JPanel implements MouseListener {
|
||||
* @return SCHACK, SCHACKMATT, PATT, NORMAL
|
||||
*/
|
||||
private SchackState getSchackState() {
|
||||
final ArrayList<Point> allValidMoves = getMoves(whitesTurn);
|
||||
final ArrayList<Point> opposingAttacks = getAttacks(!whitesTurn);
|
||||
final boolean weCanMove = !allValidMoves.isEmpty();
|
||||
ArrayList<Point> allValidMoves = getMoves(whitesTurn);
|
||||
ArrayList<Point> opposingAttacks = getAttacks(!whitesTurn);
|
||||
boolean weCanMove = !allValidMoves.isEmpty();
|
||||
|
||||
boolean inSchack = false;
|
||||
for (Point attack : opposingAttacks) {
|
||||
@ -189,7 +189,7 @@ public class Board extends JPanel implements MouseListener {
|
||||
}
|
||||
|
||||
private ArrayList<Point> getMoves(boolean whiteMovesAreWanted) {
|
||||
final ArrayList<Point> allValidMoves = new ArrayList<>();
|
||||
ArrayList<Point> allValidMoves = new ArrayList<>();
|
||||
for (Piece[] pieceArr : pieces) {
|
||||
for (Piece piece : pieceArr) {
|
||||
if (piece == null || whiteMovesAreWanted != piece.isWhite()) {
|
||||
@ -202,7 +202,7 @@ public class Board extends JPanel implements MouseListener {
|
||||
}
|
||||
|
||||
public ArrayList<Point> getAttacks(boolean whiteAttacksAreWanted) {
|
||||
final ArrayList attacks = new ArrayList();
|
||||
ArrayList attacks = new ArrayList();
|
||||
for (Piece[] pieceArr : pieces) {
|
||||
for (Piece piece : pieceArr) {
|
||||
if (piece == null || whiteAttacksAreWanted != piece.isWhite()) {
|
||||
|
@ -24,22 +24,22 @@ public final class King extends Piece {
|
||||
}
|
||||
|
||||
boolean[] somethingBetweenOrSchackOnTheWay = new boolean[2]; // Vänster, höger
|
||||
int left_modifier = -1, right_modifier = 1;
|
||||
for (int modifier : new int[]{left_modifier, right_modifier}) {
|
||||
int leftModifier = -1, rightModifier = 1;
|
||||
for (int modifier : new int[]{leftModifier, rightModifier}) {
|
||||
for (int loopX = this.position.x + modifier; loopX > 0 && loopX < 7; loopX += modifier) {
|
||||
if (pieces[loopX][this.position.y] != null || isInSchack(pieces, new Point(loopX, this.position.y))) {
|
||||
somethingBetweenOrSchackOnTheWay[(modifier == left_modifier) ? 0 : 1] = true;
|
||||
somethingBetweenOrSchackOnTheWay[(modifier == leftModifier) ? 0 : 1] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
left_modifier = 0;
|
||||
right_modifier = 1;
|
||||
for (int direction : new int[]{left_modifier, right_modifier}) {
|
||||
leftModifier = 0;
|
||||
rightModifier = 1;
|
||||
for (int direction : new int[]{leftModifier, rightModifier}) {
|
||||
if (!somethingBetweenOrSchackOnTheWay[direction]) {
|
||||
Piece possibleRook = pieces[direction == left_modifier ? 0 : 7][this.position.y];
|
||||
Piece possibleRook = pieces[direction == leftModifier ? 0 : 7][this.position.y];
|
||||
if (possibleRook != null && !possibleRook.isMoved()) {
|
||||
possibleCastling.add(new Point(direction == left_modifier ? 2 : 6, this.position.y));
|
||||
possibleCastling.add(new Point(direction == leftModifier ? 2 : 6, this.position.y));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -75,7 +75,6 @@ public final class King extends Piece {
|
||||
} else {
|
||||
super.move(pieces, toMove);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,8 +3,6 @@ package schack;
|
||||
import java.awt.Point;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPopupMenu;
|
||||
|
||||
public class Pawn extends Piece {
|
||||
|
||||
|
@ -17,7 +17,6 @@ public class Rook extends LongWalkers {
|
||||
pieces,
|
||||
allowedToRecurse
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user