Improved package structure

- Renamed the piece package into board
- Moved Board, Move and Position into the board package
This commit is contained in:
Kai S. K. Engelbart 2019-07-06 18:05:00 +02:00
parent 7dd5c2e02b
commit e8e040669c
Signed by: kske
GPG Key ID: 8BEB13EC5DF7EF13
14 changed files with 43 additions and 78 deletions

View File

@ -1,12 +1,8 @@
package dev.kske.chess.piece; package dev.kske.chess.board;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import dev.kske.chess.Board;
import dev.kske.chess.Move;
import dev.kske.chess.Position;
/** /**
* Project: <strong>Chess</strong><br> * Project: <strong>Chess</strong><br>
* File: <strong>Bishop.java</strong><br> * File: <strong>Bishop.java</strong><br>

View File

@ -1,22 +1,15 @@
package dev.kske.chess; package dev.kske.chess.board;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; 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;
import dev.kske.chess.event.GameEvent.GameEventType; import dev.kske.chess.event.GameEvent.GameEventType;
import dev.kske.chess.event.GameEventListener; 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: <strong>Chess</strong><br> * Project: <strong>Chess</strong><br>
@ -146,30 +139,6 @@ public class Board {
gameEventListeners.forEach(listener -> listener.onGameEvent(evt)); 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. * Initialized the board array with the default chess pieces and positions.
*/ */
@ -216,6 +185,30 @@ public class Board {
boardArr[i][j] = null; 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 * @return The board array
*/ */

View File

@ -1,12 +1,8 @@
package dev.kske.chess.piece; package dev.kske.chess.board;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import dev.kske.chess.Board;
import dev.kske.chess.Move;
import dev.kske.chess.Position;
/** /**
* Project: <strong>Chess</strong><br> * Project: <strong>Chess</strong><br>
* File: <strong>King.java</strong><br> * File: <strong>King.java</strong><br>

View File

@ -1,12 +1,8 @@
package dev.kske.chess.piece; package dev.kske.chess.board;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import dev.kske.chess.Board;
import dev.kske.chess.Move;
import dev.kske.chess.Position;
/** /**
* Project: <strong>Chess</strong><br> * Project: <strong>Chess</strong><br>
* File: <strong>Knight.java</strong><br> * File: <strong>Knight.java</strong><br>

View File

@ -1,4 +1,4 @@
package dev.kske.chess; package dev.kske.chess.board;
/** /**
* Project: <strong>Chess</strong><br> * Project: <strong>Chess</strong><br>

View File

@ -1,12 +1,8 @@
package dev.kske.chess.piece; package dev.kske.chess.board;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import dev.kske.chess.Board;
import dev.kske.chess.Move;
import dev.kske.chess.Position;
/** /**
* Project: <strong>Chess</strong><br> * Project: <strong>Chess</strong><br>
* File: <strong>Pawn.java</strong><br> * File: <strong>Pawn.java</strong><br>

View File

@ -1,12 +1,8 @@
package dev.kske.chess.piece; package dev.kske.chess.board;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import dev.kske.chess.Board;
import dev.kske.chess.Move;
import dev.kske.chess.Position;
/** /**
* Project: <strong>Chess</strong><br> * Project: <strong>Chess</strong><br>
* File: <strong>Piece.java</strong><br> * File: <strong>Piece.java</strong><br>

View File

@ -1,4 +1,4 @@
package dev.kske.chess; package dev.kske.chess.board;
/** /**
* Project: <strong>Chess</strong><br> * Project: <strong>Chess</strong><br>

View File

@ -1,12 +1,8 @@
package dev.kske.chess.piece; package dev.kske.chess.board;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import dev.kske.chess.Board;
import dev.kske.chess.Move;
import dev.kske.chess.Position;
/** /**
* Project: <strong>Chess</strong><br> * Project: <strong>Chess</strong><br>
* File: <strong>Queen.java</strong><br> * File: <strong>Queen.java</strong><br>

View File

@ -1,12 +1,8 @@
package dev.kske.chess.piece; package dev.kske.chess.board;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import dev.kske.chess.Board;
import dev.kske.chess.Move;
import dev.kske.chess.Position;
/** /**
* Project: <strong>Chess</strong><br> * Project: <strong>Chess</strong><br>
* File: <strong>Rook.java</strong><br> * File: <strong>Rook.java</strong><br>

View File

@ -2,8 +2,8 @@ package dev.kske.chess.event;
import java.util.EventObject; import java.util.EventObject;
import dev.kske.chess.Board; import dev.kske.chess.board.Board;
import dev.kske.chess.piece.Piece.Color; import dev.kske.chess.board.Piece.Color;
/** /**
* Project: <strong>Chess</strong><br> * Project: <strong>Chess</strong><br>

View File

@ -13,9 +13,9 @@ import java.util.List;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import dev.kske.chess.Board; import dev.kske.chess.board.Board;
import dev.kske.chess.Move; import dev.kske.chess.board.Move;
import dev.kske.chess.Position; import dev.kske.chess.board.Position;
import dev.kske.chess.event.GameEvent; import dev.kske.chess.event.GameEvent;
import dev.kske.chess.event.GameEventListener; import dev.kske.chess.event.GameEventListener;

View File

@ -7,7 +7,7 @@ import javax.swing.JButton;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JPanel; import javax.swing.JPanel;
import dev.kske.chess.Board; import dev.kske.chess.board.Board;
/** /**

View File

@ -9,7 +9,7 @@ import java.util.Map;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import dev.kske.chess.piece.Piece; import dev.kske.chess.board.Piece;
/** /**
* Project: <strong>Chess</strong><br> * Project: <strong>Chess</strong><br>