movable = new ArrayList<>();
- for (int dx : new int[]{-2, -1, 1, 2}) {
- for (int direction : new int[]{-1, 1}) {
+ for (int dx : new int[] { -2, -1, 1, 2 }) {
+ for (int direction : new int[] { -1, 1 }) {
int stepLength = (3 - Math.abs(dx)),
dy = direction * stepLength;
Point potentialMove = new Point(this.position.x + dx, this.position.y + dy);
diff --git a/src/schack/King.java b/src/main/java/com/billenius/schack/King.java
similarity index 92%
rename from src/schack/King.java
rename to src/main/java/com/billenius/schack/King.java
index 988fd1d..599adff 100644
--- a/src/schack/King.java
+++ b/src/main/java/com/billenius/schack/King.java
@@ -1,4 +1,4 @@
-package schack;
+package com.billenius.schack;
import java.awt.Point;
import java.io.IOException;
@@ -26,7 +26,7 @@ public final class King extends Piece {
boolean[] somethingBetweenOrSchackOnTheWay = new boolean[2]; // Vänster, höger
int leftModifier = -1, rightModifier = 1;
- for (int modifier : new int[]{leftModifier, rightModifier}) {
+ 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 == leftModifier) ? 0 : 1] = true;
@@ -36,7 +36,7 @@ public final class King extends Piece {
}
leftModifier = 0;
rightModifier = 1;
- for (int direction : new int[]{leftModifier, rightModifier}) {
+ for (int direction : new int[] { leftModifier, rightModifier }) {
if (!somethingBetweenOrSchackOnTheWay[direction]) {
Piece possibleRook = pieces[direction == leftModifier ? 0 : 7][this.position.y];
if (possibleRook != null && !possibleRook.isMoved()) {
@@ -87,7 +87,8 @@ public final class King extends Piece {
if (loopY == 0 && loopX == 0) {
continue;
}
- addMovesIfCan(new Point(this.position.x + loopX, this.position.y + loopY), movable, pieces, allowedToRecurse);
+ addMovesIfCan(new Point(this.position.x + loopX, this.position.y + loopY), movable, pieces,
+ allowedToRecurse);
}
}
diff --git a/src/schack/LongWalkers.java b/src/main/java/com/billenius/schack/LongWalkers.java
similarity index 78%
rename from src/schack/LongWalkers.java
rename to src/main/java/com/billenius/schack/LongWalkers.java
index d025af4..c6cef8b 100644
--- a/src/schack/LongWalkers.java
+++ b/src/main/java/com/billenius/schack/LongWalkers.java
@@ -1,4 +1,4 @@
-package schack;
+package com.billenius.schack;
import java.awt.Point;
import java.io.IOException;
@@ -14,9 +14,15 @@ public abstract class LongWalkers extends Piece {
/**
* Generell metod för att generera möjliga drag för LongWalkers
*
- * @param directions vilka håll. Exempel:
- * {@code new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}}
för att gå
- * som ett torn
+ * @param directions vilka håll. Exempel:
+ *
+ *
+ * {@code
+ * new int[][] { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 } }
+ * }
+ *
+ * för att gå
+ * som ett torn
*
* @param pieces
* @param allowedToRecurse
diff --git a/src/schack/Pawn.java b/src/main/java/com/billenius/schack/Pawn.java
similarity index 93%
rename from src/schack/Pawn.java
rename to src/main/java/com/billenius/schack/Pawn.java
index 4eece1d..7d9286d 100644
--- a/src/schack/Pawn.java
+++ b/src/main/java/com/billenius/schack/Pawn.java
@@ -1,4 +1,4 @@
-package schack;
+package com.billenius.schack;
import java.awt.HeadlessException;
import java.awt.Point;
@@ -18,7 +18,8 @@ public class Pawn extends Piece {
*
* @param pieces
* @param shouldNotCareIfAttackSpaceIsEmptyOrNot Ifall man ska kolla ifall
- * det är något i möjliga attackrutor ifall
+ * det är något i möjliga
+ * attackrutor ifall
* @return Alla lämpliga attackMoves
*/
@Override
@@ -26,7 +27,7 @@ public class Pawn extends Piece {
List movable = new ArrayList<>();
// Kolla ifall vi kan ta någon
- for (int pawnX : new int[]{-1, 1}) {
+ 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.isWhite() ? -1 : 1));
if (pos.x < 0 || pos.x > 7 || pos.y < 0 || pos.y > 7) {
@@ -59,7 +60,7 @@ public class Pawn extends Piece {
}
// Kolla ifall vi kan ta någon
- for (int pawnX : new int[]{-1, 1}) {
+ for (int pawnX : new int[] { -1, 1 }) {
// Position vi kollar just nu, snett upp åt höger & vänster
final Point pos = new Point(this.position.x + pawnX, this.position.y + (this.isWhite() ? -1 : 1));
movable.addAll(addAttackMovesIfCan(pos, pieces));
@@ -121,7 +122,7 @@ public class Pawn extends Piece {
}
private void transform(Piece[][] pieces) throws HeadlessException {
- String[] transformations = {"Queen", "Rook", "Bishop", "Horse"};
+ String[] transformations = { "Queen", "Rook", "Bishop", "Horse" };
int choosenTransformations = JOptionPane.showOptionDialog(null,
"What do you want to the pawn to transform into?",
"Pawn about to transform",
@@ -129,8 +130,7 @@ public class Pawn extends Piece {
JOptionPane.INFORMATION_MESSAGE,
null,
transformations,
- transformations[0]
- );
+ transformations[0]);
try {
switch (choosenTransformations) {
case 0:
diff --git a/src/schack/Piece.java b/src/main/java/com/billenius/schack/Piece.java
similarity index 90%
rename from src/schack/Piece.java
rename to src/main/java/com/billenius/schack/Piece.java
index 15e853a..a7fe100 100644
--- a/src/schack/Piece.java
+++ b/src/main/java/com/billenius/schack/Piece.java
@@ -1,4 +1,4 @@
-package schack;
+package com.billenius.schack;
import java.awt.Graphics2D;
import java.awt.Point;
@@ -54,7 +54,7 @@ public abstract class Piece {
String className = this.getClass().getSimpleName();
String colorName = this.isWhite() ? "White" : "Black";
String fileName = colorName + className + ".png";
- InputStream is = getClass().getResourceAsStream("/img/" + fileName);
+ InputStream is = getClass().getResourceAsStream("/com/billenius/img/" + fileName);
icon = ImageIO.read(is);
}
@@ -72,7 +72,8 @@ public abstract class Piece {
*
* @param pieces
* @param shouldNotCareIfAttackSpaceIsEmptyOrNot För bönder ifall den ska
- * kolla ifall det är något i möjliga attackrutor ifall
+ * kolla ifall det är något i
+ * möjliga attackrutor ifall
* @return Alla lämpliga attackMoves
*/
public List validAttacks(Piece[][] pieces, boolean shouldNotCareIfAttackSpaceIsEmptyOrNot) {
@@ -89,8 +90,7 @@ public abstract class Piece {
icon,
position.x * Board.SIZE_OF_TILE,
position.y * Board.SIZE_OF_TILE,
- null
- );
+ null);
}
/**
@@ -114,11 +114,12 @@ public abstract class Piece {
/**
* Lägg till move ifall det går, alltså inte är schack där
*
- * @param pos Drag att lägga till ifall det går
- * @param movable Lägger till drag i denna ArrayList
- * @param pieces Piece[][] över brädet
+ * @param pos Drag att lägga till ifall det går
+ * @param movable Lägger till drag i denna ArrayList
+ * @param pieces Piece[][] över brädet
* @param allowedToRecurse Behövs för att inte gå in i en evig loop där
- * {@code addMovesIfCan -> isInSchack -> validMoves -> getCastlingIfPossible(King) -> isInSchack}
+ *
+ * {@code addMovesIfCan -> isInSchack -> validMoves -> getCastlingIfPossible(King) -> isInSchack}
*
* @return true ifall man inte kan gå längre i denna riktning
*/
@@ -155,7 +156,7 @@ public abstract class Piece {
* Kolla ifall det är schack vid den här positionen
*
* @param pieces Piece[][] över hela brädet
- * @param pos Kollar ifall det är schack om denna Piece flyttar hit
+ * @param pos Kollar ifall det är schack om denna Piece flyttar hit
* @return true ifall det är schack
*/
protected boolean isInSchack(Piece[][] pieces, Point pos) {
diff --git a/src/schack/Queen.java b/src/main/java/com/billenius/schack/Queen.java
similarity index 67%
rename from src/schack/Queen.java
rename to src/main/java/com/billenius/schack/Queen.java
index d4138b7..1260206 100644
--- a/src/schack/Queen.java
+++ b/src/main/java/com/billenius/schack/Queen.java
@@ -1,4 +1,4 @@
-package schack;
+package com.billenius.schack;
import java.awt.Point;
import java.io.IOException;
@@ -13,9 +13,8 @@ public class Queen extends LongWalkers {
@Override
public List validMoves(Piece[][] pieces, boolean allowedToRecurse) {
return getMoves(
- new int[][]{{1, 0}, {-1, 0}, {0, 1}, {-1, -1}, {0, -1}, {1, 1}, {-1, 1}, {1, -1}},
+ new int[][] { { 1, 0 }, { -1, 0 }, { 0, 1 }, { -1, -1 }, { 0, -1 }, { 1, 1 }, { -1, 1 }, { 1, -1 } },
pieces,
- allowedToRecurse
- );
+ allowedToRecurse);
}
}
diff --git a/src/schack/Rook.java b/src/main/java/com/billenius/schack/Rook.java
similarity index 74%
rename from src/schack/Rook.java
rename to src/main/java/com/billenius/schack/Rook.java
index f08503b..26bb479 100644
--- a/src/schack/Rook.java
+++ b/src/main/java/com/billenius/schack/Rook.java
@@ -1,4 +1,4 @@
-package schack;
+package com.billenius.schack;
import java.awt.Point;
import java.io.IOException;
@@ -13,10 +13,9 @@ public class Rook extends LongWalkers {
@Override
public List validMoves(Piece[][] pieces, boolean allowedToRecurse) {
return getMoves(
- new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}},
+ new int[][] { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 } },
pieces,
- allowedToRecurse
- );
+ allowedToRecurse);
}
}
diff --git a/src/schack/Schack.java b/src/main/java/com/billenius/schack/Schack.java
similarity index 91%
rename from src/schack/Schack.java
rename to src/main/java/com/billenius/schack/Schack.java
index 0ef6fb0..dc6bee2 100644
--- a/src/schack/Schack.java
+++ b/src/main/java/com/billenius/schack/Schack.java
@@ -1,4 +1,4 @@
-package schack;
+package com.billenius.schack;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
@@ -33,12 +33,12 @@ public class Schack {
frame.setAlwaysOnTop(false);
frame.setResizable(false);
- // Might throw an IOException if the icon of the Pieces isn't embedded correctly
+ // Might throw an IOException if the icon of the Pieces isn't embedded correctly
final Board board = new Board();
frame.setContentPane(board);
frame.getContentPane().addMouseListener(board);
- // Create menu
+ // Create menu
final JMenuBar menuBar = new JMenuBar();
final JMenu gameMenu = new JMenu("Game");
final JMenu connectMenu = new JMenu("Connect");
@@ -81,9 +81,8 @@ public class Schack {
});
connectToOpponent.addActionListener((ActionEvent ae) -> {
String opponentIP = JOptionPane.showInputDialog(null, "What's your opponents IP?");
- System.out.println("opponents ip: "+opponentIP);
-
-
+ System.out.println("opponents ip: " + opponentIP);
+
});
// Add the menu stuff
diff --git a/src/schack/SchackState.java b/src/main/java/com/billenius/schack/SchackState.java
similarity index 76%
rename from src/schack/SchackState.java
rename to src/main/java/com/billenius/schack/SchackState.java
index f6d0266..686ab20 100644
--- a/src/schack/SchackState.java
+++ b/src/main/java/com/billenius/schack/SchackState.java
@@ -1,4 +1,4 @@
-package schack;
+package com.billenius.schack;
/**
*