/// <summary>
        /// Loads a PCPictureBox type object
        /// </summary>
        /// <param name="row">The maze row that the PCPictureBox will be created at.</param>
        /// <param name="col">The maze column that the PCPictureBox will be created at.</param>
        /// <param name="tileType">The enum that specifies the image.</param>
        /// <returns>Null if the tileType is of type "none", or the loaded PCPictureBox otherwise.</returns>
        private PCPictureBox LoadPictureBox(int row, int col, PictureTypeEnum tileType)
        {
            if (tileType == PictureTypeEnum.None)
            {
                return(null);
            }

            PCPictureBox pictureBox = new PCPictureBox
            {
                Size          = new Size(SQUARE_SIDE_SIZE, SQUARE_SIDE_SIZE),
                BorderStyle   = BorderStyle.FixedSingle,
                SizeMode      = PictureBoxSizeMode.StretchImage,
                PictureRow    = row,
                PictureColumn = col
            };

            pictureBox.Click += new EventHandler(PictureBox_Click);

            pictureBox.SetImage(tileType);

            if (tileType == PictureTypeEnum.GreenBox || tileType == PictureTypeEnum.RedBox)
            {
                pictureBox.Cursor = Cursors.Hand;
            }

            return(pictureBox);
        }
Beispiel #2
0
        /// <summary>
        /// Generates the maze.
        /// </summary>
        /// <param name="xPosition">The distance from the left border of the panel.</param>
        /// <param name="yPosition">The distance from the upper border of the panel.</param>
        /// <param name="numberOfRows">The number of rows to be generated.</param>
        /// <param name="numberOfColumns">The number of columns to be generated.</param>
        private void GenerateMaze(int xPosition, int yPosition, int numberOfRows, int numberOfColumns)
        {
            pnlMaze.Controls.Clear();

            for (int i = 0; i < numberOfRows; i++)
            {
                for (int j = 0; j < numberOfColumns; j++)
                {
                    PCPictureBox pictureBox = new PCPictureBox
                    {
                        Size          = new Size(SQUARE_SIDE_SIZE, SQUARE_SIDE_SIZE),
                        Location      = new Point(xPosition, yPosition),
                        Image         = Properties.Resources.None,
                        BorderStyle   = BorderStyle.FixedSingle,
                        Name          = "pictureBox" + i.ToString() + j.ToString(),
                        SizeMode      = PictureBoxSizeMode.StretchImage,
                        Cursor        = Cursors.Hand,
                        PictureType   = PictureTypeEnum.None,
                        PictureRow    = i,
                        PictureColumn = j
                    };

                    pictureBox.Click += new EventHandler(PictureBox_Click);

                    pnlMaze.Controls.Add(pictureBox);

                    xPosition += SQUARE_SIDE_SIZE;
                }

                yPosition += SQUARE_SIDE_SIZE;
                xPosition  = INITIAL_POSITION;
            }

            pnlToolBox.Enabled = true;
        }
        /// <summary>
        /// Checks if the picture on the side of the selected picture is a door that has the same box' color as the selected picture.
        /// </summary>
        /// <param name="sidePicture">The picture on the side (left, right, up or down) of the selected picture.</param>
        /// <returns>True if the colors are the same, false otherwise.</returns>
        private bool IsRemoveBox(PCPictureBox sidePicture)
        {
            if ((sidePicture.PictureType == PictureTypeEnum.GreenDoor && selectedPicture.PictureType == PictureTypeEnum.GreenBox) ||
                sidePicture.PictureType == PictureTypeEnum.RedDoor && selectedPicture.PictureType == PictureTypeEnum.RedBox)
            {
                return(true);
            }

            return(false);
        }
        private void PictureBox_Click(object sender, EventArgs e)
        {
            PCPictureBox pictureClicked = sender as PCPictureBox;

            if (pictureClicked.PictureType == PictureTypeEnum.GreenBox || pictureClicked.PictureType == PictureTypeEnum.RedBox)
            {
                if (selectedPicture != null)
                {
                    PCPictureBox.UnselectTool(selectedPicture, SQUARE_SIDE_SIZE);
                }

                selectedPicture      = pictureClicked;
                selectedPicture.Left = INITIAL_POSITION + SQUARE_SIDE_SIZE * selectedPicture.PictureColumn;
                selectedPicture.Top  = INITIAL_POSITION + SQUARE_SIDE_SIZE * selectedPicture.PictureRow;

                PCPictureBox.SelectTool(selectedPicture, SQUARE_SIDE_SIZE);
            }
        }
        /// <summary>
        /// Moves the box horizontally or vertically.
        /// </summary>
        /// <param name="displacement">The positive or negative value that displaces the picture (left/right/up/down).</param>
        private void MoveBox(int displacement)
        {
            PCPictureBox sidePicture = isHorizontalMovement
                ? GetTileFromMaze(selectedPicture.PictureRow, selectedPicture.PictureColumn + displacement)
                : GetTileFromMaze(selectedPicture.PictureRow + displacement, selectedPicture.PictureColumn);

            while (sidePicture == null)
            {
                int previousRow = selectedPicture.PictureRow;
                int previousCol = selectedPicture.PictureColumn;
                if (isHorizontalMovement)
                {
                    selectedPicture.PictureColumn += displacement;
                    Thread.Sleep(10);
                    selectedPicture.Left = INITIAL_POSITION + SQUARE_SIDE_SIZE * (selectedPicture.PictureColumn);
                    Thread.Sleep(10);
                    tiles[previousRow, previousCol] = null;
                    tiles[selectedPicture.PictureRow, selectedPicture.PictureColumn] = selectedPicture;
                    sidePicture = GetTileFromMaze(selectedPicture.PictureRow, selectedPicture.PictureColumn + displacement);
                }
                else
                {
                    selectedPicture.PictureRow += displacement;
                    Thread.Sleep(10);
                    selectedPicture.Top = INITIAL_POSITION + SQUARE_SIDE_SIZE * (selectedPicture.PictureRow);
                    Thread.Sleep(10);
                    tiles[previousRow, previousCol] = null;
                    tiles[selectedPicture.PictureRow, selectedPicture.PictureColumn] = selectedPicture;
                    sidePicture = GetTileFromMaze(selectedPicture.PictureRow + displacement, selectedPicture.PictureColumn);
                }
            }
            if (IsRemoveBox(sidePicture))
            {
                RemoveSelectedBoxFromPanel();
                CountBoxes(tiles);
            }
        }
 /// <summary>
 /// Removes the selected box from the panel.
 /// </summary>
 private void RemoveSelectedBoxFromPanel()
 {
     tiles[selectedPicture.PictureRow, selectedPicture.PictureColumn] = null;
     pnlMaze.Controls.Remove(selectedPicture);
     selectedPicture = null;
 }
Beispiel #7
0
 private void pbxGreenBox_Click(object sender, EventArgs e)
 {
     chosenPictureType = PictureTypeEnum.GreenBox;
     UnselectAllTools();
     PCPictureBox.SelectTool(pbxGreenBox, SELECTED_SQUARE_SIDE_SIZE);
 }
Beispiel #8
0
        private void PictureBox_Click(object sender, EventArgs e)
        {
            PCPictureBox pictureClicked = sender as PCPictureBox;

            pictureClicked.SetImage(chosenPictureType);
        }