public void Handle(SquareSelected message)
        {
            var piece = Board.GetPiece(message.Square);

            if (piece != null && piece.ThisPiecesPlayer == Board.CurrentPlayer)
            {
                ChessingtonServices.EventAggregator.Publish(new PieceSelected(message.Square));
                return;
            }

            if (currentPiece == null)
            {
                return;
            }

            var moves = currentPiece.GetAvailableMoves(Board);

            if (moves.Contains(message.Square))
            {
                currentPiece.MoveTo(Board, message.Square);

                ChessingtonServices.EventAggregator.Publish(new PiecesMoved(Board));
                ChessingtonServices.EventAggregator.Publish(new SelectionCleared());
            }
        }
Example #2
0
        public void Handle(SquareSelected message)
        {
            var piece = Board.GetPiece(message.Square);

            if (piece != null && piece.Player == Board.CurrentPlayer)
            {
                ChessingtonServices.EventAggregator.Publish(new PieceSelected(message.Square));
                return;
            }

            if (currentPiece == null)
            {
                return;
            }

            var moves = currentPiece.GetAvailableMoves(Board);

            if (moves.Contains(message.Square))
            {
                currentPiece.MoveTo(Board, message.Square);

                ChessingtonServices.EventAggregator.Publish(new PiecesMoved(Board));
                ChessingtonServices.EventAggregator.Publish(new SelectionCleared());
                if (Check.IsInCheck(Player.White))
                {
                    var whiteKing = Board.FindPiece(Check.Kings[Player.White]);
                    ChessingtonServices.EventAggregator.Publish(new CheckNotification(whiteKing));
                }

                if (Check.IsInCheck(Player.Black))
                {
                    var blackKing = Board.FindPiece(Check.Kings[Player.Black]);
                    ChessingtonServices.EventAggregator.Publish(new CheckNotification(blackKing));
                }
            }
        }