Пример #1
0
        public playForm()
        {
            InitializeComponent();

            BasicGridElementDelta = 70;
            selectedPBox          = new GridObject();
        }
Пример #2
0
        private void PictureClick(object sender, EventArgs e)
        {
            bool       safecounter = false;
            PictureBox oPictureBox = (PictureBox)sender;

            for (int i = 0; i < GridRows - 1; i++)
            {
                if (safecounter == true)
                {
                    break;
                }
                for (int j = 0; j < GridColumns - 1; j++)
                {
                    if (grid[i, j].Location == oPictureBox.Location)
                    {
                        if (grid[i, j] is RedBox || grid[i, j] is GreenBox)
                        {
                            selectedPBox = grid[i, j];
                            safecounter  = true;
                            break;
                        }
                    }
                }
            }

            MessageBox.Show(oPictureBox.Location + "");
        }
Пример #3
0
        private void upBtn_Click(object sender, EventArgs e)
        {
            try
            {
                int  currX       = selectedPBox.Location.X;
                int  currY       = selectedPBox.Location.Y - BasicGridElementDelta;
                bool safecounter = false;//actually there are several more accurate ways to get out of cycle, but this one is the laziest
                for (int i = 0; i < GridRows - 1; i++)
                {
                    if (safecounter)
                    {
                        break;
                    }
                    for (int j = 0; j < GridColumns - 1; j++)
                    {
                        if (grid[i, j].Location == selectedPBox.Location)
                        {
                            if (((Box)grid[i, j]).isGreen)
                            {
                                if (grid[i, j - 1] is NoneEmpty)
                                {
                                    GridObject a            = grid[i, j];
                                    Point      Location_Now = grid[i, j].Location;

                                    grid[i, j]          = grid[i, j - 1];
                                    grid[i, j].Location = grid[i, j - 1].Location;

                                    grid[i, j - 1]          = a;        //there we swap higher element and element we chose(box) and thee locations
                                    grid[i, j - 1].Location = Location_Now;

                                    selectedPBox          = grid[i, j - 1];
                                    selectedPBox.Location = Location_Now;


                                    grid[i, j].Image     = new Bitmap("None.JPG");
                                    grid[i, j - 1].Image = new Bitmap("GreenBox.PNG");
                                    MessageBox.Show("Was Noneempty");
                                }
                                else if (grid[i, j - 1] is GreenDoor)
                                {
                                    grid[i, j] = (NoneEmpty)grid[i, j];
                                }
                            }
                            else if (((Box)grid[i, j]).isRed)
                            {
                                if (grid[i, j - 1] is NoneEmpty)
                                {
                                    GridObject a = grid[i, j];
                                    grid[i, j]           = grid[i, j - 1];
                                    grid[i, j - 1]       = a;                      //there we swap higher element and element we chose(box)
                                    selectedPBox         = grid[i, j - 1];
                                    grid[i, j].Image     = new Bitmap("None.JPG"); //doesn't work, try to change indexes
                                    grid[i, j - 1].Image = new Bitmap("GreenBox.PNG");
                                    MessageBox.Show("Was Noneempty");
                                }
                                else if (grid[i, j - 1] is RedDoor)
                                {
                                    grid[i, j] = (NoneEmpty)grid[i, j];
                                }
                                else
                                {
                                    MessageBox.Show("Wall or box");
                                }
                            }

                            safecounter = true;
                            break;
                        }
                    }
                }
                count++;

                textBox1.Text = count.ToString();
            }
            catch (IndexOutOfRangeException ex)
            {
                MessageBox.Show("Impossible to move out of grid" + ex.Message);
            }
        }