Esempio n. 1
0
        private void update_list()
        {
            ConnDatabase    bd   = new ConnDatabase();
            List <string[]> path = bd.selectPuzzlesByComplexity(level);
            string          s    = "";

            // заполняем список изображениями
            listBox1.Items.Clear();
            foreach (string[] file in path)
            {
                s = "";
                if (file[1][0] == '1')
                {
                    s += "Лёгкий";
                }
                else if (file[1][0] == '2')
                {
                    s += "Средний";
                }
                else
                {
                    s += "Сложный";
                }
                s += ", " + bd.cutExcessSpace(file[2]) + ", " + bd.cutExcessSpace(file[4]) + " x " + bd.cutExcessSpace(file[5]);

                listBox1.Items.Add(s);
            }
        }
Esempio n. 2
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //добавить обработку сейвов

            ConnDatabase    bd   = new ConnDatabase();
            List <string[]> puzz = bd.selectPuzzlesByComplexity(level);

            if ((listBox1.SelectedIndex < puzz.Count) && (listBox1.SelectedIndex > -1))
            {
                string[] selected = puzz.ElementAt(listBox1.SelectedIndex);
                forma         = bd.cutExcessSpace(selected[2]);
                textBox1.Text = "";
                if (selected[1][0] == '1')
                {
                    textBox1.Text += "Лёгкий";
                }
                else if (selected[1][0] == '2')
                {
                    textBox1.Text += "Средний";
                }
                else
                {
                    textBox1.Text += "Сложный";
                }
                textBox1.Text += " \r\n" + bd.cutExcessSpace(selected[2]) + " \r\n" + bd.cutExcessSpace(selected[4]) + " x " + bd.cutExcessSpace(selected[5]);
                string path = bd.selectPathByIdPicture(selected[3]);
                Bitmap MyImage;
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                MyImage           = new Bitmap(path);
                pictureBox1.Image = (Image)MyImage;
                id_puzzle_curr    = selected[0];
                button2.Enabled   = true;
                List <string> saved_game = bd.selectAllAboutGameByLoginAndIdPuzzle(login, selected[0]);
                if (saved_game.Count > 0)
                {
                    button1.Enabled = true;
                    button1.Visible = true;
                    textBox1.Text  += " \r\n" + bd.cutExcessSpace(saved_game[0]);
                    textBox1.Text  += " \r\n" + bd.cutExcessSpace(saved_game[1]);
                    textBox1.Text  += " \r\nРезультат:" + bd.cutExcessSpace(saved_game[2]);
                    button2.Text    = "Начать заново";
                }
                else
                {
                    button1.Enabled = false;
                    button1.Visible = false;
                    button2.Text    = "Играть!";
                }
            }
            else
            {
                button2.Enabled = false;
            }
        }
Esempio n. 3
0
        public Recorde()
        {
            InitializeComponent();
            while (dataGridView1.Rows.Count > 1)
            {
                for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                {
                    dataGridView1.Rows.Remove(dataGridView1.Rows[i]);
                }
            }
            ConnDatabase    bd  = new ConnDatabase();
            List <string[]> res = new List <string[]>();


            res.Clear();
            res = bd.selectResultOfUsersByGamemode();

            foreach (string[] s in res)
            {
                if (s[1][0] != ' ')
                {
                    for (int i = 0; i < s.Length; i++)
                    {
                        s[i] = bd.cutExcessSpace(s[i]);
                    }
                    dataGridView1.Rows.Add(s);
                }
            }
        }
Esempio n. 4
0
        public ReadyPuzzles()
        {
            InitializeComponent();
            dataGridView1.RowTemplate.Height = 150;
            List <string[]> res = bd.selectPuzzlesByComplexity("");
            int             x   = 0;

            foreach (string[] s in res)
            {
                dataGridView1.Rows.Add();

                Bitmap MyImage;
                MyImage = new Bitmap(bd.selectPathByIdPicture(s[3]));
                Bitmap image2 = new Bitmap(MyImage, 200, 150);
                dataGridView1[0, x].Value = image2;
                dataGridView1[1, x].Value = bd.cutExcessSpace(s[1]);
                dataGridView1[2, x].Value = bd.cutExcessSpace(s[2]);
                dataGridView1[3, x].Value = bd.cutExcessSpace(s[4]) + " x " + bd.cutExcessSpace(s[5]);
                x++;
            }
        }
Esempio n. 5
0
        public Profiles()
        {
            InitializeComponent();
            List <string[]> res = bd.selectAllUsersAndResults();

            foreach (string[] s in res)
            {
                for (int i = 0; i < s.Length; i++)
                {
                    s[i] = bd.cutExcessSpace(s[i]);
                }
                dataGridView1.Rows.Add(s);
            }
        }
Esempio n. 6
0
        public void updateListView()
        {
            ConnDatabase    bd   = new ConnDatabase();
            List <string[]> path = bd.selectPathToPicturesByComplexityOrder(comboBox2.SelectedItem.ToString());
            string          s    = "";

            // заполняем список изображениями
            listView1.Clear();
            foreach (string[] file in path)
            {
                // установка названия файла
                s  = bd.cutExcessSpace(file[1]) + ", ";
                s += file[0].Remove(0, file[0].LastIndexOf('\\') + 1);
                listView1.Items.Add(s);
            }
        }
Esempio n. 7
0
        private void button1_Click(object sender, EventArgs e)
        {
            string formOfPuzzle = "";
            string width        = "";
            string height       = "";
            string complexity   = "";
            string pictureID    = "";
            string pictureID1   = "";

            if (!((radio_triangle.Checked) | (radio_square.Checked)))
            {
                MessageBox.Show("Выберите форму пазла");
            }
            else
            {
                if (radio_square.Checked)
                {
                    formOfPuzzle = "прямоугольник";
                }
                else
                {
                    formOfPuzzle = "треугольник";
                }

                height = numeric_height.Value.ToString();
                width  = numeric_width.Value.ToString();

                if (!((radio_level3.Checked) | (radio_level2.Checked) | (radio_level1.Checked)))
                {
                    MessageBox.Show("Выберите сложность пазла");
                }
                else
                {
                    if (radio_level3.Checked)
                    {
                        complexity = "3";
                    }
                    else if (radio_level2.Checked)
                    {
                        complexity = "2";
                    }
                    else
                    {
                        complexity = "1";
                    }

                    if (text_picture_id.Text.Equals(""))
                    {
                        MessageBox.Show("Выберите картинку");
                    }
                    else
                    {
                        ConnDatabase bd = new ConnDatabase();
                        pictureID  = bd.selectIdByPathPicture(text_picture_id.Text);
                        pictureID1 = bd.cutExcessSpace(pictureID);
                        string puzzleID = bd.insertInPuzzle(complexity, formOfPuzzle, pictureID1, height, width);
                        if (puzzleID.Equals(""))
                        {
                            MessageBox.Show("Не удалось создать такой пазл!");
                        }
                        else
                        {
                            MessageBox.Show("Пазл успешно создан!");
                            numeric_height.Value   = 3;
                            numeric_width.Value    = 3;
                            radio_level1.Checked   = true;
                            radio_level2.Checked   = false;
                            radio_level3.Checked   = false;
                            radio_triangle.Checked = false;
                            radio_square.Checked   = true;
                            text_picture_id.Text   = "";
                            picture_pazzle.Image   = null;
                        }
                    }
                }
            }
        }
Esempio n. 8
0
        public GameOnField(string id, string game_m, string rec, string log, string form, bool fromSavedGame)
        {
            ConnDatabase bd = new ConnDatabase();

            InitializeComponent();
            ControlMover.Owner = this;

            //верхние пикчербоксы
            List <Bitmap> top = new List <Bitmap>();
            //нижние пикчербоксы
            List <Bitmap> bottom = new List <Bitmap>();
            //верхние пикчербоксы
            List <PicBox> top_pic = new List <PicBox>();
            //нижние пикчербоксы
            List <PicBox> bottom_pic = new List <PicBox>();
            //верхние номера
            List <int> top_num = new List <int>();
            //нижние номера
            List <int> bottom_num = new List <int>();


            if (form.Equals("треугольник"))
            {
                triangle = true;
            }

            id_puzzle = id;
            game_mode = game_m;
            record    = rec;
            login     = log;
            fromGame  = fromSavedGame;
            this.form = form;

            id_picture = bd.selectIdPictureByIdPuzzle(id_puzzle);
            string        path    = bd.selectPathByIdPicture(id_picture);
            List <string> picture = bd.selectSizeAndComplexityFromPuzzleByIdPuzzle(id_puzzle);

            verticalCountOfPieces   = Convert.ToInt32(picture[0]);
            horisontalCountOfPieces = Convert.ToInt32(picture[1]);

            if (bd.cutExcessSpace(picture[2]).Equals("1"))
            {
                complexityKoeff = 10;
            }
            else if (bd.cutExcessSpace(picture[2]).Equals("2"))
            {
                complexityKoeff = 50;
            }
            else
            {
                complexityKoeff = 100;
            }
            if (bd.cutExcessSpace(record).Equals("На очки"))
            {
                //в движениях
                betweenGreatAndNormal = 5;
                betweenNormalAndBad   = 15;
                //потом при подсчете результата число мувов делю на верт*горизонт и сравниваю и домнажаю на бэднормалгуд и на комплексити
            }
            else
            {
                //в секундах
                betweenGreatAndNormal = 20;
                betweenNormalAndBad   = 60;
            }

            int count = 0;

            btm1 = new List <Bitmap>();                                                //нормальный список кусочков пазл
            btm1 = Section.RectangleSection(path, picture[1], picture[0], id_picture); //разрезаем картинку на кусочки
            if (triangle)
            {
                btm = new List <Bitmap>();
                Bitmap[] mass = new Bitmap[2];
                for (int i = 0; i < horisontalCountOfPieces * verticalCountOfPieces; i++)
                {
                    mass = Section.TriangularSection(btm1[i], false);
                    top.Add(mass[0]);
                    bottom.Add(mass[1]);
                }
                count = horisontalCountOfPieces * verticalCountOfPieces * 2;
            }
            else
            {
                btm   = btm1;
                count = horisontalCountOfPieces * verticalCountOfPieces;
            }

            if (fromGame)
            {
                try
                {
                    List <string> saved = bd.selectAllAboutGameByLoginAndIdPuzzle(login, id_puzzle);
                    if (bd.cutExcessSpace(record).Equals("На очки"))
                    {
                        currentmoves = Convert.ToInt32(saved[2]);
                    }
                    else
                    {
                        string hh = "";
                        hh += saved[2][0];
                        hh += saved[2][1];
                        string mm = "";
                        mm += saved[2][3];
                        mm += saved[2][4];
                        string ss = "";
                        ss      += saved[2][6];
                        ss      += saved[2][7];
                        fromSave = new TimeSpan(Convert.ToInt32(hh), Convert.ToInt32(mm), Convert.ToInt32(ss));
                    }
                    //загрузить все кусочки в виде номер - координаты текущие
                    pieces = bd.selectPuzzlePiecesByPuzzleIdAndLogin(id_puzzle, login);
                    string[] buff;
                    //отсортировать по номеру
                    for (int i = 0; i < count; i++)
                    {
                        for (int j = 0; j < count - 1; j++)
                        {
                            if (Convert.ToInt32(pieces[j][0]) > Convert.ToInt32(pieces[j + 1][0]))
                            {
                                buff          = pieces[j];
                                pieces[j]     = pieces[j + 1];
                                pieces[j + 1] = buff;
                            }
                        }
                    }
                }
                catch
                {
                    if (MessageBox.Show("Не удалось загрузить пазл!") == DialogResult.OK)
                    {
                        this.Close();
                    }
                }
            }
            h = btm1[0].Height;
            w = btm1[0].Width;

            int newHeightOfForm = this.Size.Height + h + 30;

            buttonLeft.Location  = new Point(buttonLeft.Location.X, newHeightOfForm - 15 - (h / 2) - buttonLeft.Height - 38);
            buttonRight.Location = new Point(buttonRight.Location.X, newHeightOfForm - 15 - (h / 2) - buttonRight.Height - 38);

            currentLocationOfStripZoneBottomRight = new Point(this.Width - 50, newHeightOfForm - 15 - 38);
            currentLocationOfStripZoneTopLeft     = new Point(50, newHeightOfForm - h - buttonLeft.Height - 38);



            int currH = 0;
            int currW = 0;

            PicBox p  = new PicBox();
            PicBox p1 = new PicBox();

            object[] obj;
            object[] obj1;
            Graphics gr = this.CreateGraphics();

            gr.DrawEllipse(Pens.Black, currW * (w + 1) + 5, currH * (h + 1) + 25, 10, 10);
            Point pp;

            for (int i = 0; i < verticalCountOfPieces * horisontalCountOfPieces; i++)
            {
                if (triangle)
                {
                    p          = new PicBox();
                    p.Size     = new Size(w, h);
                    p.SizeMode = PictureBoxSizeMode.StretchImage;
                    p.Image    = (Image)top[i];
                    top_pic.Add(p);

                    p1          = new PicBox();
                    p1.Size     = new Size(w, h);
                    p1.SizeMode = PictureBoxSizeMode.StretchImage;
                    p1.Image    = (Image)bottom[i];
                    bottom_pic.Add(p1);
                }
                else
                {
                    p          = new PicBox();
                    p.Size     = new Size(w, h);
                    p.SizeMode = PictureBoxSizeMode.StretchImage;
                    p.Image    = (Image)btm[i];
                    pb.Add(p);
                }

                obj  = new object[2];
                obj1 = new object[2];
                if (game_mode == "На ленте")
                {
                    if (fromGame)
                    {
                        if (triangle)
                        {
                            if (((Convert.ToInt32(pieces[i * 2][1]) == 0) && (Convert.ToInt32(pieces[i * 2][2]) == 0)) || (currentLocationOfStripZoneTopLeft.X < Convert.ToInt32(pieces[i * 2][1])) && (Convert.ToInt32(pieces[i * 2][1]) < currentLocationOfStripZoneBottomRight.X) && (currentLocationOfStripZoneTopLeft.Y < Convert.ToInt32(pieces[i * 2][2])) && (Convert.ToInt32(pieces[i * 2][2]) < currentLocationOfStripZoneBottomRight.Y))
                            {
                                //в ленте
                                p.Visible = false;
                                obj[1]    = 'n';
                            }
                            else
                            {
                                p.Visible = true;
                                obj[1]    = 'f';
                            }
                            if (((Convert.ToInt32(pieces[i + i + 1][1]) == 0) && (Convert.ToInt32(pieces[i + i + 1][2]) == 0)) || (currentLocationOfStripZoneTopLeft.X < Convert.ToInt32(pieces[i + i + 1][1])) && (Convert.ToInt32(pieces[i + i + 1][1]) < currentLocationOfStripZoneBottomRight.X) && (currentLocationOfStripZoneTopLeft.Y < Convert.ToInt32(pieces[i + i + 1][2])) && (Convert.ToInt32(pieces[i + i + 1][2]) < currentLocationOfStripZoneBottomRight.Y))
                            {
                                //в ленте
                                p1.Visible = false;
                                obj1[1]    = 'n';
                            }
                            else
                            {
                                p1.Visible = true;
                                obj1[1]    = 'f';
                            }
                        }
                        else
                        {
                            if (((Convert.ToInt32(pieces[i][1]) == 0) && (Convert.ToInt32(pieces[i][2]) == 0)) || (currentLocationOfStripZoneTopLeft.X < Convert.ToInt32(pieces[i][1])) && (Convert.ToInt32(pieces[i][1]) < currentLocationOfStripZoneBottomRight.X) && (currentLocationOfStripZoneTopLeft.Y < Convert.ToInt32(pieces[i][2])) && (Convert.ToInt32(pieces[i][2]) < currentLocationOfStripZoneBottomRight.Y))
                            {
                                //в ленте
                                p.Visible = false;
                                obj[1]    = 'n';
                            }
                            else
                            {
                                p.Visible = true;
                                obj[1]    = 'f';
                            }
                        }
                    }
                    else
                    {
                        if (triangle)
                        {
                            p.Visible  = false;
                            p1.Visible = false;
                        }
                        else
                        {
                            p.Visible = false;
                        }
                        obj[1] = 'n';
                    }
                }
                else
                {
                    if (triangle)
                    {
                        obj[1]  = ' ';
                        obj1[1] = ' ';
                    }
                    else
                    {
                        obj[1] = ' ';
                    }
                }
                pp      = new Point(currW * (w + 1) + 5, currH * (h + 1) + 25);
                obj[0]  = pp;
                obj1[0] = pp;
                if (triangle)
                {
                    p.Tag  = obj;
                    p1.Tag = obj1;
                }
                else
                {
                    p.Tag = obj;
                    serial_number.Add(i);
                }

                if (fromGame)
                {
                    if (triangle)
                    {
                        p.Location = new Point(Convert.ToInt32(pieces[i * 2][1]), Convert.ToInt32(pieces[i * 2][2]));
                        if ((pp.X == p.Location.X) && (pp.Y == p.Location.Y))
                        {
                            p.BorderStyle = BorderStyle.Fixed3D;
                            p.Enabled     = false;
                        }

                        p1.Location = new Point(Convert.ToInt32(pieces[i + i + 1][1]), Convert.ToInt32(pieces[i + i + 1][2]));
                        if ((pp.X == p1.Location.X) && (pp.Y == p1.Location.Y))
                        {
                            p1.BorderStyle = BorderStyle.Fixed3D;
                            p1.Enabled     = false;
                        }
                    }
                    else
                    {
                        p.Location = new Point(Convert.ToInt32(pieces[i][1]), Convert.ToInt32(pieces[i][2]));
                        if ((pp.X == p.Location.X) && (pp.Y == p.Location.Y))
                        {
                            p.BorderStyle = BorderStyle.Fixed3D;
                            p.Enabled     = false;
                        }
                    }
                }

                if (triangle)
                {
                    this.Controls.Add(p);
                    ControlMover.Add(p);
                    this.Controls.Add(p1);
                    ControlMover.Add(p1);
                }
                else
                {
                    this.Controls.Add(pb[i]);
                    ControlMover.Add(pb[i]);
                }
                currW++;
                if (currW == horisontalCountOfPieces)
                {
                    currH++;
                    currW = 0;
                }
            }



            if (!fromGame)
            {
                //тут шафл массива пикчеров и номеров синхронно
                if (triangle)
                {
                    for (int i = 0; i < 2 * verticalCountOfPieces * horisontalCountOfPieces; i += 2)
                    {
                        top_num.Add(i);
                        bottom_num.Add(i + 1);
                    }
                    //перемешивание верхних кусочков
                    syncShuffle <PicBox, int>(top_pic, top_num);
                    //нижние
                    syncShuffle <PicBox, int>(bottom_pic, bottom_num);
                    //объединение
                }
                else
                {
                    syncShuffle <PicBox, int>(pb, serial_number);
                }


                currH = 0;
                currW = 0;

                if (game_mode == "На поле")
                {
                    for (int i = 0; i < verticalCountOfPieces * horisontalCountOfPieces; i++)
                    {
                        if (triangle)
                        {
                            top_pic[i].Location    = new Point(currW * (w + 1) + 5, currH * (h + 1) + 25);
                            bottom_pic[i].Location = new Point(currW * (w + 1) + 5, currH * (h + 1) + 25);
                        }
                        else
                        {
                            pb[i].Location = new Point(currW * (w + 1) + 5, currH * (h + 1) + 25);
                        }

                        currW++;
                        if (currW == horisontalCountOfPieces)
                        {
                            currH++;
                            currW = 0;
                        }
                    }
                    pb.AddRange(top_pic);
                    pb.AddRange(bottom_pic);
                    serial_number.AddRange(top_num);
                    serial_number.AddRange(bottom_num);
                }
                else if (game_mode == "В куче")
                {
                    if (triangle)
                    {
                        for (int i = 0; i < verticalCountOfPieces * horisontalCountOfPieces; i++)
                        {
                            top_pic[i].Location    = new Point(currW * (w + 1) + 5, currH * (h + 1) + 25);
                            bottom_pic[i].Location = new Point(currW * (w + 1) + 5, currH * (h + 1) + 25);


                            currW++;
                            if (currW == horisontalCountOfPieces)
                            {
                                currH++;
                                currW = 0;
                            }
                        }
                        pb.AddRange(top_pic);
                        pb.AddRange(bottom_pic);
                        serial_number.AddRange(top_num);
                        serial_number.AddRange(bottom_num);
                    }
                    else
                    {
                        Random r = new Random();
                        for (int i = 0; i < verticalCountOfPieces * horisontalCountOfPieces; i++)
                        {
                            if (triangle)
                            {
                                top_pic[i].Location    = new Point(r.Next(50, 300), r.Next(50, 300));
                                bottom_pic[i].Location = new Point(r.Next(50, 300), r.Next(50, 300));
                            }
                            else
                            {
                                pb[i].Location = new Point(r.Next(50, 300), r.Next(50, 300));
                            }
                        }
                        pb.AddRange(top_pic);
                        pb.AddRange(bottom_pic);
                        serial_number.AddRange(top_num);
                        serial_number.AddRange(bottom_num);
                    }
                }
                else if (game_mode == "На ленте")
                {
                    pb.AddRange(top_pic);
                    pb.AddRange(bottom_pic);
                    serial_number.AddRange(top_num);
                    serial_number.AddRange(bottom_num);

                    buttonLeft.Enabled = true;
                    buttonLeft.Visible = true;

                    buttonRight.Enabled = true;
                    buttonRight.Visible = true;

                    this.Size = new Size(this.Width, newHeightOfForm);

                    //столько кусочков уместится на ленте
                    countOfPiecesOnStrip = (currentLocationOfStripZoneBottomRight.X - currentLocationOfStripZoneTopLeft.X - 5) / (w + 5);

                    for (int i = 0; i < countOfPiecesOnStrip; i++)
                    {
                        pb[i].Location = new Point(5 + currentLocationOfStripZoneTopLeft.X + i * (w + 5), currentLocationOfStripZoneTopLeft.Y);

                        object[] o = new object[2];
                        o[0]      = ((Point)((object[])pb[i].Tag)[0]);
                        o[1]      = 's';
                        pb[i].Tag = o;

                        pb[i].Visible = true;
                    }
                    currentFirstElementOnStrip = 0;
                }
            }
            else
            {
                if (game_mode == "На ленте")
                {
                    if (triangle)
                    {
                        for (int i = 0; i < 2 * verticalCountOfPieces * horisontalCountOfPieces; i += 2)
                        {
                            top_num.Add(i);
                            bottom_num.Add(i + 1);
                        }
                    }
                    pb.AddRange(top_pic);
                    pb.AddRange(bottom_pic);
                    serial_number.AddRange(top_num);
                    serial_number.AddRange(bottom_num);
                    syncShuffle <PicBox, int>(pb, serial_number);

                    buttonLeft.Enabled = true;
                    buttonLeft.Visible = true;

                    buttonRight.Enabled = true;
                    buttonRight.Visible = true;

                    this.Size = new Size(this.Width, newHeightOfForm);

                    //столько кусочков уместится на ленте
                    countOfPiecesOnStrip = (currentLocationOfStripZoneBottomRight.X - currentLocationOfStripZoneTopLeft.X - 5) / (w + 5);

                    updateStrip();
                }
            }

            //ЗАПУТАЛАСЬ С РАЗМЕТКОЙ ШО ДЕЛАТЬ
            this.Paint   += new PaintEventHandler(Form1_Paint);
            hint          = new PicBox();
            hint.SizeMode = PictureBoxSizeMode.StretchImage;
            hint.Size     = new Size((btm1[0].Width + 1) * horisontalCountOfPieces, (btm1[0].Height + 1) * verticalCountOfPieces);
            hint.Location = new Point(5, 25);
            hint.Image    = Image.FromFile(path);
            hhh           = new Hint(hint);
        }