diff --git a/MavenChess/.idea/misc.xml b/MavenChess/.idea/misc.xml index 0a5c3589fb9cb8a9a86a4d002a6d654e1b26c97c..abcc7fdbf4f41962418209acb3e25fd65eea731e 100644 --- a/MavenChess/.idea/misc.xml +++ b/MavenChess/.idea/misc.xml @@ -8,7 +8,7 @@ </list> </option> </component> - <component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-20" project-jdk-type="JavaSDK"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_20" default="true" project-jdk-name="openjdk-20" project-jdk-type="JavaSDK"> <output url="file://$PROJECT_DIR$/out" /> </component> </project> \ No newline at end of file diff --git a/MavenChess/MavenChess/src/main/java/controller/Main.java b/MavenChess/MavenChess/src/main/java/controller/Main.java index 5ac2f1933028dc7444ad7326c70007abfdd2f5f1..0637b74e9c8be4a513ebed53156ba4369da52178 100644 --- a/MavenChess/MavenChess/src/main/java/controller/Main.java +++ b/MavenChess/MavenChess/src/main/java/controller/Main.java @@ -2,16 +2,12 @@ package controller; import javafx.application.Application; import javafx.scene.*; -import javafx.scene.input.KeyEvent; import javafx.scene.input.MouseEvent; import javafx.scene.input.ScrollEvent; import javafx.stage.Stage; import model.Board; -import model.Position; import view.*; -import java.util.ArrayList; - public class Main extends Application { @Override public void start(Stage stage) { @@ -43,39 +39,33 @@ public class Main extends Application { Desk desk = new Desk(material); desk.addAllToScene(group); // adds the desk to scene - // init - creates a (visual) chessboard of 8x8, and all (visual) 3d pieces - BoardView boardView = new BoardView(model, material); - boardView.addAllToScene(group); // adds the board and the pieces to scene - // init - creates a (model) list of all pieces Board board = new Board(); + // init - creates a (visual) chessboard of 8x8, and all (visual) 3d pieces + BoardView boardView = new BoardView(model, material, board); + boardView.addAllToScene(group); // adds the board and the pieces to scene + // event -------------------------------------------------------------- // event - camera rotation (mouse dragging) camera.initMouseControl(scene.get()); // allow user to move camera with mouse, with some constraints // event - camera zoom (mouse scroll) - stage.addEventHandler(ScrollEvent.SCROLL, event -> { - camera.scrollCamera(event.getDeltaY()); - }); + stage.addEventHandler(ScrollEvent.SCROLL, event -> camera.scrollCamera(event.getDeltaY())); // event - click on (visual) pieces to show (visually) available movements. (asked from model rules) for(int n = 0 ; n < 64 ; n++) { PieceView piece = boardView.getPiece(n); if(piece != null) { - piece.getObj().addEventHandler(MouseEvent.MOUSE_CLICKED, event -> { - boardView.clickPiece(material, piece, board); - }); + piece.getObj().addEventHandler(MouseEvent.MOUSE_CLICKED, event -> boardView.clickPiece(material, piece, board)); } } // event - click on (visual) "colored tiles" to move the selected piece there for(int n = 0 ; n < 64 ; n++) { TileView tile = boardView.getTile(n); - tile.getObj().addEventHandler(MouseEvent.MOUSE_CLICKED, event -> { - boardView.clickTile(material, tile, board); - }); + tile.getObj().addEventHandler(MouseEvent.MOUSE_CLICKED, event -> boardView.clickTile(material, tile, board)); } // start -------------------------------------------------------------- diff --git a/MavenChess/MavenChess/src/main/java/model/Bishop.java b/MavenChess/MavenChess/src/main/java/model/Bishop.java index 2f52deaf8fe84dbc777c03def65595305986aefc..cd2e3566b0bc6eaf0cef0c38aa52cf3e1e1dcfea 100644 --- a/MavenChess/MavenChess/src/main/java/model/Bishop.java +++ b/MavenChess/MavenChess/src/main/java/model/Bishop.java @@ -8,81 +8,84 @@ public class Bishop extends Piece { super(p, color); } - public ArrayList<Position> getAvailableMoves(Board b) { // creates a dynamic list of available moves - ArrayList<Position> moves = new ArrayList<Position>(); - + ArrayList<Position> moves = new ArrayList<>(); Position arrival; - Position Cursor = new Position(p.getX(), p.getY()); + // list of the 4 bishop directions + int[] all_x = {1, 1, -1, -1}; + int[] all_y = {1, -1, -1, 1}; + + for(int n = 0 ; n < all_x.length ; n++) { // for each direction + int x = all_x[n]; + int y = all_y[n]; + boolean blocked = false; + int i = 1; + while (i < 8 && !blocked) { // continues "as a ray" in that direction until blocked + arrival = new Position(p.getX() + (x * i), p.getY() + (y * i)); + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { + moves.add(arrival); + } + if (!b.isFree(arrival)) { + blocked = true; + } + i++; + } + } + // Full wrote version : -------------------------------------------- + /* + Position Cursor = new Position(p.getX(), p.getY()); int i = 1; boolean leftTop = false; boolean rightTop = false; boolean leftDown = false; boolean rightDown = false; - while (i < 8) { - //left diagonal - arrival = new Position(p.getX() + i, p.getY() + i); - if (!leftTop) { - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } } - if (!b.isFree(arrival)) { leftTop = true; } - - - - - //right diagonal arrival = new Position(p.getX() - i, p.getY() + i); if (!rightTop) { - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } } if (!b.isFree(arrival)) { rightTop = true; } - - - arrival = new Position(p.getX() + i, p.getY() - i); if (!leftDown) { - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } } if (!b.isFree(arrival)) { leftDown = true; } - - - arrival = new Position(p.getX() - i, p.getY() - i); if (!rightDown) { - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } } if (!b.isFree(arrival)) { rightDown = true; } - - i++; } - + */ + // ----------------------------------------------------------- return moves; } diff --git a/MavenChess/MavenChess/src/main/java/model/Board.java b/MavenChess/MavenChess/src/main/java/model/Board.java index d458d600096b7aa174f0a0b551d4832ee2deaa8b..7a0e8388ff9bc85dd3d7c33d2a1af305a13e484b 100644 --- a/MavenChess/MavenChess/src/main/java/model/Board.java +++ b/MavenChess/MavenChess/src/main/java/model/Board.java @@ -3,36 +3,37 @@ package model; public class Board { public static final int PAWN = 0, ROOK = 1, KNIGHT = 2, BISHOP = 3, QUEEN = 4, KING = 5; + public static final int A = 1, B = 2, C = 3, D = 4, E = 5, F = 6, G = 7, H = 8; - private Piece[] pieces; + private final Piece[] pieces; private Position selected; public Board() { selected = null; - pieces = new Piece[64]; // initialisation of the list of pieces + pieces = new Piece[64]; for(int i = 0 ; i < 64 ; i++) { pieces[i] = null; } - int y = 0; + int y; for(int color = Piece.WHITE ; color == Piece.WHITE || color == Piece.BLACK ; color++) { // placement of pawns if(color == Piece.WHITE) { y = 2; } else { y = 7; } - for(int x = Position.a ; x <= Position.h ; x++) { + for(int x = A ; x <= H ; x++) { createPiece(x, y, color, PAWN); // fills line 2 and line 7 with pawns } // placement of rook, knight, bishop, queen, king - line 1 and line 8 if(color == Piece.WHITE) { y = 1; } else { y = 8; } - createPiece(Position.a, y, color, ROOK); - createPiece(Position.b, y, color, KNIGHT); - createPiece(Position.c, y, color, BISHOP); - createPiece(Position.d, y, color, QUEEN); - createPiece(Position.e, y, color, KING); - createPiece(Position.f, y, color, BISHOP); - createPiece(Position.g, y, color, KNIGHT); - createPiece(Position.h, y, color, ROOK); + createPiece(A, y, color, ROOK); + createPiece(B, y, color, KNIGHT); + createPiece(C, y, color, BISHOP); + createPiece(D, y, color, QUEEN); + createPiece(E, y, color, KING); + createPiece(F, y, color, BISHOP); + createPiece(G, y, color, KNIGHT); + createPiece(H, y, color, ROOK); } } @@ -43,23 +44,25 @@ public class Board { public Piece getPiece(Position position) { return pieces[position.getID()]; } + + public Piece getPiece(int id) { + return pieces[id]; + } public void createPiece(int x, int y, int color, int type) { + Position p = new Position(x, y); switch(type) { - case ROOK -> setPiece(new Rook(new Position(x, y), color)); - case KNIGHT -> setPiece(new Knight(new Position(x, y), color)); - case BISHOP -> setPiece(new Bishop(new Position(x, y), color)); - case QUEEN -> setPiece(new Queen(new Position(x, y), color)); - case KING -> setPiece(new King(new Position(x, y), color)); - default -> setPiece(new Pawn(new Position(x, y), color)); + case ROOK -> setPiece(new Rook(p, color)); + case KNIGHT -> setPiece(new Knight(p, color)); + case BISHOP -> setPiece(new Bishop(p, color)); + case QUEEN -> setPiece(new Queen(p, color)); + case KING -> setPiece(new King(p, color)); + default -> setPiece(new Pawn(p, color)); } } public Position getSelected() { return selected; } - public Piece getSelectedPiece() { - return getPiece(selected); - } public void setSelected(Position p) { selected = p; @@ -68,29 +71,35 @@ public class Board { public void movePiece(Position origin, Position arrival) { Piece piece = getPiece(origin); piece.setPosition(arrival); // changes position to arrival - setPiece(piece); // copies the piece from origin ID to arrival ID - pieces[origin.getID()] = null; // removes the origin ID piece + setPiece(piece); // copies the piece (from origin ID) to arrival ID on the pieces list + pieces[origin.getID()] = null; // removes the origin ID piece on the pieces list } public boolean isFree(Position p) { - return (Position.isCorrect(p) && pieces[p.getID()] == null); - } - public boolean isBlack(Position p) { - return (!isFree(p) && pieces[p.getID()].getColor() == Piece.BLACK); - } - - public boolean isWhite(Position p) { - return (!isFree(p) && pieces[p.getID()].getColor() == Piece.WHITE); + return (p.isCorrect() + && getPiece(p) == null); } - public boolean isEnnemy(Position p, Position origin) { - return (Position.isCorrect(p) && !isFree(p) && pieces[p.getID()].getColor() != pieces[origin.getID()].getColor() ); + public boolean isEnemy(Position arrival, Position origin) { + return (arrival.isCorrect() + && !isFree(arrival) + && getPiece(arrival).getColor() != getPiece(origin).getColor() ); } public boolean isKing(Position p) { - return (!isFree(p) && pieces[p.getID()].getClass() == King.class); + return (p.isCorrect() + && !isFree(p) + && getPiece(p).getClass() == King.class); + } + + public boolean isRook(Position p) { + return (p.isCorrect() + && !isFree(p) + && getPiece(p).getClass() == Rook.class); } public boolean isPawn(Position p) { - return (!isFree(p) && pieces[p.getID()].getClass() == Pawn.class); + return (p.isCorrect() + && !isFree(p) + && getPiece(p).getClass() == Pawn.class); } } diff --git a/MavenChess/MavenChess/src/main/java/model/King.java b/MavenChess/MavenChess/src/main/java/model/King.java index e1ec7723dc919b8e121a5b1e4dcd35b6f778177d..6bb57ca083c271652356e46586be4771bd88e4ce 100644 --- a/MavenChess/MavenChess/src/main/java/model/King.java +++ b/MavenChess/MavenChess/src/main/java/model/King.java @@ -5,58 +5,84 @@ import java.util.ArrayList; public class King extends Piece { - private boolean Casteling = true; - private final Position original; - public King(Position p, int color) { super(p, color); - this.original = p; } - public ArrayList<Position> getAvailableMoves(Board b) { // creates a dynamic list of available moves - ArrayList<Position> moves = new ArrayList<Position>(); - + ArrayList<Position> moves = new ArrayList<>(); Position arrival; + // list of the 8 king movements + int[] all_x = {0, 1, 1, 1, 0, -1, -1, -1}; + int[] all_y = {1, 1, 0, -1, -1, -1, 0, 1}; + + for(int n = 0 ; n < all_x.length ; n++) { // for each direction + int x = all_x[n]; + int y = all_y[n]; + arrival = new Position(p.getX() + x, p.getY() + y); + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { + moves.add(arrival); + } + } + + // Castling + if(!hasBeenMoved) { + Position rookWest = new Position(1, p.getY()); + if( b.isRook(rookWest) && !b.getPiece(rookWest).hasBeenMoved() + && b.isFree(new Position(2, p.getY())) + && b.isFree(new Position(3, p.getY())) + && b.isFree(new Position(4, p.getY())) ) { + moves.add(rookWest); + } + Position rookEast = new Position(8, p.getY()); + if( b.isRook(rookEast) && !b.getPiece(rookEast).hasBeenMoved() + && b.isFree(new Position(7, p.getY())) + && b.isFree(new Position(6, p.getY())) ) { + moves.add(rookEast); + } + } + + // Full wrote version : -------------------------------------------- + /* // up arrival = new Position(p.getX(), p.getY() + 1); - if(b.isEnnemy(arrival,p) || b.isFree(arrival)) { moves.add(arrival); } + if(b.isEnemy(arrival,p) || b.isFree(arrival)) { moves.add(arrival); } //down arrival = new Position(p.getX(), p.getY() - 1); - if(b.isEnnemy(arrival,p) || b.isFree(arrival)) { moves.add(arrival); } + if(b.isEnemy(arrival,p) || b.isFree(arrival)) { moves.add(arrival); } //left arrival = new Position(p.getX()+1, p.getY()); - if(b.isEnnemy(arrival,p) || b.isFree(arrival)) { moves.add(arrival); } + if(b.isEnemy(arrival,p) || b.isFree(arrival)) { moves.add(arrival); } //right arrival = new Position(p.getX()-1, p.getY()); - if(b.isEnnemy(arrival,p) || b.isFree(arrival)) { moves.add(arrival); } + if(b.isEnemy(arrival,p) || b.isFree(arrival)) { moves.add(arrival); } //up left arrival = new Position(p.getX()-1, p.getY() + 1); - if(b.isEnnemy(arrival,p) || b.isFree(arrival)) { moves.add(arrival); } + if(b.isEnemy(arrival,p) || b.isFree(arrival)) { moves.add(arrival); } //up right arrival = new Position(p.getX()+1, p.getY() + 1); - if(b.isEnnemy(arrival,p) || b.isFree(arrival)) { moves.add(arrival); } + if(b.isEnemy(arrival,p) || b.isFree(arrival)) { moves.add(arrival); } //down left arrival = new Position(p.getX()-1, p.getY() -1); - if(b.isEnnemy(arrival,p) || b.isFree(arrival)) { moves.add(arrival); } + if(b.isEnemy(arrival,p) || b.isFree(arrival)) { moves.add(arrival); } //down right arrival = new Position(p.getX()+1, p.getY() - 1); - if(b.isEnnemy(arrival,p) || b.isFree(arrival)) { moves.add(arrival); } + if(b.isEnemy(arrival,p) || b.isFree(arrival)) { moves.add(arrival); } arrival = new Position(p.getX(), p.getY() + 1); - if(b.isEnnemy(arrival,p) || b.isFree(arrival)) { moves.add(arrival); } - - + if(b.isEnemy(arrival,p) || b.isFree(arrival)) { moves.add(arrival); } + */ + // --------------------------------------------------------------- return moves; } diff --git a/MavenChess/MavenChess/src/main/java/model/Knight.java b/MavenChess/MavenChess/src/main/java/model/Knight.java index 7a731d0c95c2c066eaabfe3670422c754e756156..b65fb00a98ce31af03a06135a2a287345973494e 100644 --- a/MavenChess/MavenChess/src/main/java/model/Knight.java +++ b/MavenChess/MavenChess/src/main/java/model/Knight.java @@ -13,47 +13,60 @@ public class Knight extends Piece { public ArrayList<Position> getAvailableMoves(Board b) { // creates a dynamic list of available moves - ArrayList<Position> moves = new ArrayList<Position>(); - + ArrayList<Position> moves = new ArrayList<>(); Position arrival; + // list of the 8 knight specific movements + int[] all_x = {1, 2, 2, 1, -1, -2, -2, -1}; + int[] all_y = {2, 1, -1, -2, -2, -1, 1, 2}; + + for(int n = 0 ; n < all_x.length ; n++) { // for each direction + int x = all_x[n]; + int y = all_y[n]; + arrival = new Position(p.getX() + x, p.getY() + y); + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { + moves.add(arrival); + } + } + // Full wrote version : -------------------------- + /* arrival = new Position(p.getX() - 1, p.getY() + 2); - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } // up right arrival = new Position(p.getX() + 1, p.getY() + 2); - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } // down left arrival = new Position(p.getX() - 1, p.getY() - 2); - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } //down right arrival = new Position(p.getX() + 1, p.getY() - 2); - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } arrival = new Position(p.getX() - 2, p.getY() + 1); - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } // up right arrival = new Position(p.getX() + 2, p.getY() + 1); - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } // down left arrival = new Position(p.getX() - 2, p.getY() - 1); - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } @@ -61,7 +74,8 @@ public class Knight extends Piece { arrival = new Position(p.getX() + 2, p.getY() - 1); if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); - } + }*/ + // ----------------------------------------------- return moves; } diff --git a/MavenChess/MavenChess/src/main/java/model/Pawn.java b/MavenChess/MavenChess/src/main/java/model/Pawn.java index 0861484c74d2ec2a1f1bd1b88f053b011afac658..226e685b9b80c167ab66b299590b2e46f9854300 100644 --- a/MavenChess/MavenChess/src/main/java/model/Pawn.java +++ b/MavenChess/MavenChess/src/main/java/model/Pawn.java @@ -3,62 +3,40 @@ package model; import java.util.ArrayList; public class Pawn extends Piece { - private final Position original; public Pawn(Position p, int color) { super(p, color); - this.original = p; } - public ArrayList<Position> getAvailableMoves(Board b) { // creates a dynamic list of available moves - ArrayList<Position> moves = new ArrayList<Position>(); - + ArrayList<Position> moves = new ArrayList<>(); Position arrival; - if(color == Piece.WHITE) { // black and white have an opposite direction behavior - - if(this.p.getID() == this.original.getID()){ - // up, free movement first time - arrival = new Position(p.getX(), p.getY() + 2); - if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); } - - } - - // up, free movement - arrival = new Position(p.getX(), p.getY() + 1); - if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); } - - // up right, attack movement - arrival = new Position(p.getX() + 1, p.getY() + 1); - if(Position.isCorrect(arrival) && b.isBlack(arrival)) { moves.add(arrival); } - - // up left, attack movement - arrival = new Position(p.getX() - 1, p.getY() + 1); - if(Position.isCorrect(arrival) && b.isBlack(arrival)) { moves.add(arrival); } + int y = -1; + if(color == Piece.WHITE) { // black and white have an opposite direction behavior + y = 1; } - else { - if(this.p.getID() == this.original.getID()){ - // up, free movement first time - arrival = new Position(p.getX(), p.getY() - 2); - if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); } + // forward + arrival = new Position(p.getX(), p.getY() + y); + if(b.isFree(arrival)) { + moves.add(arrival); + // forward twice, only if it's first move + if(!hasBeenMoved){ + arrival = new Position(p.getX(), p.getY() + y + y); + if(b.isFree(arrival)) { moves.add(arrival); } } + } - // down, free movement - arrival = new Position(p.getX(), p.getY() - 1); - if(Position.isCorrect(arrival) && b.isFree(arrival)) { moves.add(arrival); } - - // down right, attack movement - arrival = new Position(p.getX() + 1, p.getY() - 1); - if(Position.isCorrect(arrival) && b.isWhite(arrival)) { moves.add(arrival); } + // forward + east, attack-only movement + arrival = new Position(p.getX() + 1, p.getY() + y); + if(b.isEnemy(arrival, p)) { moves.add(arrival); } - // down left, attack movement - arrival = new Position(p.getX() - 1, p.getY() - 1); - if(Position.isCorrect(arrival) && b.isWhite(arrival)) { moves.add(arrival); } + // forward + west, attack-only movement + arrival = new Position(p.getX() - 1, p.getY() + y); + if(b.isEnemy(arrival, p)) { moves.add(arrival); } - } return moves; } } diff --git a/MavenChess/MavenChess/src/main/java/model/Piece.java b/MavenChess/MavenChess/src/main/java/model/Piece.java index 72d2d8d5f3c065ee9623cc6281c0b89703e7c7e0..d26f9f4b4151a7e3e8c2cead5982e465b740dc6b 100644 --- a/MavenChess/MavenChess/src/main/java/model/Piece.java +++ b/MavenChess/MavenChess/src/main/java/model/Piece.java @@ -7,12 +7,14 @@ import java.util.ArrayList; public abstract class Piece { protected Position p; protected int color; + protected boolean hasBeenMoved; public static final int WHITE = 1, BLACK = 2; protected Piece(Position p, int color) { this.p = p; this.color = color; + hasBeenMoved = false; } public ArrayList<Position> getAvailableMoves(Board b) { @@ -27,7 +29,12 @@ public abstract class Piece { return p; } + public boolean hasBeenMoved() { + return hasBeenMoved; + } + public void setPosition(Position p) { this.p = p; + hasBeenMoved = true; } } diff --git a/MavenChess/MavenChess/src/main/java/model/Position.java b/MavenChess/MavenChess/src/main/java/model/Position.java index 7a29479c7a3d7d20d8ceaae892b87dc43fa73d0d..b1562dce36959388bc1e51114e3f4f0fd448ea79 100644 --- a/MavenChess/MavenChess/src/main/java/model/Position.java +++ b/MavenChess/MavenChess/src/main/java/model/Position.java @@ -3,7 +3,6 @@ package model; public class Position { private int x; // x horizontal -> use static Position.a to Position.h private int y; // y vertical -> use 1 to 8 - public static final int a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7, h = 8; // PS : graveyards are specified as negative 'x', and we use 'y' to pile dead pieces from 1 to n public static final int WHITE_GRAVEYARD = -1, BLACK_GRAVEYARD = -2; @@ -40,7 +39,11 @@ public class Position { this.y = y; } - public static boolean isCorrect(Position arrival) { - return (arrival.getX() >= 1 && arrival.getX() <= 8 && arrival.getY() >= 1 && arrival.getY() <= 8); + public boolean isCorrect() { + return (x >= 1 && x <= 8 && y >= 1 && y <= 8); + } + + public boolean equals(Position p) { + return (x == p.getX() && y == p.getY()); } } diff --git a/MavenChess/MavenChess/src/main/java/model/Queen.java b/MavenChess/MavenChess/src/main/java/model/Queen.java index 0d740f16487c0cb1688577459fbe89defc7f35bb..08f4ae3130cfc72640421c3b4b2c3ba558950b40 100644 --- a/MavenChess/MavenChess/src/main/java/model/Queen.java +++ b/MavenChess/MavenChess/src/main/java/model/Queen.java @@ -11,11 +11,32 @@ public class Queen extends Piece{ public ArrayList<Position> getAvailableMoves(Board b) { // creates a dynamic list of available moves - ArrayList<Position> moves = new ArrayList<Position>(); - + ArrayList<Position> moves = new ArrayList<>(); Position arrival; + // list of the 8 queen directions + int[] all_x = {0, 1, 1, 1, 0, -1, -1, -1}; + int[] all_y = {1, 1, 0, -1, -1, -1, 0, 1}; + + for(int n = 0 ; n < all_x.length ; n++) { // for each direction + int x = all_x[n]; + int y = all_y[n]; + boolean blocked = false; + int i = 1; + while (i < 8 && !blocked) { // continues "as a ray" in that direction until blocked + arrival = new Position(p.getX() + (x * i), p.getY() + (y * i)); + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { + moves.add(arrival); + } + if (!b.isFree(arrival)) { + blocked = true; + } + i++; + } + } + // Full wrote version : -------------------------------------------- + /* int i = 1; boolean left = false; boolean right = false; @@ -29,111 +50,84 @@ public class Queen extends Piece{ while (i < 8) { // Bishop moves arrival = new Position(p.getX() + i, p.getY() + i); - if (!leftTop) { - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } } - if (!b.isFree(arrival)) { leftTop = true; } - - - - - //right diagonal arrival = new Position(p.getX() - i, p.getY() + i); if (!rightTop) { - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } } if (!b.isFree(arrival)) { rightTop = true; } - - - arrival = new Position(p.getX() + i, p.getY() - i); if (!leftDown) { - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } } if (!b.isFree(arrival)) { leftDown = true; } - - - arrival = new Position(p.getX() - i, p.getY() - i); if (!rightDown) { - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } } if (!b.isFree(arrival)) { rightDown = true; } - - // RooK moves - arrival = new Position(p.getX() +i, p.getY()); - if (!left) { - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } } - if (!b.isFree(arrival)) { left = true; } - - - //right diagonal arrival = new Position(p.getX()- i , p.getY() ); if (!right) { - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } } if (!b.isFree(arrival)) { right = true; } - - - arrival = new Position(p.getX(), p.getY() + i); if (!top) { - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } } if (!b.isFree(arrival)) { top = true; } - - - arrival = new Position(p.getX(), p.getY() - i); if (!down) { - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } } if (!b.isFree(arrival)) { down = true; } - - i++; } + */ + // ------------------------------------------------------------ return moves; } diff --git a/MavenChess/MavenChess/src/main/java/model/Rook.java b/MavenChess/MavenChess/src/main/java/model/Rook.java index 859120d2d532b813f744407c780094342c1e7291..a04763e2c50b2fb6d3c7398810462e9e4a5f0d1d 100644 --- a/MavenChess/MavenChess/src/main/java/model/Rook.java +++ b/MavenChess/MavenChess/src/main/java/model/Rook.java @@ -4,43 +4,59 @@ import java.util.ArrayList; public class Rook extends Piece { - - private final Position original; - public Rook(Position p, int color) { super(p, color); - this.original = p; } - public ArrayList<Position> getAvailableMoves(Board b) { // creates a dynamic list of available moves - ArrayList<Position> moves = new ArrayList<Position>(); - + ArrayList<Position> moves = new ArrayList<>(); Position arrival; + // list of the 4 rook directions + int[] all_x = {0, 1, 0, -1}; + int[] all_y = {1, 0, -1, 0}; + + for(int n = 0 ; n < all_x.length ; n++) { // for each direction + int x = all_x[n]; + int y = all_y[n]; + boolean blocked = false; + int i = 1; + while (i < 8 && !blocked) { // continues "as a ray" in that direction until blocked + arrival = new Position(p.getX() + (x * i), p.getY() + (y * i)); + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { + moves.add(arrival); + } + if(b.isKing(arrival) && !b.getPiece(arrival).hasBeenMoved() && !hasBeenMoved) { // Castling + moves.add(arrival); + } + if (!b.isFree(arrival)) { + blocked = true; + } + i++; + } + } + + // Full explicit directions version : ---------------------------- + /* int i = 1; boolean left = false; boolean right = false; boolean top = false; boolean down = false; - while (i < 8) { //left - arrival = new Position(p.getX() + i, p.getY()); if (Position.isCorrect(arrival)) { if (!left) { - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } - if (b.isKing(arrival)) { moves.add(arrival); - } } if (!b.isFree(arrival)) { @@ -52,51 +68,45 @@ public class Rook extends Piece { arrival = new Position(p.getX() - i, p.getY()); if (Position.isCorrect(arrival)) { if (!right) { - if (b.isEnnemy(arrival, p) || b.isFree(arrival)) { + if (b.isEnemy(arrival, p) || b.isFree(arrival)) { moves.add(arrival); } if (b.isKing(arrival)) { moves.add(arrival); } } - if (!b.isFree(arrival)) { - right = true; } } - arrival = new Position(p.getX(), p.getY() + i); if (Position.isCorrect(arrival)) { if (!top) { - if (b.isEnnemy(arrival, p)|| b.isFree(arrival)) { + if (b.isEnemy(arrival, p)|| b.isFree(arrival)) { moves.add(arrival); } } - if (!b.isFree(arrival)) { - top = true; } } - arrival = new Position(p.getX(), p.getY() - i); if(Position.isCorrect(arrival)||b.isFree(arrival)) { if (!down) { - if (b.isEnnemy(arrival, p)) { + if (b.isEnemy(arrival, p)) { moves.add(arrival); } } if (!b.isFree(arrival)) { - down = true; } } - i++; } + */ + // ------------------------------------------------------------ return moves; } diff --git a/MavenChess/MavenChess/src/main/java/view/BoardView.java b/MavenChess/MavenChess/src/main/java/view/BoardView.java index 2f5def44276b33dacab6bd120bd5214491999e6d..a0579b8ace412dfc44feea95506d28872c9acce8 100644 --- a/MavenChess/MavenChess/src/main/java/view/BoardView.java +++ b/MavenChess/MavenChess/src/main/java/view/BoardView.java @@ -3,7 +3,11 @@ package view; import javafx.scene.Group; import javafx.scene.shape.*; import model.Board; -import model.Pawn; +import model.Rook; +import model.Knight; +import model.Bishop; +import model.Queen; +import model.King; import model.Piece; import model.Position; @@ -11,58 +15,43 @@ import java.util.ArrayList; public class BoardView { - public static final int BOARD_SIZE = 16, CENTERED_ORIGIN = -BOARD_SIZE*7/2; + public static final int BOARD_SIZE = 16, CENTERED_ORIGIN = -BOARD_SIZE*7/2, BOARD_HEIGHT = -5, GRAVEYARD_HEIGHT = -1; - private TileView[] tiles; // contains all the squares/tiles of the board (visual) - private PieceView[] pieces; // contains all the 3d pieces (visual) + private final TileView[] tiles; // contains all the squares/tiles of the board (visual) + private final PieceView[] pieces; // contains all the 3d pieces (visual) private int black_death_count, white_death_count; // graveyard counter - public BoardView(Custom3dModel model, CustomMaterial material) { + + public BoardView(Custom3dModel model, CustomMaterial material, Board board) { // creates the board squares, and position them properly tiles = new TileView[64]; for(int j = 1 ; j <= 8 ; j++) { - for (int i = 1 ; i <= 8; i++) { - createTile(i, j); + for(int i = 1 ; i <= 8 ; i++){ + createTile(new Position(i, j)); } } resetColor(material); // init/reset the board squares with black and white - // creates the 3d pieces + // creates the 3d pieces (from the board list) pieces = new PieceView[64]; for(int n = 0 ; n < 64 ; n++) { pieces[n] = null; - } - int y; - for(int color = Piece.WHITE; color == Piece.WHITE || color == Piece.BLACK ; color++) { - // placement of pawns - if(color == Piece.WHITE) { y = 2; } else { y = 7; } - for(int x = Position.a ; x <= Position.h ; x++) { - createPiece(x, y, model.get(Custom3dModel.PAWN), color, material); + Piece piece = board.getPiece(n); + if(piece != null) { + int type = Custom3dModel.PAWN; // we can't do switch statement on ".getClass()" + if (piece.getClass() == Rook.class) { type = Custom3dModel.ROOK; } + if (piece.getClass() == Knight.class) { type = Custom3dModel.KNIGHT; } + if (piece.getClass() == Bishop.class) { type = Custom3dModel.BISHOP; } + if (piece.getClass() == Queen.class) { type = Custom3dModel.QUEEN; } + if (piece.getClass() == King.class) { type = Custom3dModel.KING; } + createPiece(piece.getPosition(), piece.getColor(), type, material, model); } - // placement of rook, knight, bishop, queen, king - if(color == Piece.WHITE) { y = 1; } else { y = 8; } - createPiece(Position.a, y, model.get(Custom3dModel.ROOK), color, material); - createPiece(Position.b, y, model.get(Custom3dModel.KNIGHT), color, material); - createPiece(Position.c, y, model.get(Custom3dModel.BISHOP), color, material); - createPiece(Position.d, y, model.get(Custom3dModel.QUEEN), color, material); - createPiece(Position.e, y, model.get(Custom3dModel.KING), color, material); - createPiece(Position.f, y, model.get(Custom3dModel.BISHOP), color, material); - createPiece(Position.g, y, model.get(Custom3dModel.KNIGHT), color, material); - createPiece(Position.h, y, model.get(Custom3dModel.ROOK), color, material); } - // init graveyard empty + // init graveyards as empty black_death_count = 0; white_death_count = 0; } - public void updateAllPieces() { // updates all the pieces, visually, to the right position - for(int j = 1 ; j <= 8 ; j++) { - for (int i = 1; i <= 8; i++) { - updatePiece(new Position(i, j)); - } - } - } - public void updatePiece(Position position) { // updates the piece(i, j), visually, to the right position int id = position.getID(); if(getPiece(id) != null) { @@ -81,21 +70,21 @@ public class BoardView { piece.getObj().setTranslateX(9 * BOARD_SIZE + CENTERED_ORIGIN); piece.getObj().setTranslateZ(-y * BOARD_SIZE*0.65f + BOARD_SIZE*4); } - piece.getObj().setTranslateY(-1); // place at right height (Y axis) on table + piece.getObj().setTranslateY(GRAVEYARD_HEIGHT); // place at right height (Y axis) on table } - public void createTile(int x, int y) { - // creates a tile and inits the right size and position - Box box = new Box(BOARD_SIZE, BOARD_SIZE / 2, BOARD_SIZE); - box.setTranslateX((x-1) * BOARD_SIZE + CENTERED_ORIGIN); - box.setTranslateZ((y-1) * BOARD_SIZE + CENTERED_ORIGIN); + public void createTile(Position position) { + // creates a tile and with the right size and position + Box box = new Box(BOARD_SIZE, (double) BOARD_SIZE / 2, BOARD_SIZE); + box.setTranslateX((position.getX()-1) * BOARD_SIZE + CENTERED_ORIGIN); + box.setTranslateZ((position.getY()-1) * BOARD_SIZE + CENTERED_ORIGIN); // sets the tile on the list - setTile(new TileView(box, new Position(x, y))); + setTile(new TileView(box, position)); } - private void createPiece(int x, int y, TriangleMesh mesh, int color, CustomMaterial material) { - // creates a piece, and inits materials, drawmode, scale, and the right height (Y axis) - MeshView obj = new MeshView(mesh); + private void createPiece(Position position, int color, int type, CustomMaterial material, Custom3dModel model) { + // creates a piece, 3d-model, materials, draw-mode, scale, and the right height (Y-axis) + MeshView obj = new MeshView(model.get(type)); obj.setDrawMode(DrawMode.FILL); if(color == Piece.WHITE) obj.setMaterial(material.get(CustomMaterial.WHITE)); @@ -103,25 +92,20 @@ public class BoardView { obj.setMaterial(material.get(CustomMaterial.BLACK)); int scale = 16; // scales the 3d models to a wanted size, to fit a board tile obj.setScaleX(scale); - obj.setScaleY(-scale); // Y axis is down (not up) in javaFX, so we need to reverse object - obj.setScaleZ(-scale); // we reverse Z axis too, "to keep the orientation of the 3-axis vectors", (reversing Y and Z is equivalent of 180° rotation of X axis) - obj.setTranslateY(-5); // place at right height (Y axis) on board + obj.setScaleY(-scale); // Y-axis is down (not up) in javaFX, so we need to reverse object + obj.setScaleZ(-scale); // we reverse Z-axis too, "to keep the orientation of the 3-axis vectors", (reversing Y and Z is equivalent of 180° rotation of X-axis) + obj.setTranslateY(BOARD_HEIGHT); // place at right 3d height (Y-axis) on board // if color is black we rotate if(color == Piece.BLACK) { obj.setScaleX(-obj.getScaleX()); obj.setScaleZ(-obj.getScaleZ()); } // sets the piece on the list - Position position = new Position(x, y); setPiece(new PieceView(obj, position, color)); - // updates the right board-tile position x, y (corresponding to X axis and Z axis placements) + // updates piece on the right visual position (corresponding to X-axis and Z-axis placements in 3d) updatePiece(position); } - public TileView[] getTiles() { - return tiles; - } - public TileView getTile(int id) { return tiles[id]; } @@ -134,10 +118,6 @@ public class BoardView { tiles[tile.getPosition().getID()] = tile; } - public PieceView[] getPieces() { - return pieces; - } - public PieceView getPiece(int id) { return pieces[id]; } @@ -155,24 +135,26 @@ public class BoardView { for (int i = 1; i <= 8; i++, n++) { // resets board with black and white - bottom left (first case) is black, then alternates if((i + j) % 2 == 0) { - getTileObj(n).setMaterial(material.get(CustomMaterial.BOARDBLACK)); - getTile(n).setState(TileView.NORMAL); + getTileObj(n).setMaterial(material.get(CustomMaterial.BLACK_TILE)); // (visually) } else { - getTileObj(n).setMaterial(material.get(CustomMaterial.BOARDWHITE)); - getTile(n).setState(TileView.NORMAL); + getTileObj(n).setMaterial(material.get(CustomMaterial.WHITE_TILE)); // (visually) } + getTile(n).setState(TileView.NORMAL); // (on 'state' attribute) } } } public void setColor(CustomMaterial material, Position position, int type) { - getTileObj(position.getID()).setMaterial(material.get(type)); + int id = position.getID(); + // set the new color-type (visually) + getTileObj(id).setMaterial(material.get(type)); + // save color-type in the "state" attribute of that tile switch(type) { - case CustomMaterial.SELECTED -> getTile(position.getID()).setState(TileView.SELECTED); - case CustomMaterial.MOVABLE -> getTile(position.getID()).setState(TileView.MOVABLE); - case CustomMaterial.ATTACK -> getTile(position.getID()).setState(TileView.ATTACK); - case CustomMaterial.SPECIAL -> getTile(position.getID()).setState(TileView.SPECIAL); - default -> getTile(position.getID()).setState(TileView.NORMAL); + case CustomMaterial.SELECTED_TILE -> getTile(id).setState(TileView.SELECTED); + case CustomMaterial.MOVABLE_TILE -> getTile(id).setState(TileView.MOVABLE); + case CustomMaterial.ATTACK_TILE -> getTile(id).setState(TileView.ATTACK); + case CustomMaterial.SPECIAL_TILE -> getTile(id).setState(TileView.SPECIAL); + default -> getTile(id).setState(TileView.NORMAL); } } @@ -180,19 +162,19 @@ public class BoardView { Position position = clickedPiece.getPosition(); board.setSelected(position); resetColor(material); - setColor(material, position, CustomMaterial.SELECTED); + setColor(material, position, CustomMaterial.SELECTED_TILE); ArrayList<Position> moves = board.getPiece(position).getAvailableMoves(board); for (Position move : moves) { if(board.isFree(move)) { - setColor(material, move, CustomMaterial.MOVABLE); - } else if(board.isEnnemy(move, position)) { - setColor(material, move, CustomMaterial.ATTACK); + setColor(material, move, CustomMaterial.MOVABLE_TILE); + } else if(board.isEnemy(move, position)) { + setColor(material, move, CustomMaterial.ATTACK_TILE); } else { - setColor(material, move, CustomMaterial.SPECIAL); + setColor(material, move, CustomMaterial.SPECIAL_TILE); } // promotion if(board.isPawn(position) && (move.getY() == 8 || move.getY() == 1)) { - setColor(material, move, CustomMaterial.SPECIAL); + setColor(material, move, CustomMaterial.SPECIAL_TILE); } } } diff --git a/MavenChess/MavenChess/src/main/java/view/Custom3dModel.java b/MavenChess/MavenChess/src/main/java/view/Custom3dModel.java index 7ec0d344779259008b17cf46775ff7e956c927e8..d27fa5a8fd321b5756365f842912009a6709777d 100644 --- a/MavenChess/MavenChess/src/main/java/view/Custom3dModel.java +++ b/MavenChess/MavenChess/src/main/java/view/Custom3dModel.java @@ -10,7 +10,7 @@ import java.util.Scanner; public class Custom3dModel { - private TriangleMesh[] model; + private final TriangleMesh[] model; public static final int PAWN = 0, ROOK = 1, KNIGHT = 2, BISHOP = 3, QUEEN = 4, KING = 5; @@ -37,8 +37,8 @@ public class Custom3dModel { TriangleMesh mesh = new TriangleMesh(); mesh.getTexCoords().addAll(0,0,0,0); // setup empty texture UV , we import without texture mesh.getPoints().addAll(0,0,0); // adds a vertex 0 (because files .obj start from vertex 1) - float min = 0, max = 0, y; - ArrayList<Float> vdata = new ArrayList<Float>(); + float max = 0, y; + ArrayList<Float> vertexData = new ArrayList<>(); try { URL url = this.getClass().getResource(filename); File myObj = new File(url.getPath().replaceAll("%20", " ")); @@ -51,9 +51,9 @@ public class Custom3dModel { if(y > max) { max = y; } - vdata.add(Float.parseFloat(data[1]+"f")); - vdata.add(y); - vdata.add(Float.parseFloat(data[3]+"f")); + vertexData.add(Float.parseFloat(data[1]+"f")); + vertexData.add(y); + vertexData.add(Float.parseFloat(data[3]+"f")); } else if(data[0].equals("f")) { mesh.getFaces().addAll( Integer.parseInt(data[1].split("/")[0]), 0, @@ -63,17 +63,19 @@ public class Custom3dModel { } } myReader.close(); - } catch (FileNotFoundException e) { + } catch (FileNotFoundException | NullPointerException e) { System.out.println("Error while importing .obj file"); e.printStackTrace(); } + // replaces height (Y-axis) properly, + // it seems that javaFX tries to modify height to center models, so, we counter it for alignment purposes int n = 0; - for(float v : vdata) { - if(n == 1) { - mesh.getPoints().addAll(v+max); + for(float vertex : vertexData) { + if(n == 1) { // only for Y (in 'X Y Z', as '0 1 2') + mesh.getPoints().addAll(vertex + max); } else { - mesh.getPoints().addAll(v); + mesh.getPoints().addAll(vertex); } n = (n + 1) % 3; } diff --git a/MavenChess/MavenChess/src/main/java/view/CustomCamera.java b/MavenChess/MavenChess/src/main/java/view/CustomCamera.java index f4eba9fa15ec379583f895a46e769c608b798fc2..6aef910994eb6fd35706956a5d122a3ca670dcbf 100644 --- a/MavenChess/MavenChess/src/main/java/view/CustomCamera.java +++ b/MavenChess/MavenChess/src/main/java/view/CustomCamera.java @@ -10,12 +10,12 @@ import javafx.scene.transform.Translate; public class CustomCamera { - private PerspectiveCamera camera; - private Group group; // used to rotate camera from 0,0,0 and not from camera x,y,z + private final PerspectiveCamera camera; + private final Group group; // used to rotate camera from 0,0,0 and not from camera x,y,z private double anchorX, anchorY, anchorAngleX, anchorAngleY; private final static double SCROLL_SPEED = 10; - private DoubleProperty angleX, angleY; + private final DoubleProperty angleX, angleY; public CustomCamera(int nearClip, int farClip, int fov) { camera = new PerspectiveCamera(true); camera.setFieldOfView(fov); @@ -29,10 +29,6 @@ public class CustomCamera { angleY = new SimpleDoubleProperty(8); } - public Group getGroup() { - return group; - } - public PerspectiveCamera getCamera() { return camera; } diff --git a/MavenChess/MavenChess/src/main/java/view/CustomLight.java b/MavenChess/MavenChess/src/main/java/view/CustomLight.java index ab79cb23455720e9dfd7d0d34f4d5bd359bf93cd..dddfbf4d30f282de56fffef9b864b59a42609828 100644 --- a/MavenChess/MavenChess/src/main/java/view/CustomLight.java +++ b/MavenChess/MavenChess/src/main/java/view/CustomLight.java @@ -3,14 +3,12 @@ package view; import javafx.scene.AmbientLight; import javafx.scene.Group; import javafx.scene.PointLight; -import javafx.scene.SpotLight; import javafx.scene.paint.Color; import javafx.scene.transform.Translate; public class CustomLight { AmbientLight ambient; PointLight[] light; - SpotLight spot; public CustomLight() { ambient = new AmbientLight(Color.rgb(35, 35, 35)); light = new PointLight[3]; @@ -20,12 +18,10 @@ public class CustomLight { light[0].getTransforms().add(new Translate(-100, -50, 100)); light[1].getTransforms().add(new Translate(0, -60, -100)); light[2].getTransforms().add(new Translate(100, -50, 100)); - spot = new SpotLight(Color.rgb(255,0,0)); - spot.getTransforms().add(new Translate(0, -50, 0)); } public void addAllToScene(Group group) { - // PS : javaFX have max HARDCAP of 3 pointlight/spotlights, and 1 ambient + // PS : javaFX have max HARD cap of 3 point-light/spot-light, and 1 ambient group.getChildren().addAll(light[0], light[1], light[2], ambient); } } diff --git a/MavenChess/MavenChess/src/main/java/view/CustomMaterial.java b/MavenChess/MavenChess/src/main/java/view/CustomMaterial.java index 8acfa80c8d364ed6f1f0c0a0ef78c3be8c020461..0302968fa94f2293407f7cbfec7db1eecdf92b31 100644 --- a/MavenChess/MavenChess/src/main/java/view/CustomMaterial.java +++ b/MavenChess/MavenChess/src/main/java/view/CustomMaterial.java @@ -8,8 +8,8 @@ public class CustomMaterial { private static PhongMaterial[] material; public static final int - BLACK = 0, WHITE = 1, SELECTED = 2, MOVABLE = 3, - ATTACK = 4, SPECIAL = 5, BOARDBLACK = 6, BOARDWHITE = 7, WOOD = 8; + BLACK = 0, WHITE = 1, SELECTED_TILE = 2, MOVABLE_TILE = 3, + ATTACK_TILE = 4, SPECIAL_TILE = 5, BLACK_TILE = 6, WHITE_TILE = 7, WOOD = 8; private static final int MATERIAL_LENGTH = 9; public CustomMaterial() { @@ -18,18 +18,18 @@ public class CustomMaterial { material[BLACK].setDiffuseColor(Color.BLACK); material[WHITE] = new PhongMaterial(); material[WHITE].setDiffuseColor(Color.WHITE); - material[SELECTED] = new PhongMaterial(); - material[SELECTED].setDiffuseColor(Color.rgb(50,200,100)); - material[MOVABLE] = new PhongMaterial(); - material[MOVABLE].setDiffuseColor(Color.rgb(50,240,0)); - material[ATTACK] = new PhongMaterial(); - material[ATTACK].setDiffuseColor(Color.rgb(200,50,50)); - material[SPECIAL] = new PhongMaterial(); - material[SPECIAL].setDiffuseColor(Color.rgb(120,20,255)); - material[BOARDBLACK] = new PhongMaterial(); - material[BOARDBLACK].setDiffuseColor(Color.grayRgb(64)); - material[BOARDWHITE] = new PhongMaterial(); - material[BOARDWHITE].setDiffuseColor(Color.grayRgb(200)); + material[SELECTED_TILE] = new PhongMaterial(); + material[SELECTED_TILE].setDiffuseColor(Color.rgb(50,200,100)); + material[MOVABLE_TILE] = new PhongMaterial(); + material[MOVABLE_TILE].setDiffuseColor(Color.rgb(50,240,0)); + material[ATTACK_TILE] = new PhongMaterial(); + material[ATTACK_TILE].setDiffuseColor(Color.rgb(200,50,50)); + material[SPECIAL_TILE] = new PhongMaterial(); + material[SPECIAL_TILE].setDiffuseColor(Color.rgb(120,20,255)); + material[BLACK_TILE] = new PhongMaterial(); + material[BLACK_TILE].setDiffuseColor(Color.grayRgb(64)); + material[WHITE_TILE] = new PhongMaterial(); + material[WHITE_TILE].setDiffuseColor(Color.grayRgb(200)); material[WOOD] = new PhongMaterial(); material[WOOD].setDiffuseMap(new Image("/wood.jpg")); diff --git a/MavenChess/MavenChess/src/main/java/view/CustomScene.java b/MavenChess/MavenChess/src/main/java/view/CustomScene.java index 974c03ed5fc2e2a22358a952ad84cf3c9ca0c4bc..30def40d9e0978fd5638893fa86f73edd80dd0cb 100644 --- a/MavenChess/MavenChess/src/main/java/view/CustomScene.java +++ b/MavenChess/MavenChess/src/main/java/view/CustomScene.java @@ -7,7 +7,7 @@ import javafx.scene.SceneAntialiasing; import javafx.scene.paint.Color; public class CustomScene { - private Scene scene; + private final Scene scene; public CustomScene(Group group, PerspectiveCamera camera, SceneAntialiasing antialiasing) { scene = new Scene(group, 800, 500, true, antialiasing); // create scene scene.setFill(Color.rgb(50, 50, 50)); // background default color diff --git a/MavenChess/MavenChess/src/main/java/view/Desk.java b/MavenChess/MavenChess/src/main/java/view/Desk.java index 78565b7a93fa3fd2a9d922e467e55cbda12814fb..06def99af1b9705fedf042e7f64e3daddb60a62d 100644 --- a/MavenChess/MavenChess/src/main/java/view/Desk.java +++ b/MavenChess/MavenChess/src/main/java/view/Desk.java @@ -4,11 +4,11 @@ import javafx.scene.Group; import javafx.scene.shape.Box; public class Desk { - private Box desk; + private final Box desk; public Desk(CustomMaterial material) { int table_size = BoardView.BOARD_SIZE*12; desk = new Box(table_size*2, BoardView.BOARD_SIZE, table_size); - desk.translateYProperty().set(BoardView.BOARD_SIZE/2); + desk.translateYProperty().set((double) BoardView.BOARD_SIZE /2); desk.setMaterial(material.get(CustomMaterial.WOOD)); } diff --git a/MavenChess/MavenChess/src/main/java/view/TileView.java b/MavenChess/MavenChess/src/main/java/view/TileView.java index 31a1646c4221ee448683199be7fb1e0d33e4b0d1..d92276eb1bb4c1c82b4a5e2bc32f9f67ab69de31 100644 --- a/MavenChess/MavenChess/src/main/java/view/TileView.java +++ b/MavenChess/MavenChess/src/main/java/view/TileView.java @@ -5,8 +5,8 @@ import model.Position; public class TileView { - private Box obj; - private Position position; + private final Box obj; + private final Position position; private int state; public static final int NORMAL = 0, SELECTED = 1, MOVABLE = 2, ATTACK = 3, SPECIAL = 4; diff --git a/MavenChess/MavenChess/target/classes/controller/Main.class b/MavenChess/MavenChess/target/classes/controller/Main.class index 7e602f090202b3207e258b6d0ef9a9e73c90bf9e..1021ecf5800bb5235d0702489ee5928b761d82ea 100644 Binary files a/MavenChess/MavenChess/target/classes/controller/Main.class and b/MavenChess/MavenChess/target/classes/controller/Main.class differ diff --git a/MavenChess/MavenChess/target/classes/model/Bishop.class b/MavenChess/MavenChess/target/classes/model/Bishop.class index 398d50bd457f077c36e29485a75dfac67ee15440..832b9497d29b38de2956a0abe0267ae57755b1ad 100644 Binary files a/MavenChess/MavenChess/target/classes/model/Bishop.class and b/MavenChess/MavenChess/target/classes/model/Bishop.class differ diff --git a/MavenChess/MavenChess/target/classes/model/Board.class b/MavenChess/MavenChess/target/classes/model/Board.class index 50215dddae1418b33ede47485b465cdb3d5f4022..1407815545854fd1dd5a89e16d2f19e127a9ecb9 100644 Binary files a/MavenChess/MavenChess/target/classes/model/Board.class and b/MavenChess/MavenChess/target/classes/model/Board.class differ diff --git a/MavenChess/MavenChess/target/classes/model/King.class b/MavenChess/MavenChess/target/classes/model/King.class index 2b7365022be2e1d12fc9d6144b60ef72220043f0..d65b114ff0c54a6ee0ff7a82f114683e338e82a4 100644 Binary files a/MavenChess/MavenChess/target/classes/model/King.class and b/MavenChess/MavenChess/target/classes/model/King.class differ diff --git a/MavenChess/MavenChess/target/classes/model/Knight.class b/MavenChess/MavenChess/target/classes/model/Knight.class index 09ed6279d228976b0614f6977c88b26d6efd00ac..a2fb5a72f9b96f88fa01675125be2b18fe9d8c6b 100644 Binary files a/MavenChess/MavenChess/target/classes/model/Knight.class and b/MavenChess/MavenChess/target/classes/model/Knight.class differ diff --git a/MavenChess/MavenChess/target/classes/model/Pawn.class b/MavenChess/MavenChess/target/classes/model/Pawn.class index a9d05b2520252001c47ac6dc5354e655d8b2eb69..f60f87c4bf81c0cdab3eaea62436f853ed6b9dc8 100644 Binary files a/MavenChess/MavenChess/target/classes/model/Pawn.class and b/MavenChess/MavenChess/target/classes/model/Pawn.class differ diff --git a/MavenChess/MavenChess/target/classes/model/Piece.class b/MavenChess/MavenChess/target/classes/model/Piece.class index be225fd85e4b2c272930d7561313f34ff749d8fc..c70cfe3367e1cb27e247905ca4d730e0342c589f 100644 Binary files a/MavenChess/MavenChess/target/classes/model/Piece.class and b/MavenChess/MavenChess/target/classes/model/Piece.class differ diff --git a/MavenChess/MavenChess/target/classes/model/Position.class b/MavenChess/MavenChess/target/classes/model/Position.class index f1a4edbd041caca66d157e1c11b2ed2df615a826..bf4b97164c8118351d4b88aa50f9425eaff273f9 100644 Binary files a/MavenChess/MavenChess/target/classes/model/Position.class and b/MavenChess/MavenChess/target/classes/model/Position.class differ diff --git a/MavenChess/MavenChess/target/classes/model/Queen.class b/MavenChess/MavenChess/target/classes/model/Queen.class index ce7f8807817995cd62883140b43a974c44646d23..10479f12d5926eab2359e138d32913df50571a05 100644 Binary files a/MavenChess/MavenChess/target/classes/model/Queen.class and b/MavenChess/MavenChess/target/classes/model/Queen.class differ diff --git a/MavenChess/MavenChess/target/classes/model/Rook.class b/MavenChess/MavenChess/target/classes/model/Rook.class index ee62dd3c32855be4fe2f5261aed520c175275f3d..936be027e604e017fbd32ca0ca0b34308ae8b7a1 100644 Binary files a/MavenChess/MavenChess/target/classes/model/Rook.class and b/MavenChess/MavenChess/target/classes/model/Rook.class differ diff --git a/MavenChess/MavenChess/target/classes/view/BoardView.class b/MavenChess/MavenChess/target/classes/view/BoardView.class index 07076728f78342beebbbcf75905400bb31d83718..658950bedb33ff474e89419b3e918501d22fd96f 100644 Binary files a/MavenChess/MavenChess/target/classes/view/BoardView.class and b/MavenChess/MavenChess/target/classes/view/BoardView.class differ diff --git a/MavenChess/MavenChess/target/classes/view/Custom3dModel.class b/MavenChess/MavenChess/target/classes/view/Custom3dModel.class index b9724d85e6009c24f25759fa7841c0791ab818b8..b56a7c62690b04a4b2304ab7ef8ce2400c8a2049 100644 Binary files a/MavenChess/MavenChess/target/classes/view/Custom3dModel.class and b/MavenChess/MavenChess/target/classes/view/Custom3dModel.class differ diff --git a/MavenChess/MavenChess/target/classes/view/CustomCamera.class b/MavenChess/MavenChess/target/classes/view/CustomCamera.class index 03a2e0653bb42d437418ddfec3bee1441df92cfe..26d3a8efec8aa8c0024ccc05fe267bc80ab29f96 100644 Binary files a/MavenChess/MavenChess/target/classes/view/CustomCamera.class and b/MavenChess/MavenChess/target/classes/view/CustomCamera.class differ diff --git a/MavenChess/MavenChess/target/classes/view/CustomLight.class b/MavenChess/MavenChess/target/classes/view/CustomLight.class index 99527e13383b6d4d8d92231c1c7c93ac223491c5..5dca188028fe0f1b9563d42a38f325d9a1293066 100644 Binary files a/MavenChess/MavenChess/target/classes/view/CustomLight.class and b/MavenChess/MavenChess/target/classes/view/CustomLight.class differ diff --git a/MavenChess/MavenChess/target/classes/view/CustomMaterial.class b/MavenChess/MavenChess/target/classes/view/CustomMaterial.class index 7a14a2eb28337bdc65f227b580d3a20f0ec86851..716c4af3b9b45177c2e298edd4a74ae7fb2c8078 100644 Binary files a/MavenChess/MavenChess/target/classes/view/CustomMaterial.class and b/MavenChess/MavenChess/target/classes/view/CustomMaterial.class differ diff --git a/MavenChess/MavenChess/target/classes/view/CustomScene.class b/MavenChess/MavenChess/target/classes/view/CustomScene.class index 81e4bbefc75c5d8e4dc1702512caeb6ef69af5e9..6f961b88f066934065f9339e26e71c1f847402e7 100644 Binary files a/MavenChess/MavenChess/target/classes/view/CustomScene.class and b/MavenChess/MavenChess/target/classes/view/CustomScene.class differ diff --git a/MavenChess/MavenChess/target/classes/view/Desk.class b/MavenChess/MavenChess/target/classes/view/Desk.class index cb8dfbd1f233a6a57ad1d06b7451d7c9f08f0671..55a49cd16fcf1060e1a916541af1fe10e381ae50 100644 Binary files a/MavenChess/MavenChess/target/classes/view/Desk.class and b/MavenChess/MavenChess/target/classes/view/Desk.class differ diff --git a/MavenChess/MavenChess/target/classes/view/TileView.class b/MavenChess/MavenChess/target/classes/view/TileView.class index d0c63dff6102454b28998207b6a2a891f84e26eb..df2fc8f7e944a9eb86325a43fab5c5685fb402d6 100644 Binary files a/MavenChess/MavenChess/target/classes/view/TileView.class and b/MavenChess/MavenChess/target/classes/view/TileView.class differ