From 7bf4f78b700bc5d0e80f01ddf84170ff89b75c58 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sat, 6 Jul 2019 18:05:00 +0200 Subject: [PATCH] Improved package structure - Renamed the piece package into board - Moved Board, Move and Position into the board package --- .../kske/chess/{piece => board}/Bishop.java | 6 +- src/dev/kske/chess/{ => board}/Board.java | 61 ++++++++----------- src/dev/kske/chess/{piece => board}/King.java | 6 +- .../kske/chess/{piece => board}/Knight.java | 6 +- src/dev/kske/chess/{ => board}/Move.java | 2 +- src/dev/kske/chess/{piece => board}/Pawn.java | 6 +- .../kske/chess/{piece => board}/Piece.java | 6 +- src/dev/kske/chess/{ => board}/Position.java | 2 +- .../kske/chess/{piece => board}/Queen.java | 6 +- src/dev/kske/chess/{piece => board}/Rook.java | 6 +- src/dev/kske/chess/event/GameEvent.java | 4 +- src/dev/kske/chess/ui/BoardPanel.java | 6 +- src/dev/kske/chess/ui/MainWindow.java | 2 +- src/dev/kske/chess/ui/TextureUtil.java | 2 +- 14 files changed, 43 insertions(+), 78 deletions(-) rename src/dev/kske/chess/{piece => board}/Bishop.java (91%) rename src/dev/kske/chess/{ => board}/Board.java (91%) rename src/dev/kske/chess/{piece => board}/King.java (85%) rename src/dev/kske/chess/{piece => board}/Knight.java (88%) rename src/dev/kske/chess/{ => board}/Move.java (93%) rename src/dev/kske/chess/{piece => board}/Pawn.java (91%) rename src/dev/kske/chess/{piece => board}/Piece.java (89%) rename src/dev/kske/chess/{ => board}/Position.java (88%) rename src/dev/kske/chess/{piece => board}/Queen.java (94%) rename src/dev/kske/chess/{piece => board}/Rook.java (91%) diff --git a/src/dev/kske/chess/piece/Bishop.java b/src/dev/kske/chess/board/Bishop.java similarity index 91% rename from src/dev/kske/chess/piece/Bishop.java rename to src/dev/kske/chess/board/Bishop.java index 7727550..c4dc97d 100644 --- a/src/dev/kske/chess/piece/Bishop.java +++ b/src/dev/kske/chess/board/Bishop.java @@ -1,12 +1,8 @@ -package dev.kske.chess.piece; +package dev.kske.chess.board; import java.util.ArrayList; import java.util.List; -import dev.kske.chess.Board; -import dev.kske.chess.Move; -import dev.kske.chess.Position; - /** * Project: Chess
* File: Bishop.java
diff --git a/src/dev/kske/chess/Board.java b/src/dev/kske/chess/board/Board.java similarity index 91% rename from src/dev/kske/chess/Board.java rename to src/dev/kske/chess/board/Board.java index fe90b51..5f7347e 100644 --- a/src/dev/kske/chess/Board.java +++ b/src/dev/kske/chess/board/Board.java @@ -1,22 +1,15 @@ -package dev.kske.chess; +package dev.kske.chess.board; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import dev.kske.chess.board.Piece.Color; +import dev.kske.chess.board.Piece.Type; import dev.kske.chess.event.GameEvent; import dev.kske.chess.event.GameEvent.GameEventType; import dev.kske.chess.event.GameEventListener; -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.Piece.Type; -import dev.kske.chess.piece.Queen; -import dev.kske.chess.piece.Rook; /** * Project: Chess
@@ -146,30 +139,6 @@ public class Board { gameEventListeners.forEach(listener -> listener.onGameEvent(evt)); } - public Piece get(Position pos) { - return boardArr[pos.x][pos.y]; - } - - public void set(Position pos, Piece piece) { - boardArr[pos.x][pos.y] = piece; - } - - public Piece getPos(Move move) { - return get(move.pos); - } - - public Piece getDest(Move move) { - return get(move.dest); - } - - public void setPos(Move move, Piece piece) { - set(move.pos, piece); - } - - public void setDest(Move move, Piece piece) { - set(move.dest, piece); - } - /** * Initialized the board array with the default chess pieces and positions. */ @@ -216,6 +185,30 @@ public class Board { boardArr[i][j] = null; } + public Piece get(Position pos) { + return boardArr[pos.x][pos.y]; + } + + public void set(Position pos, Piece piece) { + boardArr[pos.x][pos.y] = piece; + } + + public Piece getPos(Move move) { + return get(move.pos); + } + + public Piece getDest(Move move) { + return get(move.dest); + } + + public void setPos(Move move, Piece piece) { + set(move.pos, piece); + } + + public void setDest(Move move, Piece piece) { + set(move.dest, piece); + } + /** * @return The board array */ diff --git a/src/dev/kske/chess/piece/King.java b/src/dev/kske/chess/board/King.java similarity index 85% rename from src/dev/kske/chess/piece/King.java rename to src/dev/kske/chess/board/King.java index 7c1493e..1b6bbd2 100644 --- a/src/dev/kske/chess/piece/King.java +++ b/src/dev/kske/chess/board/King.java @@ -1,12 +1,8 @@ -package dev.kske.chess.piece; +package dev.kske.chess.board; import java.util.ArrayList; import java.util.List; -import dev.kske.chess.Board; -import dev.kske.chess.Move; -import dev.kske.chess.Position; - /** * Project: Chess
* File: King.java
diff --git a/src/dev/kske/chess/piece/Knight.java b/src/dev/kske/chess/board/Knight.java similarity index 88% rename from src/dev/kske/chess/piece/Knight.java rename to src/dev/kske/chess/board/Knight.java index b14c404..15d4d78 100644 --- a/src/dev/kske/chess/piece/Knight.java +++ b/src/dev/kske/chess/board/Knight.java @@ -1,12 +1,8 @@ -package dev.kske.chess.piece; +package dev.kske.chess.board; import java.util.ArrayList; import java.util.List; -import dev.kske.chess.Board; -import dev.kske.chess.Move; -import dev.kske.chess.Position; - /** * Project: Chess
* File: Knight.java
diff --git a/src/dev/kske/chess/Move.java b/src/dev/kske/chess/board/Move.java similarity index 93% rename from src/dev/kske/chess/Move.java rename to src/dev/kske/chess/board/Move.java index e6df053..55986b1 100644 --- a/src/dev/kske/chess/Move.java +++ b/src/dev/kske/chess/board/Move.java @@ -1,4 +1,4 @@ -package dev.kske.chess; +package dev.kske.chess.board; /** * Project: Chess
diff --git a/src/dev/kske/chess/piece/Pawn.java b/src/dev/kske/chess/board/Pawn.java similarity index 91% rename from src/dev/kske/chess/piece/Pawn.java rename to src/dev/kske/chess/board/Pawn.java index 9201f06..e43da04 100644 --- a/src/dev/kske/chess/piece/Pawn.java +++ b/src/dev/kske/chess/board/Pawn.java @@ -1,12 +1,8 @@ -package dev.kske.chess.piece; +package dev.kske.chess.board; import java.util.ArrayList; import java.util.List; -import dev.kske.chess.Board; -import dev.kske.chess.Move; -import dev.kske.chess.Position; - /** * Project: Chess
* File: Pawn.java
diff --git a/src/dev/kske/chess/piece/Piece.java b/src/dev/kske/chess/board/Piece.java similarity index 89% rename from src/dev/kske/chess/piece/Piece.java rename to src/dev/kske/chess/board/Piece.java index 6aacc4c..2ef3db7 100644 --- a/src/dev/kske/chess/piece/Piece.java +++ b/src/dev/kske/chess/board/Piece.java @@ -1,12 +1,8 @@ -package dev.kske.chess.piece; +package dev.kske.chess.board; import java.util.Iterator; import java.util.List; -import dev.kske.chess.Board; -import dev.kske.chess.Move; -import dev.kske.chess.Position; - /** * Project: Chess
* File: Piece.java
diff --git a/src/dev/kske/chess/Position.java b/src/dev/kske/chess/board/Position.java similarity index 88% rename from src/dev/kske/chess/Position.java rename to src/dev/kske/chess/board/Position.java index 17c64ef..c007f50 100644 --- a/src/dev/kske/chess/Position.java +++ b/src/dev/kske/chess/board/Position.java @@ -1,4 +1,4 @@ -package dev.kske.chess; +package dev.kske.chess.board; /** * Project: Chess
diff --git a/src/dev/kske/chess/piece/Queen.java b/src/dev/kske/chess/board/Queen.java similarity index 94% rename from src/dev/kske/chess/piece/Queen.java rename to src/dev/kske/chess/board/Queen.java index 4a0589a..29a2ba6 100644 --- a/src/dev/kske/chess/piece/Queen.java +++ b/src/dev/kske/chess/board/Queen.java @@ -1,12 +1,8 @@ -package dev.kske.chess.piece; +package dev.kske.chess.board; import java.util.ArrayList; import java.util.List; -import dev.kske.chess.Board; -import dev.kske.chess.Move; -import dev.kske.chess.Position; - /** * Project: Chess
* File: Queen.java
diff --git a/src/dev/kske/chess/piece/Rook.java b/src/dev/kske/chess/board/Rook.java similarity index 91% rename from src/dev/kske/chess/piece/Rook.java rename to src/dev/kske/chess/board/Rook.java index e69254d..158eefe 100644 --- a/src/dev/kske/chess/piece/Rook.java +++ b/src/dev/kske/chess/board/Rook.java @@ -1,12 +1,8 @@ -package dev.kske.chess.piece; +package dev.kske.chess.board; import java.util.ArrayList; import java.util.List; -import dev.kske.chess.Board; -import dev.kske.chess.Move; -import dev.kske.chess.Position; - /** * Project: Chess
* File: Rook.java
diff --git a/src/dev/kske/chess/event/GameEvent.java b/src/dev/kske/chess/event/GameEvent.java index 68517d0..ae5d6c9 100644 --- a/src/dev/kske/chess/event/GameEvent.java +++ b/src/dev/kske/chess/event/GameEvent.java @@ -2,8 +2,8 @@ package dev.kske.chess.event; import java.util.EventObject; -import dev.kske.chess.Board; -import dev.kske.chess.piece.Piece.Color; +import dev.kske.chess.board.Board; +import dev.kske.chess.board.Piece.Color; /** * Project: Chess
diff --git a/src/dev/kske/chess/ui/BoardPanel.java b/src/dev/kske/chess/ui/BoardPanel.java index 3210635..d5e4269 100644 --- a/src/dev/kske/chess/ui/BoardPanel.java +++ b/src/dev/kske/chess/ui/BoardPanel.java @@ -13,9 +13,9 @@ import java.util.List; import javax.swing.JOptionPane; import javax.swing.JPanel; -import dev.kske.chess.Board; -import dev.kske.chess.Move; -import dev.kske.chess.Position; +import dev.kske.chess.board.Board; +import dev.kske.chess.board.Move; +import dev.kske.chess.board.Position; import dev.kske.chess.event.GameEvent; import dev.kske.chess.event.GameEventListener; diff --git a/src/dev/kske/chess/ui/MainWindow.java b/src/dev/kske/chess/ui/MainWindow.java index cb1c20b..33c7574 100644 --- a/src/dev/kske/chess/ui/MainWindow.java +++ b/src/dev/kske/chess/ui/MainWindow.java @@ -7,7 +7,7 @@ import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; -import dev.kske.chess.Board; +import dev.kske.chess.board.Board; /** diff --git a/src/dev/kske/chess/ui/TextureUtil.java b/src/dev/kske/chess/ui/TextureUtil.java index b7267ce..7a37f39 100644 --- a/src/dev/kske/chess/ui/TextureUtil.java +++ b/src/dev/kske/chess/ui/TextureUtil.java @@ -9,7 +9,7 @@ import java.util.Map; import javax.imageio.ImageIO; -import dev.kske.chess.piece.Piece; +import dev.kske.chess.board.Piece; /** * Project: Chess