Skip to content

Commit

Permalink
fix: add capturing piece highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
mirko-felice committed Feb 23, 2023
1 parent 8f9ed69 commit 833a09c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Expand Up @@ -17,6 +17,7 @@ object InterfaceConfiguration:
val LightBrownCell: Color = Color.web("#F9D19D")
val DarkBrownCell: Color = Color.web("#D18C47")
val SelectedCell: Color = Color.web("#D5E8D4")
val CapturingCell: Color = Color.web("#F5372A")

/** Images of the ChessGame interface. */
object Images:
Expand Down
Expand Up @@ -6,7 +6,7 @@
*/
package io.github.chess.viewcontroller.fxcomponents.controllers

import io.github.chess.model.moves.Move
import io.github.chess.model.moves.{CaptureMove, CastlingMove, DoubleMove, Move}
import io.github.chess.model.pieces.Piece
import io.github.chess.model.{ChessBoard, Position, moves}
import io.github.chess.util.stateful.StatefulSystem
Expand Down Expand Up @@ -110,13 +110,21 @@ case class ChessBoardController private (
case NoneSelected =>
case PieceSelected(selectedCell, availableMoves) =>
selectedCell.emphasize()
availableMoves.keys.foreach { this.cells.get(_).foreach(_.setMoveAvailableEffect()) }
availableMoves.foreach((position, move) =>
move match
case _: CaptureMove => this.cells.get(position).foreach(_.emphasizeCapture())
case _ => this.cells.get(position).foreach(_.setMoveAvailableEffect())
)

override protected def exitBehavior(state: State): Unit = state match
case NoneSelected =>
case PieceSelected(selectedCell, availableMoves) =>
selectedCell.deemphasize()
availableMoves.keys.foreach { this.cells.get(_).foreach(_.removeMoveAvailableEffect()) }
availableMoves.foreach((position, move) =>
move match
case _: CaptureMove => this.cells.get(position).foreach(_.deemphasize())
case _ => this.cells.get(position).foreach(_.removeMoveAvailableEffect())
)

/** Companion object of [[ChessBoardController]]. */
object ChessBoardController:
Expand Down
Expand Up @@ -71,6 +71,9 @@ case class CellView(cell: GridCell[Pane]):
/** Add an highlighting effect to this cell. */
def emphasize(): Unit = FXUtils.changeColor(this.cell.content, Colors.SelectedCell)

/** Add an highlighting effect of capture to this cell. */
def emphasizeCapture(): Unit = FXUtils.changeColor(this.cell.content, Colors.CapturingCell)

/** Remove the highlighting effect from this cell. */
def deemphasize(): Unit = FXUtils.changeColor(this.cell.content, this.defaultColor)

Expand Down

0 comments on commit 833a09c

Please sign in to comment.