From ea1523c3dcc314ec94b842af990386eacc27d5a6 Mon Sep 17 00:00:00 2001 From: loveb Date: Thu, 19 May 2022 09:30:40 +0200 Subject: [PATCH] =?UTF-8?q?ta=20bort=20on=C3=B6diga=20finals?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/schack/Board.java | 1 + src/schack/Horse.java | 6 +++--- src/schack/King.java | 6 +++--- src/schack/LongWalkers.java | 4 ++-- src/schack/Piece.java | 16 ++++++++-------- src/schack/Schack.java | 2 +- src/schack/SchackState.java | 1 - 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/schack/Board.java b/src/schack/Board.java index 5262321..14a0a03 100644 --- a/src/schack/Board.java +++ b/src/schack/Board.java @@ -157,6 +157,7 @@ public class Board extends JPanel implements MouseListener { /** * Få status över brädet + * * @return SCHACK, SCHACKMATT, PATT, NORMAL */ private SchackState getSchackState() { diff --git a/src/schack/Horse.java b/src/schack/Horse.java index d7c5113..a5f8b28 100644 --- a/src/schack/Horse.java +++ b/src/schack/Horse.java @@ -12,13 +12,13 @@ public class Horse extends Piece { @Override public ArrayList validMoves(Piece[][] pieces, boolean allowedToRecurse) { - final ArrayList movable = new ArrayList<>(); + ArrayList movable = new ArrayList<>(); for (int dx : new int[]{-2, -1, 1, 2}) { for (int direction : new int[]{-1, 1}) { - final int stepLength = (3 - Math.abs(dx)), + int stepLength = (3 - Math.abs(dx)), dy = direction * stepLength; - final Point potentialMove = new Point(this.position.x + dx, this.position.y + dy); + Point potentialMove = new Point(this.position.x + dx, this.position.y + dy); addMovesIfCan(potentialMove, movable, pieces, allowedToRecurse); } } diff --git a/src/schack/King.java b/src/schack/King.java index e0fbd78..4ec650c 100644 --- a/src/schack/King.java +++ b/src/schack/King.java @@ -53,8 +53,8 @@ public final class King extends Piece { * @param shouldGoToLeftSide avgör ifall rockaden är åt vänster håll */ private void castle(Piece[][] pieces, boolean shouldGoToLeftSide) { - final Piece rook = pieces[shouldGoToLeftSide ? 0 : 7][this.position.y]; - final Piece king = this; + Piece rook = pieces[shouldGoToLeftSide ? 0 : 7][this.position.y]; + Piece king = this; // Null där de stod pieces[king.position.x][king.position.y] = null; @@ -70,7 +70,7 @@ public final class King extends Piece { @Override public void move(Piece[][] pieces, Point toMove) { if (Math.abs(position.x - toMove.x) == 2) { - final boolean goToLeftSide = toMove.x < 5; + boolean goToLeftSide = toMove.x < 5; castle(pieces, goToLeftSide); } else { super.move(pieces, toMove); diff --git a/src/schack/LongWalkers.java b/src/schack/LongWalkers.java index fca326a..9ec5824 100644 --- a/src/schack/LongWalkers.java +++ b/src/schack/LongWalkers.java @@ -22,14 +22,14 @@ public abstract class LongWalkers extends Piece { * @return */ ArrayList getMoves(int[][] directions, Piece[][] pieces, boolean allowedToRecurse) { - final ArrayList movable = new ArrayList<>(); + ArrayList movable = new ArrayList<>(); for (int[] xy : directions) { int loopX = this.position.x, loopY = this.position.y; while (loopX + xy[0] >= 0 && loopX + xy[0] <= 7 && loopY + xy[1] >= 0 && loopY + xy[1] <= 7) { loopX += xy[0]; loopY += xy[1]; - final boolean shouldBreak = addMovesIfCan(new Point(loopX, loopY), movable, pieces, allowedToRecurse); + boolean shouldBreak = addMovesIfCan(new Point(loopX, loopY), movable, pieces, allowedToRecurse); if (shouldBreak) { break; } diff --git a/src/schack/Piece.java b/src/schack/Piece.java index 3d0e8a4..e988b58 100644 --- a/src/schack/Piece.java +++ b/src/schack/Piece.java @@ -50,9 +50,9 @@ public abstract class Piece { * @throws IOException ifall det inte finns någon bild på pjäsen */ private void setPieceIcon() throws IOException { - final String className = this.getClass().getSimpleName(); - final String colorName = this.isWhite() ? "White" : "Black"; - final String fileName = colorName + className + ".png"; + String className = this.getClass().getSimpleName(); + String colorName = this.isWhite() ? "White" : "Black"; + String fileName = colorName + className + ".png"; InputStream is = getClass().getResourceAsStream("/img/" + fileName); icon = ImageIO.read(is); } @@ -127,7 +127,7 @@ public abstract class Piece { return false; } - final Piece pieceToCheck = pieces[pos.x][pos.y]; + Piece pieceToCheck = pieces[pos.x][pos.y]; // Detta är en tom plats if (pieceToCheck == null) { @@ -159,17 +159,17 @@ public abstract class Piece { */ protected boolean isInSchack(Piece[][] pieces, Point pos) { // Kom ihåg vart vi var - final Point previousPosition = new Point(this.position); + Point previousPosition = new Point(this.position); // Kom ihåg motståndarpjäs - final Piece guyThatsAlreadyHere = pieces[pos.x][pos.y]; + Piece guyThatsAlreadyHere = pieces[pos.x][pos.y]; // Testa att flytta pieces[pos.x][pos.y] = this; pieces[previousPosition.x][previousPosition.y] = null; this.position = pos; - final boolean inSchack = isInSchack(pieces); + boolean inSchack = isInSchack(pieces); // Flytta tillbaka pieces[previousPosition.x][previousPosition.y] = this; @@ -200,7 +200,7 @@ public abstract class Piece { // Kollar ifall kungen står i schack just nu for (Point enemyAttack : enemyAttacks) { - final Piece attackedPiece = pieces[enemyAttack.x][enemyAttack.y]; + Piece attackedPiece = pieces[enemyAttack.x][enemyAttack.y]; if (attackedPiece != null && attackedPiece.supremeRuler) { return true; } diff --git a/src/schack/Schack.java b/src/schack/Schack.java index eaaff8e..3b72b7e 100644 --- a/src/schack/Schack.java +++ b/src/schack/Schack.java @@ -55,7 +55,7 @@ public class Schack { }); surrender.addActionListener((ActionEvent ae) -> { String whosGivingUp = board.isWhitesTurn() ? "Vit" : "Svart"; - final int choice = JOptionPane.showConfirmDialog(board, whosGivingUp + " har gett upp\nStarta om?"); + int choice = JOptionPane.showConfirmDialog(board, whosGivingUp + " har gett upp\nStarta om?"); if (choice == JOptionPane.YES_OPTION) { try { board.restartGame(); diff --git a/src/schack/SchackState.java b/src/schack/SchackState.java index 5088d0b..f6d0266 100644 --- a/src/schack/SchackState.java +++ b/src/schack/SchackState.java @@ -6,5 +6,4 @@ package schack; */ public enum SchackState { SCHACK, SCHACKMATT, PATT, NORMAL, REMI - }