Exemple #1
0
        // Открытие окна для начала новой игры
        internal void Operation_LoadPicture(FormPuzzle form)
        {
            Difficulty Diff = new Difficulty();

            Diff.Owner = form;
            Diff.ShowDialog();
        }
Exemple #2
0
        internal void function_HintGame(FormPuzzle form)
        {
            if (form.PicPath != null)
            {
                Random Rnd = new Random();
                int    a   = 0;

                if (!IfEnd(form))
                {
l_hint:
                    a = Rnd.Next(0, form.status.Length - 1);

                    if (form.status[a] == false)
                    {
                        if (form.HintNumber != 0)
                        {
                            form.FieldSites[a].Location = new Point(form.Puzzles[a].Location.X, form.Puzzles[a].Location.Y);
                            form.FieldSites[a].Enabled  = false;
                            form.status[a] = true;
                            form.HintNumber--;

                            MessageBox.Show("Осталось подсказок: " + form.HintNumber.ToString(), "Подсказка", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    else
                    {
                        goto l_hint;
                    }
                    function_AttachCell_CheckEnd(form); // проверка конца игры
                }
            }
        }
Exemple #3
0
        internal void Operation_CreateGameCells(FormPuzzle form, int x, int y, PictureBox[] array)   // Генерирование массива с игровой сеткой
        {
            int x1   = x;
            int all  = form.difficulty * form.difficulty;
            int size = 400 / form.difficulty;

            for (int i = 0; i < all; i++)
            {
                array[i]             = new PictureBox();
                array[i].Size        = new Size(size, size);
                array[i].Location    = new Point(x, y);
                array[i].BorderStyle = BorderStyle.FixedSingle;
                array[i].TabIndex    = i;
                form.groupBox1.Controls.Add(array[i]);
                array[i].MouseUp += new MouseEventHandler(form.MouseUp2);
                if ((i + 1) % form.difficulty == 0)
                {
                    y += array[i].Height; x = x1;
                }
                else
                {
                    x += array[i].Width;
                }
            }
        }
Exemple #4
0
        internal void function_SaveGame(FormPuzzle form)
        {
            if (form.PicPath != null && !IfEnd(form))
            {
                int    number_of_puzzles = form.difficulty * form.difficulty;
                string FilePath          = "FileGame";

                if (File.Exists(FilePath))
                {
                    File.Delete(FilePath);
                }

                using (StreamWriter fs = new StreamWriter(FilePath))
                {
                    fs.WriteLine(form.PicPath);
                    fs.WriteLine(form.difficulty);
                    for (int i = 0; i < number_of_puzzles; i++)
                    {
                        fs.WriteLine(form.FieldSites[i].Location.X.ToString());
                        fs.WriteLine(form.FieldSites[i].Location.Y.ToString());
                        fs.WriteLine(form.status[i].ToString());
                    }
                }
                MessageBox.Show("Текущая игра сохранена", "Сохраниение...", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            MessageBox.Show("Нечего сохранять", "Сохраниение...", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemple #5
0
        // Открытие окна для демонстрации оригинала картинки
        internal void Operation_ShowOriginal(FormPuzzle form)
        {
            SourceImage SourceImg = new SourceImage();

            SourceImg.Owner = form;
            SourceImg.ShowDialog();
        }
Exemple #6
0
        private void Button_Load_Play_Click(object sender, EventArgs e)
        {
            FormPuzzle Main = this.Owner as FormPuzzle;

            if (Main != null)
            {
                foreach (Control control in groupBox1.Controls)
                {
                    if (control is RadioButton)
                    {
                        if (((RadioButton)control).Checked)
                        {
                            int diff = int.Parse(control.Tag.ToString());
                            Main.difficulty = diff;

                            break;
                        }
                    }
                }
            }

            OpenFileDialog Dialog = new OpenFileDialog();

            Dialog.Filter      = "jpg|*.jpg|bmp|*.bmp";
            Dialog.FilterIndex = 1;
            if (Dialog.ShowDialog() == DialogResult.OK)
            {
                Main.PicPath = Dialog.FileName;
                this.Close();
            }
        }
Exemple #7
0
        internal void Operation_DeleteCells(FormPuzzle form)                                         // Генерирование массива с игровой сеткой
        {
            form.groupBox1.Enabled = true;
            Array.Clear(form.FieldSites, 0, form.FieldSites.Length);
            Array.Clear(form.Puzzles, 0, form.Puzzles.Length);
            Array.Clear(form.status, 0, form.status.Length);
            Array.Clear(form.cells, 0, form.cells.Length);

            form.groupBox1.Controls.Clear();
        }
Exemple #8
0
        internal void function_StartGame(FormPuzzle form)
        {
            if (form.PicPath != null)
            {
                Facade.DeleteCells(form);
                Facade.CreatePuzzles(form, form.PicPath, form.difficulty, form.difficulty);      //создание и вывод на экран массива пазлов (слева)
                Facade.CreateGameCells(form, 475, 20, form.Puzzles);                             //создание и вывод на экран массива секторов в роли игровой сетки (справа)

                form.sek = 0; form.min = 0; form.hours = 0;
                form.timerPuzzle.Start();
            }
        }
Exemple #9
0
        private void SourceImage_Load(object sender, EventArgs e)
        {
            FormPuzzle Main = this.Owner as FormPuzzle;

            if (Main != null)
            {
                if (Main.PicPath != null)
                {
                    Bitmap BitMP = new Bitmap(Main.PicPath);
                    pictureBoxSource.Image = BitMP;
                }
            }
        }
Exemple #10
0
        internal void function_LoadGame(FormPuzzle form)
        {
            if (MessageBox.Show("Вы действительно хотите загрузить ранее сохраненную игру? Текущий процесс будет утерян!", "Загрузка...", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
            {
                string FilePath = "FileGame";
                if (!File.Exists(FilePath))
                {
                    MessageBox.Show("Нет сохраненной игры!", "Ошибка загрузки", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                using (StreamReader sr = File.OpenText(FilePath))
                {
                    string X, Y = "";
                    int    d, i = 0;

                    form.PicPath    = sr.ReadLine();                  // расположение к картинке
                    d               = Convert.ToInt32(sr.ReadLine()); // уровень сложности
                    form.difficulty = d;

                    X = sr.ReadLine();
                    Y = sr.ReadLine();

                    Facade.DeleteCells(form);
                    Facade.CreatePuzzles(form, form.PicPath, d, d);
                    form.groupBox1.Controls.Clear();

                    while ((X) != null)
                    {
                        form.status[i] = Convert.ToBoolean(sr.ReadLine());
                        if (form.status[i])
                        {
                            form.FieldSites[i].Enabled = false;                 //если пазл был верен, то перемещать нельзя
                        }
                        form.FieldSites[i].Location = new Point(Convert.ToInt32(X), Convert.ToInt32(Y));
                        form.groupBox1.Controls.Add(form.FieldSites[i]);

                        i++;
                        X = sr.ReadLine();
                        Y = sr.ReadLine();
                    }
                    Facade.CreateGameCells(form, 475, 20, form.Puzzles);

                    form.IndexDown = 0;
                    form.sek       = 0; form.min = 0; form.hours = 0;
                    form.timerPuzzle.Start();
                }
            }
        }
Exemple #11
0
        internal bool IfEnd(FormPuzzle form)
        {
            bool flag = form.status[0];

            for (int i = 1; i < form.FieldSites.Length; i++)
            {
                flag = flag && form.status[i];

                if (!flag)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #12
0
        internal void function_AttachCell_CheckEnd(FormPuzzle form)
        {
            int all  = form.difficulty * form.difficulty;
            int size = 400 / form.difficulty;

            for (int i = 0; i < all; i++)
            {
                //попал ли подводимый пазл в область сетки (и отдельного пазла) по координате X
                if ((form.FieldSites[form.IndexDown].Location.X >= form.Puzzles[i].Location.X) && (form.FieldSites[form.IndexDown].Location.X <= form.Puzzles[i].Location.X + size))
                {
                    //попал ли подводимый пазл в область сетки (и отдельного пазла) по координате Y
                    if ((form.FieldSites[form.IndexDown].Location.Y >= form.Puzzles[i].Location.Y) && (form.FieldSites[form.IndexDown].Location.Y <= form.Puzzles[i].Location.Y + size))
                    {
                        //если да, то проверка подводящего пазла на зону крипежки сетки
                        if (Math.Abs((form.Puzzles[i].Location.X - form.FieldSites[form.IndexDown].Location.X)) <= (size - 1) &&
                            Math.Abs((form.Puzzles[i].Location.Y - form.FieldSites[form.IndexDown].Location.Y)) <= (size - 1))
                        {
                            form.FieldSites[form.IndexDown].Location = new Point(form.Puzzles[i].Location.X, form.Puzzles[i].Location.Y); //крипежка пазла на сетку

                            for (int j = 0; j < all; j++)
                            {
                                if (j != form.IndexDown && form.FieldSites[form.IndexDown].Location == form.FieldSites[j].Location)
                                {
                                    form.FieldSites[form.IndexDown].Location = new Point(form.X, form.Y); // если пазл занят, вернуть текущий на место
                                    break;
                                }
                            }


                            if (form.IndexDown == form.Puzzles[i].TabIndex) //если индексы ячеек совпали
                            {
                                form.status[form.IndexDown]             = true;
                                form.FieldSites[form.IndexDown].Enabled = false;
                            }
                        }

                        if (IfEnd(form))
                        {
                            form.timerPuzzle.Stop();
                            MessageBox.Show("Поздравляю! Вы собрали пазл. Ваше время: " + form.toolStripStatusLabel2.Text, "Победа", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            form.toolStripStatusLabel2.Text = "00:00:00";
                            form.groupBox1.Enabled          = false;
                        }
                        break;
                    }
                }
            }
        }
Exemple #13
0
        // Генерирование массива с пазлами
        internal void Operation_CreatePuzzles(FormPuzzle form, string filename, int nx, int ny)
        {
            Random n     = new Random();
            Image  image = Image.FromFile(filename);

            image = ResizeImage(image, 400, 400);

            int w = image.Width;
            int h = image.Height;

            Array.Resize(ref form.FieldSites, form.difficulty * form.difficulty);
            Array.Resize(ref form.Puzzles, form.difficulty * form.difficulty);
            Array.Resize(ref form.status, form.difficulty * form.difficulty);
            Array.Resize(ref form.cells, form.difficulty * form.difficulty);

            form.HintNumber = form.difficulty;

            // координаты по X
            int[] x = new int[nx + 1];
            x[0] = 0;
            for (int i = 1; i <= nx; i++)
            {
                x[i] = (w * i / nx);
            }

            // координаты по Y
            int[] y = new int[ny + 1];
            y[0] = 0;
            for (int i = 1; i <= ny; i++)
            {
                y[i] = (h * i / ny);
            }

            int li = 0;

            while (li < form.cells.Length)
            {
l1:
                int lx = n.Next(0, form.difficulty);
                int ly = n.Next(0, form.difficulty);
                for (int i = 0; i < li; i++)
                {
                    if (form.cells[i].x == lx && form.cells[i].y == ly)
                    {
                        goto l1;
                    }
                }

                form.cells[li].x = lx;
                form.cells[li].y = ly;

                li++;
            }
            ;

            // вспомогательные переменные
            Bitmap   bmp;
            Graphics g;
            int      k    = -1;
            int      size = 400 / form.difficulty;

            // режем
            for (int j = 0; j < nx; j++)
            {
                for (int i = 0; i < ny; i++)
                {
                    // размеры тайла
                    w = x[i + 1] - x[i];
                    h = y[j + 1] - y[j];

                    // тайл
                    bmp = new Bitmap(w, h);

                    // рисуем
                    g = Graphics.FromImage(bmp);
                    g.DrawImage(image, new Rectangle(0, 0, w, h), new Rectangle(x[i], y[j], w, h), GraphicsUnit.Pixel);

                    // сохраняем результат
                    //bmp.Save(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format("image{0}_{1}.png", i, j)), System.Drawing.Imaging.ImageFormat.Png);


                    form.FieldSites[++k] = new PictureBox()
                    {
                        Image       = bmp,
                        SizeMode    = PictureBoxSizeMode.AutoSize,
                        Location    = new Point(x[form.cells[k].x] + 13, y[form.cells[k].y] + 20),
                        BorderStyle = BorderStyle.None,
                        TabIndex    = k
                    };

                    form.FieldSites[k].MouseDown += new MouseEventHandler(form.MouseDown2);
                    form.FieldSites[k].MouseUp   += new MouseEventHandler(form.MouseUp2);
                    form.groupBox1.Controls.Add(form.FieldSites[k]);
                    Move.LearnToMove(form.FieldSites[k]);
                }
            }
            image.Dispose();
        }
Exemple #14
0
 public static void DeleteCells(FormPuzzle form)
 {
     Game.Operation_DeleteCells(form);
 }
Exemple #15
0
 public static void CreateGameCells(FormPuzzle form, int x, int y, PictureBox[] array)
 {
     Game.Operation_CreateGameCells(form, x, y, array);
 }
Exemple #16
0
 public static void CreatePuzzles(FormPuzzle form, string filename, int nx, int ny)
 {
     Game.Operation_CreatePuzzles(form, filename, nx, ny);
 }
Exemple #17
0
 public static void ShowOriginal(FormPuzzle form)
 {
     Game.Operation_ShowOriginal(form);
 }
Exemple #18
0
 public static void LoadPicture(FormPuzzle form)
 {
     Game.Operation_LoadPicture(form);
 }
Exemple #19
0
 public void AttachCell_CheckEnd(FormPuzzle form) // приклейка паззла к сетке и проверка на сопадение пазла
 {
     function_AttachCell_CheckEnd(form);
 }
Exemple #20
0
 public void StartGame(FormPuzzle form)           // запуск игрового процесса
 {
     function_StartGame(form);
 }
Exemple #21
0
 public void SaveGame(FormPuzzle form)            // сохранение текущей игры
 {
     function_SaveGame(form);
 }
Exemple #22
0
 public void HintGame(FormPuzzle form)            // подсказка
 {
     function_HintGame(form);
 }
Exemple #23
0
 public void LoadGame(FormPuzzle form)            // загрузка сохраненной игры
 {
     function_LoadGame(form);
 }