コード例 #1
0
        private static void loadGameBoard(Level level, object sender, Theseus theseus, Minotaur minotaur)
        {
            int Theseus = level.TheseusLocation;
            int Minotaur = level.MinotaurLocation;
            int Exit = level.ExitLocation;
            int count = 0;

            Button loadButton = sender as Button;
            var theButton = sender as CustomControl_Button;
            Form parentForm = loadButton.FindForm();

            foreach (Cell cell in level.CellCollection)
            {
                theButton = parentForm.Controls.Find(count.ToString(), true).FirstOrDefault() as CustomControl_Button;

                if (Theseus == count)
                {

                    OldTheseusButton = theButton;
                    OldTheseusButton.ChildCharacter = theseus;

                    LevelDesigner.MyLevel.TheseusLocation = LevelDesigner.MyLevel.CellCollection.IndexOf(OldTheseusButton.ChildCell);

                }
                else if (Minotaur == count)
                {
                    OldMinotaurButton = theButton;
                    OldMinotaurButton.ChildCharacter = minotaur;
                    LevelDesigner.MyLevel.MinotaurLocation = LevelDesigner.MyLevel.CellCollection.IndexOf(OldMinotaurButton.ChildCell);

                }
                else if (Exit == count)
                {
                    OldExitButton = theButton;
                    OldExitButton._PreviousCell = theButton.ChildCell;

                    Cell cellll = new Cell() { Type = CellType.Exit };

                    theButton.ChildCell = cellll;

                    LevelDesigner.MyLevel.ExitLocation = LevelDesigner.MyLevel.CellCollection.IndexOf(theButton.ChildCell);

                }

                count++;
            }
                {
            }
        }
コード例 #2
0
        private void btn_Load_Click(object sender, EventArgs e)
        {
            List<string> allLevels = StorageManagement.StorageManagement.getLevelList();
            using (var levelSelect = new LevelSelect(allLevels))
            {
                levelSelect.ShowDialog();
                if (levelSelect.selectedLevelName != null)
                {
                    if (StorageManagement.StorageManagement.loadLevel(levelSelect.selectedLevelName) != null){
                        LevelDesigner.MyLevel = StorageManagement.StorageManagement.loadLevel(levelSelect.selectedLevelName);
                        createGameBoard(LevelDesigner.MyLevel.Height, LevelDesigner.MyLevel.Width, true);
                        comboBox1.Visible = false;
                        btn_Load.Visible = false;
                        isloaded = true;

                        minotaur = new Minotaur();
                        theseus = new Theseus();

                        loadGameBoard(LevelDesigner.MyLevel, sender, theseus, minotaur);

                    }
                }
            }
        }
コード例 #3
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();
            }
        }