Exemplo n.º 1
0
        private bool tryPlace(int column, int row)
        {
            //判断是否有棋子已压下
            ChessItem chess = getSelectedChess();

            if (null == chess)
            {
                return(false);
            }

            return(Utility.CanMove(snap.Board, chess.Column, chess.Row, column, row));
        }
Exemplo n.º 2
0
        private void refreshBoard()
        {
            var list = new List <UIElement>();

            foreach (var child in chessBoard.Children)
            {
                if (child as ChessItem != null)
                {
                    list.Add(child as UIElement);
                }
            }
            foreach (var child in list)
            {
                chessBoard.Children.Remove(child);
            }

            for (int row = 0; row < 10; ++row)
            {
                for (int column = 0; column < 9; ++column)
                {
                    var chess = snap.Board[row * 9 + column];
                    if (0 == chess)
                    {
                        continue;
                    }
                    var shape = new ChessItem();
                    shape.Type                  = chess;
                    shape.Column                = column;
                    shape.Row                   = row;
                    shape.Margin                = new Thickness(column * 40 - 18, row * 40 - 18, 0, 0);
                    shape.Width                 = 36;
                    shape.Height                = 36;
                    shape.CanCheck              = Utility.IsRed(shape.Type) == snap.RedTurn;
                    shape.ChessCheckedHandlers += OnChessChecked;
                    chessBoard.Children.Add(shape);
                }
            }
        }