mirror of
https://github.com/lov3b/Schack.git
synced 2025-01-18 04:40:11 +01:00
Ta bort blanksteg och annan formatering
This commit is contained in:
parent
ab6f9980e5
commit
e9a5416d1f
@ -26,10 +26,8 @@ public class Board extends JPanel implements MouseListener {
|
||||
private boolean whitesTurn = true;
|
||||
|
||||
public Board() throws IOException {
|
||||
|
||||
this.pieces = getPieces();
|
||||
setPreferredSize(new Dimension(800, 800));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,7 +42,6 @@ public class Board extends JPanel implements MouseListener {
|
||||
}
|
||||
|
||||
private Piece[][] getPieces() throws IOException {
|
||||
|
||||
Piece[][] piecesRet = {
|
||||
{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))},
|
||||
@ -85,11 +82,9 @@ public class Board extends JPanel implements MouseListener {
|
||||
Arrays.stream(pieces).forEach(pieceArr -> Arrays.stream(pieceArr)
|
||||
.filter(piece -> piece != null)
|
||||
.forEach(piece -> piece.draw(g2)));
|
||||
|
||||
}
|
||||
|
||||
private void drawSquares(Graphics2D g2) {
|
||||
|
||||
g2.setBackground(Color.WHITE);
|
||||
g2.setColor(Color.DARK_GRAY);
|
||||
|
||||
@ -106,10 +101,6 @@ public class Board extends JPanel implements MouseListener {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent mouseEvent) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent mouseEvent) {
|
||||
int mouseCoordinateX = (int) (mouseEvent.getX() / SIZE_OF_TILE);
|
||||
@ -210,6 +201,10 @@ public class Board extends JPanel implements MouseListener {
|
||||
return attacks;
|
||||
}
|
||||
|
||||
public boolean isWhitesTurn() {
|
||||
return whitesTurn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
}
|
||||
@ -222,7 +217,7 @@ public class Board extends JPanel implements MouseListener {
|
||||
public void mouseExited(MouseEvent e) {
|
||||
}
|
||||
|
||||
public boolean isWhitesTurn() {
|
||||
return whitesTurn;
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent mouseEvent) {
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package schack;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.io.IOException;
|
||||
import static java.lang.Math.abs;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Horse extends Piece {
|
||||
@ -17,7 +16,7 @@ public class Horse extends Piece {
|
||||
|
||||
for (int dx : new int[]{-2, -1, 1, 2}) {
|
||||
for (int direction : new int[]{-1, 1}) {
|
||||
int stepLength = (3 - abs(dx));
|
||||
int stepLength = (3 - Math.abs(dx));
|
||||
int dy = direction * stepLength;
|
||||
Point potentialMove = new Point(this.position.x + dx, this.position.y + dy);
|
||||
addMovesIfCan(potentialMove, movable, pieces, isSelected);
|
||||
|
@ -12,7 +12,7 @@ public final class King extends PieceKnownIfMoved {
|
||||
}
|
||||
|
||||
/**
|
||||
* Få en ArrayList<Point> med möjliga rockadMoves
|
||||
* Få en ArrayList med möjliga rockader
|
||||
*
|
||||
* @param pieces
|
||||
* @return
|
||||
|
@ -149,7 +149,7 @@ public abstract class Piece {
|
||||
* @param pos Kollar ifall det är schack om denna Piece flyttar hit
|
||||
* @return true ifall det är schack
|
||||
*/
|
||||
boolean isInSchack(Piece[][] pieces, Point pos) {
|
||||
protected boolean isInSchack(Piece[][] pieces, Point pos) {
|
||||
// Kom ihåg vart vi var
|
||||
Point previousPosition = new Point(this.position);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user