Example #1
0
        /// <summary>
        /// 画布局
        /// </summary>
        /// <param name="layoutCode"></param>
        /// <param name="container"></param>
        public static void Draw(this long layoutCode, Panel container)
        {
            ChessType chessType;
            long      tempCode = 0;

            for (int r = 0; r < Common.GridRows; r++)
            {
                for (int c = 0; c < Common.GridColumns; c++)
                {
                    int idx = r * Common.GridColumns + c;
                    tempCode  = Common.ChessBit << (idx * 3);
                    chessType = (ChessType)((int)((tempCode & layoutCode) >> (idx * 3)));
                    ChessBase currentChess = chessType.CreateChess();
                    if (chessType != ChessType.Blank)
                    {
                        currentChess.CreateElement(GridSize, 0, (double)c * GridSize, (double)r * GridSize);
                        container.Children.Add(currentChess.Element);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// 初始化布局
        /// </summary>
        /// <param name="container"></param>
        public void Draw(Panel container)
        {
            IDictionary <ChessType, int> chessCountDict = new Dictionary <ChessType, int>(4)
            {
                { ChessType.Square, 0 }, { ChessType.HRect, 0 }, { ChessType.VRect, 0 }, { ChessType.Block, 0 }
            };
            ChessType chessType;
            long      tempCode = 0;

            for (int r = 0; r < Common.GridRows; r++)
            {
                for (int c = 0; c < Common.GridColumns; c++)
                {
                    int idx = r * Common.GridColumns + c;
                    tempCode  = Common.ChessBit << (idx * 3);
                    chessType = (ChessType)((int)((tempCode & this.LayoutCode) >> (idx * 3)));
                    if (chessType != ChessType.Blank)
                    {
                        ChessBase currentChess = chessType.CreateChess();
                        currentChess.Position     = idx;
                        currentChess.NextPosition = idx;
                        currentChess.CreateElement(GridSize, chessCountDict[chessType], (double)(c * GridSize), (double)(r * GridSize));
                        currentChess.Element.DragCompleted += new DragCompletedEventHandler((sender, e) =>
                        {
                            Direction moveDirection = this.GetChessMoveDirection(currentChess, e.HorizontalChange, e.VerticalChange);
                            if (moveDirection != Direction.Hold)
                            {
                                currentChess.SetNewPosition(moveDirection, Common.GridColumns, this.BlankPosition, this.MoveChessToNext);
                            }
                        });
                        container.Children.Add(currentChess.Element);
                        this.ChessList.Add(currentChess);
                        chessCountDict[chessType]++;
                    }
                }
            }
        }