From ff26346623213953656a833c83de77dd9e09ef3b Mon Sep 17 00:00:00 2001 From: kske Date: Mon, 1 Jul 2019 19:50:42 +0200 Subject: [PATCH] Added all other pieces and moved them into a separate package --- src/dev/kske/chess/Board.java | 38 ++++++++++++++++++++++- src/dev/kske/chess/BoardPanel.java | 2 ++ src/dev/kske/chess/piece/Bishop.java | 17 ++++++++++ src/dev/kske/chess/piece/King.java | 17 ++++++++++ src/dev/kske/chess/piece/Knight.java | 17 ++++++++++ src/dev/kske/chess/{ => piece}/Pawn.java | 2 +- src/dev/kske/chess/{ => piece}/Piece.java | 2 +- src/dev/kske/chess/piece/Queen.java | 17 ++++++++++ src/dev/kske/chess/piece/Rook.java | 17 ++++++++++ 9 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 src/dev/kske/chess/piece/Bishop.java create mode 100644 src/dev/kske/chess/piece/King.java create mode 100644 src/dev/kske/chess/piece/Knight.java rename src/dev/kske/chess/{ => piece}/Pawn.java (87%) rename src/dev/kske/chess/{ => piece}/Piece.java (89%) create mode 100644 src/dev/kske/chess/piece/Queen.java create mode 100644 src/dev/kske/chess/piece/Rook.java diff --git a/src/dev/kske/chess/Board.java b/src/dev/kske/chess/Board.java index 7f5821c..da918d4 100644 --- a/src/dev/kske/chess/Board.java +++ b/src/dev/kske/chess/Board.java @@ -1,6 +1,13 @@ package dev.kske.chess; -import dev.kske.chess.Piece.Color; +import dev.kske.chess.piece.Bishop; +import dev.kske.chess.piece.King; +import dev.kske.chess.piece.Knight; +import dev.kske.chess.piece.Pawn; +import dev.kske.chess.piece.Piece; +import dev.kske.chess.piece.Piece.Color; +import dev.kske.chess.piece.Queen; +import dev.kske.chess.piece.Rook; /** * Project: Chess
@@ -17,12 +24,41 @@ public class Board { initializeDefaultPositions(); } + /** + * Initialized the board array with the default chess pieces and positions. + */ private void initializeDefaultPositions() { // Initialize pawns for (int i = 0; i < 8; i++) { boardArr[i][1] = new Pawn(Color.BLACK); boardArr[i][6] = new Pawn(Color.WHITE); } + + // Initialize kings + boardArr[4][0] = new King(Color.BLACK); + boardArr[4][7] = new King(Color.WHITE); + + // Initialize queens + boardArr[3][0] = new Queen(Color.BLACK); + boardArr[3][7] = new Queen(Color.WHITE); + + // Initialize rooks + boardArr[0][0] = new Rook(Color.BLACK); + boardArr[0][7] = new Rook(Color.WHITE); + boardArr[7][0] = new Rook(Color.BLACK); + boardArr[7][7] = new Rook(Color.WHITE); + + // Initialize knights + boardArr[1][0] = new Knight(Color.BLACK); + boardArr[1][7] = new Knight(Color.WHITE); + boardArr[6][0] = new Knight(Color.BLACK); + boardArr[6][7] = new Knight(Color.WHITE); + + // Initialize bishops + boardArr[2][0] = new Bishop(Color.BLACK); + boardArr[2][7] = new Bishop(Color.WHITE); + boardArr[5][0] = new Bishop(Color.BLACK); + boardArr[5][7] = new Bishop(Color.WHITE); } /** diff --git a/src/dev/kske/chess/BoardPanel.java b/src/dev/kske/chess/BoardPanel.java index 0fe5877..57c9a40 100644 --- a/src/dev/kske/chess/BoardPanel.java +++ b/src/dev/kske/chess/BoardPanel.java @@ -13,6 +13,8 @@ import java.util.Map; import javax.swing.JPanel; +import dev.kske.chess.piece.Piece; + /** * Project: Chess
* File: BoardPanel.java
diff --git a/src/dev/kske/chess/piece/Bishop.java b/src/dev/kske/chess/piece/Bishop.java new file mode 100644 index 0000000..11ccf33 --- /dev/null +++ b/src/dev/kske/chess/piece/Bishop.java @@ -0,0 +1,17 @@ +package dev.kske.chess.piece; + +/** + * Project: Chess
+ * File: Bishop.java
+ * Created: 01.07.2019
+ * Author: Kai S. K. Engelbart + */ +public class Bishop extends Piece { + + public Bishop(Color color) { + super(color); + } + + @Override + public Type getType() { return Type.BISHOP; } +} diff --git a/src/dev/kske/chess/piece/King.java b/src/dev/kske/chess/piece/King.java new file mode 100644 index 0000000..d1b2f4c --- /dev/null +++ b/src/dev/kske/chess/piece/King.java @@ -0,0 +1,17 @@ +package dev.kske.chess.piece; + +/** + * Project: Chess
+ * File: King.java
+ * Created: 01.07.2019
+ * Author: Kai S. K. Engelbart + */ +public class King extends Piece { + + public King(Color color) { + super(color); + } + + @Override + public Type getType() { return Type.KING; } +} diff --git a/src/dev/kske/chess/piece/Knight.java b/src/dev/kske/chess/piece/Knight.java new file mode 100644 index 0000000..a713880 --- /dev/null +++ b/src/dev/kske/chess/piece/Knight.java @@ -0,0 +1,17 @@ +package dev.kske.chess.piece; + +/** + * Project: Chess
+ * File: Knight.java
+ * Created: 01.07.2019
+ * Author: Kai S. K. Engelbart + */ +public class Knight extends Piece { + + public Knight(Color color) { + super(color); + } + + @Override + public Type getType() { return Type.KNIGHT; } +} diff --git a/src/dev/kske/chess/Pawn.java b/src/dev/kske/chess/piece/Pawn.java similarity index 87% rename from src/dev/kske/chess/Pawn.java rename to src/dev/kske/chess/piece/Pawn.java index 35de96b..8d546e0 100644 --- a/src/dev/kske/chess/Pawn.java +++ b/src/dev/kske/chess/piece/Pawn.java @@ -1,4 +1,4 @@ -package dev.kske.chess; +package dev.kske.chess.piece; /** * Project: Chess
diff --git a/src/dev/kske/chess/Piece.java b/src/dev/kske/chess/piece/Piece.java similarity index 89% rename from src/dev/kske/chess/Piece.java rename to src/dev/kske/chess/piece/Piece.java index 36e9ca3..cbd00a2 100644 --- a/src/dev/kske/chess/Piece.java +++ b/src/dev/kske/chess/piece/Piece.java @@ -1,4 +1,4 @@ -package dev.kske.chess; +package dev.kske.chess.piece; /** * Project: Chess
diff --git a/src/dev/kske/chess/piece/Queen.java b/src/dev/kske/chess/piece/Queen.java new file mode 100644 index 0000000..647896e --- /dev/null +++ b/src/dev/kske/chess/piece/Queen.java @@ -0,0 +1,17 @@ +package dev.kske.chess.piece; + +/** + * Project: Chess
+ * File: Queen.java
+ * Created: 01.07.2019
+ * Author: Kai S. K. Engelbart + */ +public class Queen extends Piece { + + public Queen(Color color) { + super(color); + } + + @Override + public Type getType() { return Type.QUEEN; } +} diff --git a/src/dev/kske/chess/piece/Rook.java b/src/dev/kske/chess/piece/Rook.java new file mode 100644 index 0000000..8f176a7 --- /dev/null +++ b/src/dev/kske/chess/piece/Rook.java @@ -0,0 +1,17 @@ +package dev.kske.chess.piece; + +/** + * Project: Chess
+ * File: Rook.java
+ * Created: 01.07.2019
+ * Author: Kai S. K. Engelbart + */ +public class Rook extends Piece { + + public Rook(Color color) { + super(color); + } + + @Override + public Type getType() { return Type.ROOK; } +}