Skip to content
Snippets Groups Projects
Commit 0363bcf6 authored by MasterPyo's avatar MasterPyo
Browse files

clic on red/purple target works now + graveyard pieces can't be clicked now

parent 712b7f63
No related merge requests found
...@@ -94,25 +94,38 @@ public class Main extends Application { ...@@ -94,25 +94,38 @@ public class Main extends Application {
} }
public void clickPiece(PieceView clickedPiece) { public void clickPiece(PieceView clickedPiece) {
// clicking a piece will ask her available moves
Position position = clickedPiece.getPosition(); // graveyard pieces should not do anything
board.setSelected(position); if(clickedPiece.getPosition().getX() < 0) {
boardView.resetColor(material); return;
boardView.setColor(material, position, CustomMaterial.SELECTED_TILE); }
ArrayList<Position> moves = board.getPiece(position).getAvailableMoves(board); // if piece is an "attack" or "special" target, we consider it an action to apply (tile click)
if(clickedPiece.isTargeted()) {
// shows all available moves on the tiles, with colors, each tile-color having a meaning clickTile(boardView.getTile(clickedPiece.getPosition().getID()));
for (Position move : moves) { }
if(board.isFree(move)) { else {
boardView.setColor(material, move, CustomMaterial.MOVABLE_TILE); // clicking a piece will ask her available moves
} else if(board.isEnemy(move, position)) { Position position = clickedPiece.getPosition();
boardView.setColor(material, move, CustomMaterial.ATTACK_TILE); board.setSelected(position);
} else { boardView.resetColor(material);
boardView.setColor(material, move, CustomMaterial.SPECIAL_TILE); // any special move boardView.setColor(material, position, CustomMaterial.SELECTED_TILE);
} ArrayList<Position> moves = board.getPiece(position).getAvailableMoves(board);
// PROMOTION (attacking or not)
if(board.isPawn(position) && (move.getY() == 8 || move.getY() == 1)) { // shows all available moves on the tiles, with colors, each tile-color having a meaning
boardView.setColor(material, move, CustomMaterial.SPECIAL_TILE); for (Position move : moves) {
if (board.isFree(move)) {
boardView.setColor(material, move, CustomMaterial.MOVABLE_TILE);
} else if (board.isEnemy(move, position)) {
boardView.setColor(material, move, CustomMaterial.ATTACK_TILE);
boardView.getPiece(move.getID()).setTargeted(material, CustomMaterial.ATTACK_TILE);
} else {
boardView.setColor(material, move, CustomMaterial.SPECIAL_TILE); // any special move
boardView.getPiece(move.getID()).setTargeted(material, CustomMaterial.SPECIAL_TILE);
}
// PROMOTION (attacking or not)
if (board.isPawn(position) && (move.getY() == 8 || move.getY() == 1)) {
boardView.setColor(material, move, CustomMaterial.SPECIAL_TILE);
}
} }
} }
} }
...@@ -129,6 +142,7 @@ public class Main extends Application { ...@@ -129,6 +142,7 @@ public class Main extends Application {
if(arrival.getY() == 8 || arrival.getY() == 1) { if(arrival.getY() == 8 || arrival.getY() == 1) {
// --- ATTACK (while doing promotion) --- // --- ATTACK (while doing promotion) ---
if (!board.isFree(arrival)) { if (!board.isFree(arrival)) {
boardView.getPiece(arrival.getID()).resetTargeted(material); // reset color
boardView.killPiece(arrival); // place piece on graveyard (visual) boardView.killPiece(arrival); // place piece on graveyard (visual)
} }
// Promotion to Queen (by default, Queen for now) // Promotion to Queen (by default, Queen for now)
...@@ -179,6 +193,7 @@ public class Main extends Application { ...@@ -179,6 +193,7 @@ public class Main extends Application {
else { else {
// --- ATTACK --- // --- ATTACK ---
if(state == TileView.ATTACK) { if(state == TileView.ATTACK) {
boardView.getPiece(arrival.getID()).resetTargeted(material); // reset color
boardView.killPiece(arrival); // place piece on graveyard (visual) boardView.killPiece(arrival); // place piece on graveyard (visual)
} }
// --- MOVE --- // --- MOVE ---
......
...@@ -21,7 +21,6 @@ public class BoardView { ...@@ -21,7 +21,6 @@ public class BoardView {
createTile(new Position(i, j)); createTile(new Position(i, j));
} }
} }
resetColor(material); // init/reset the board squares with black and white
// creates the 3d pieces (from the board list) // creates the 3d pieces (from the board list)
pieces = new PieceView[64]; pieces = new PieceView[64];
...@@ -41,6 +40,8 @@ public class BoardView { ...@@ -41,6 +40,8 @@ public class BoardView {
// init graveyards as empty // init graveyards as empty
black_death_count = 0; black_death_count = 0;
white_death_count = 0; white_death_count = 0;
resetColor(material); // init/reset the board squares with black and white
} }
public TileView getTile(int id) { public TileView getTile(int id) {
...@@ -131,6 +132,9 @@ public class BoardView { ...@@ -131,6 +132,9 @@ public class BoardView {
getTileObj(n).setMaterial(material.get(CustomMaterial.WHITE_TILE)); // (visually) getTileObj(n).setMaterial(material.get(CustomMaterial.WHITE_TILE)); // (visually)
} }
getTile(n).setState(TileView.NORMAL); // (on 'state' attribute) getTile(n).setState(TileView.NORMAL); // (on 'state' attribute)
if(getPiece(n) != null) {
getPiece(n).resetTargeted(material); // reset the 3d pieces color too (visual)
}
} }
} }
} }
......
package view; package view;
import javafx.scene.shape.MeshView; import javafx.scene.shape.MeshView;
import model.Piece;
import model.Position; import model.Position;
public class PieceView { public class PieceView {
private MeshView obj; private MeshView obj;
private Position position; private Position position;
private int color; private int color;
private boolean isTargeted;
public PieceView(MeshView obj, Position position, int color) { public PieceView(MeshView obj, Position position, int color) {
this.obj = obj; this.obj = obj;
this.position = position; this.position = position;
this.color = color; this.color = color;
isTargeted = false;
} }
public MeshView getObj() { public MeshView getObj() {
...@@ -37,4 +40,21 @@ public class PieceView { ...@@ -37,4 +40,21 @@ public class PieceView {
public void setColor(int color) { public void setColor(int color) {
this.color = color; this.color = color;
} }
public boolean isTargeted() {
return isTargeted;
}
public void setTargeted(CustomMaterial material, int tileColor) {
isTargeted = true;
obj.setMaterial(material.get(tileColor));
}
public void resetTargeted(CustomMaterial material) {
isTargeted = false;
if(color == Piece.WHITE)
obj.setMaterial(material.get(CustomMaterial.WHITE));
else
obj.setMaterial(material.get(CustomMaterial.BLACK));
}
} }
No preview for this file type
No preview for this file type
No preview for this file type
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment