示例#1
0
文件: BoardVM.cs 项目: Fabernaz/Chess
        public void MoveStarted(SquareVM startingSquare)
        {
            _availableSquares = new List <SquareVM>();
            _startingSquare   = startingSquare;

            startingSquare.MovingPiece = true;

            var availableSquares = startingSquare.Piece.GetAvailableMoves();

            foreach (var square in availableSquares)
            {
                var cellVM = Cells.Single(c => c.Position == square);
                cellVM.PlayableMoveForPlayer = true;
                _availableSquares.Add(cellVM);
            }
        }
示例#2
0
        public BoardCellControl(SquareVM vm,
                                IImagesFactory imagesFactory)
        {
            _vm           = vm;
            _board        = vm.Board;
            DataContext   = vm;
            _imageFactory = imagesFactory;

            Position    = vm.Position;
            Background  = GetColorFromVM(vm.Color);
            BorderBrush = System.Windows.Media.Brushes.Black;
            SetGridCoordinate();

            InitializeComponent();

            vm.WhenAny(x => x.Piece, x => x.Value)
            .Subscribe(SetImage);
        }
示例#3
0
 private BoardCellControl GetCellFromVM(SquareVM vm)
 {
     return(new BoardCellControl(vm, _piecesImageFactory));
 }
示例#4
0
 private bool HasRightColorPiece(SquareVM squareVM)
 {
     return(squareVM.Piece != null &&
            squareVM.Piece.Color == squareVM.Board.NextMoveTurn);
 }
示例#5
0
文件: BoardVM.cs 项目: Fabernaz/Chess
 public void OnMoveMade(SquareVM startingCell, SquareVM endingCell)
 {
     _board.TryPlayMove(startingCell.Square, endingCell.Square);
 }