示例#1
0
        protected void createGameBoard(int rows, int columns, bool isloaded)
        {
            if (isloaded != true)
            {
                //creating Level
                LevelDesigner.createLevel(rows, columns);
                LevelDesigner.MyLevel.CreateCells();
            }

            //Clear out the existing controls, we are generating a new table layout
            GameBoard.Controls.Clear();
            GameBoard.ColumnStyles.Clear();
            GameBoard.RowStyles.Clear();

            //Now we will generate the table, setting up the row and column counts first
            GameBoard.ColumnCount = columns;
            GameBoard.RowCount    = rows;

            //creating rows
            for (int y = 0; y < LevelDesigner.MyLevel.Height; y++)
            {
                //create a row
                GameBoard.ColumnStyles.Add(new ColumnStyle(SizeType.Percent));

                //creating columns
                for (int x = 0; x < LevelDesigner.MyLevel.Width; x++)
                {
                    //create the grid
                    CustomControl_Button btn_Cell = new CustomControl_Button()
                    {
                        Name = count.ToString()
                    };

                    //adding the cells from cell collection to the btn
                    btn_Cell.ChildCell = LevelDesigner.MyLevel.CellCollection[count];

                    //setting the button size
                    btn_Cell.Size    = new Size(40, 40);
                    btn_Cell.Padding = new Padding(0);
                    btn_Cell.Margin  = new Padding(0);
                    btn_Cell.Click  += Button_OnClick_For_Cell;

                    MenuItem m1 = new MenuItem("LeftTile", new EventHandler(ContextMenu_OnClick_For_TileLeft));
                    MenuItem m2 = new MenuItem("UpTile", new EventHandler(ContextMenu_OnClick_For_TileUp));
                    MenuItem m3 = new MenuItem("BlankTile", new EventHandler(ContextMenu_OnClick_For_TileBlank));
                    MenuItem m4 = new MenuItem("LeftUpTile", new EventHandler(ContextMenu_OnClick_For_TileLeftUp));
                    MenuItem m5 = new MenuItem("Exit", new EventHandler(ContextMenu_OnClick_For_TileExit));
                    MenuItem m6 = new MenuItem("Theseus", new EventHandler(ContextMenu_OnClick_For_Theseus));
                    MenuItem m7 = new MenuItem("Minotaur", new EventHandler(ContextMenu_OnClick_For_Minotaur));

                    btn_Cell.ContextMenu = new System.Windows.Forms.ContextMenu();
                    btn_Cell.ContextMenu.MenuItems.Add(m1);
                    btn_Cell.ContextMenu.MenuItems.Add(m2);
                    btn_Cell.ContextMenu.MenuItems.Add(m3);
                    btn_Cell.ContextMenu.MenuItems.Add(m4);
                    btn_Cell.ContextMenu.MenuItems.Add(m5);
                    btn_Cell.ContextMenu.MenuItems.Add(m6);
                    btn_Cell.ContextMenu.MenuItems.Add(m7);

                    //Finally, add the control to the correct location in the table
                    GameBoard.Controls.Add(btn_Cell, x, y);
                    count += 1;
                }
            }
            if (isloaded != true)
            {
                //AddBorders();
                theseus  = new Theseus();
                minotaur = new Minotaur();
            }
        }