Example #1
0
        protected void ContextMenu_OnClick_For_TileExit(object sender, object e)
        {
            //Converting the button object into menuitem
            var mnu = sender as MenuItem;
            //getting the right click menu(contextmenu) of the option that was clicked(MenuItem)
            ContextMenu MyContextMenu = (ContextMenu)mnu.Parent;
            //get the button of the context btton
            var theButton = MyContextMenu.SourceControl as CustomControl_Button;

            if (OldExitButton != null)
            {
                OldExitButton.DrawBackgroundImage(OldExitButton._PreviousCell.Type);
            }
            OldExitButton = theButton;
            OldExitButton._PreviousCell = OldExitButton.ChildCell;

            //create a cell object with apporiate wall
            Cell cell = new Cell()
            {
                Type = CellType.Exit
            };

            //assign the cell instance to the button
            theButton.ChildCell = cell;
            //     theButton.ChildCell.Type = CellType.Exit;

            LevelDesigner.MyLevel.ExitLocation = LevelDesigner.MyLevel.CellCollection.IndexOf(OldExitButton._PreviousCell);
        }
Example #2
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++;
            }
            {
            }
        }
Example #3
0
        protected void ContextMenu_OnClick_For_Minotaur(object sender, object e)
        {
            var mnu = sender as MenuItem;
            //getting the right click menu(contextmenu) of the option that was clicked(MenuItem)
            ContextMenu MyContextMenu = (ContextMenu)mnu.Parent;
            //get the button of the context btton
            var theButton = MyContextMenu.SourceControl as CustomControl_Button;

            //initiating an instance of Cell class
            if (OldMinotaurButton != null)
            {
                OldMinotaurButton.ClearCharacters();
            }
            OldMinotaurButton        = theButton;
            theButton.ChildCharacter = minotaur;

            LevelDesigner.MyLevel.MinotaurLocation = LevelDesigner.MyLevel.CellCollection.IndexOf(theButton.ChildCell);
        }
Example #4
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();
            }
        }
Example #5
0
        // OnClick function for Cell Buttons
        protected void Button_OnClick_For_Cell(object sender, object e)
        {
            if (this.TheClickedButton != null)
            {
                //converting the sender to button
                CustomControl_Button theButton = sender as CustomControl_Button;
                //initiating an instance of Cell class
                if (this.TheClickedButton.Name == "btn_Theseus")
                {
                    if (OldTheseusButton != null)
                    {
                        OldTheseusButton.ClearCharacters();
                        OldTheseusButton = null;
                    }
                    OldTheseusButton         = theButton;
                    theButton.ChildCharacter = theseus;
                }
                else if (this.TheClickedButton.Name == "btn_Minotaur")
                {
                    if (OldTheseusButton != null)
                    {
                        OldTheseusButton.ClearCharacters();
                        OldTheseusButton = null;
                    }
                    OldTheseusButton         = theButton;
                    theButton.ChildCharacter = minotaur;
                }
                else
                {
                    Cell cell = new Cell();
                    switch (this.TheClickedButton.Name)
                    {
                    case "btn_TileLeft":
                        //Set the type of the instance to CellType.Left
                        cell.Type = CellType.Left;
                        break;

                    case "btn_TileUp":
                        //Set the type of the instance to CellType.Up
                        cell.Type = CellType.Up;
                        break;

                    case "btn_TileBlank":
                        //Set the type of the instance to CellType.Blank
                        //add correct flor tile
                        cell.Type = CellType.Ground;
                        break;

                    case "btn_TileLeftUp":
                        //Set the type of the instance to CellType.LeftUp
                        cell.Type = CellType.LeftUP;
                        break;

                    case "btn_TileExit":
                        //Set the type of the instance to CellType.Exit
                        cell.Type = CellType.Exit;
                        break;
                    }
                    //sets the button
                    theButton.ChildCell = cell;
                }
            }
        }