Example #1
0
        public virtual void Execute(Board <Piece> board, Piece piece, Tile toTile)
        {
            var toPiece  = board.PieceAt(toTile);
            var fromTile = board.TileOf(piece);
            var hasMoved = piece.HasMoved;

            Action forward = () =>
            {
                if (toPiece != null)
                {
                    board.Take(toTile);
                }


                board.Move(fromTile, toTile);

                piece.HasMoved = true;
            };

            Action backward = () =>
            {
                piece.HasMoved = hasMoved;
                board.Move(toTile, fromTile);
                if (toPiece != null)
                {
                    board.Place(toTile, toPiece);
                }
            };

            var replayComand = new DelegateReplayComand(forward, backward);

            ReplayManager.Execute(replayComand);
        }