예제 #1
0
        //Начало игры
        private void startgame_Click(object sender, EventArgs e)
        {
            label2.Visible      = false;
            easy.Visible        = false;
            normal.Visible      = false;
            hard.Visible        = false;
            startgame.Visible   = false;
            pictureBox1.Visible = true;
            label1.Visible      = true;
            label3.Visible      = true;
            score.Visible       = true;
            moves.Visible       = true;
            Shop.Visible        = true;
            switch (difficulty)
            {
            case 1: remaining_moves = 5; break;

            case 2: remaining_moves = 2; break;

            case 3: remaining_moves = 1; break;
            }
            toolTip1.SetToolTip(Pickaxe, (1000 * difficulty * 0.5).ToString());
            toolTip1.SetToolTip(Bomb, (1600 * difficulty * 0.5).ToString());
            toolTip1.SetToolTip(Bucket, (3000 * difficulty * 0.5).ToString());
            moves.Text = remaining_moves.ToString();
            GameBoardInitialization();//нарисовать сетку
            GameProcess gameProcess = new GameProcess();

            gameboard = gameProcess.starting_game_board_initialization();
            DrawFallingBalloons_start();
        }
예제 #2
0
        private void DrawDestroyingBalloons()
        {
            DrawingLib drawing     = new DrawingLib();
            int        timer_ticks = 0;

            tDestroy          = new Timer();
            tDestroy.Interval = 30;
            tDestroy.Tick    += new EventHandler((s, e) =>
            {
                //объявить битмап
                Bitmap bmp = new Bitmap(pictureBox1.Image);
                Graphics g = Graphics.FromImage(bmp);
                for (int i = 0; i < match_indexes.Count(); i++)
                {
                    g.FillPie(new SolidBrush(Color.FromArgb(128, 128, 255)), new Rectangle(new Point(match_indexes[i][0] * 42 + 1, match_indexes[i][1] * 42 + 61), new Size(41, 41)), 18 * timer_ticks, 18 * timer_ticks + 1);
                }
                //если бомбы есть - нарисовать
                if (explosion_indexes.Count >= 1)
                {
                    for (int i = 0; i < explosion_indexes.Count; i++)
                    {
                        g.DrawImage(drawing.draw_explosion(timer_ticks, Application.StartupPath.ToString() + "\\Resouses\\Explosion\\explosion" + timer_ticks + ".png"), new Point((explosion_indexes[i][0] - 1) * 42, (explosion_indexes[i][1] - 1) * 42 + 61));
                    }
                }
                pictureBox1.Image = bmp;//вывод на picturebox
                if (timer_ticks == 19)
                {
                    //нарисовать сетку
                    g.DrawImage(drawing.draw_grid(pictureBox1.Width, pictureBox1.Height), new Point(0, 60));
                    //очистить gameboard
                    for (int i = 0; i < match_indexes.Count(); i++)
                    {
                        gameboard[match_indexes[i][0], match_indexes[i][1]] = "";
                    }
                    explosion_indexes.Clear();
                    Timer t = s as Timer;
                    t.Dispose();
                    GameProcess game    = new GameProcess();
                    ballon_falling_span = game.define_falling_balloons(ref gameboard, difficulty);
                    DrawFallingBalloons();
                    tFall.Start();
                }
                else
                {
                    timer_ticks++;
                }
            }
                                                 );
            return;
        }
예제 #3
0
        //Обработчик нажатия игрока на игровое поле
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            GameProcess game = new GameProcess();
            //объявить битмап
            Bitmap   bmp = new Bitmap(pictureBox1.Image);
            Graphics g   = Graphics.FromImage(bmp);

            for (int y = 0; y < 10; y++)
            {
                for (int x = 0; x < 10; x++)
                {
                    //считывание координат
                    if (e.X > x * 42 && e.X < (x + 1) * 42 &&
                        e.Y > y * 42 + 60 && e.Y < (y + 1) * 42 + 60)
                    {
                        int[] XY = { x, y };
                        //Если выбран инструмент
                        //кирка
                        if (cursor == "pickaxe")
                        {
                            match_indexes.Clear();
                            match_indexes.Add(XY);
                            DrawDestroyingBalloons();
                            tDestroy.Start();
                            cursor = "";
                        }
                        //краска
                        else if (cursor == "bucket")
                        {
                            gameboard[x, y] = "M";
                            cursor          = "";
                            g.FillRectangle(new SolidBrush(Color.FromArgb(128, 128, 255)), new Rectangle(new Point(x * 42 + 1, y * 42 + 61), new Size(41, 41)));
                            using (var image = new Bitmap(Application.StartupPath.ToString() + "\\Resouses\\M.png"))
                            {
                                g.DrawImage(image, new Point(x * 42 + 1, y * 42 + 61));
                            }
                        }
                        //бомба
                        else if (cursor == "bomb")
                        {
                            gameboard[x, y] = "Bomb";
                            cursor          = "";
                            g.FillRectangle(new SolidBrush(Color.FromArgb(128, 128, 255)), new Rectangle(new Point(x * 42 + 1, y * 42 + 61), new Size(41, 41)));
                            using (var image = new Bitmap(Application.StartupPath.ToString() + "\\Resouses\\Bomb.png"))
                            {
                                g.DrawImage(image, new Point(x * 42 + 1, y * 42 + 61));
                            }
                        }
                        //если это камень
                        else if (gameboard[x, y] == "Rock")
                        {
                            ;
                        }
                        //если нет выбранного шарика
                        else if (indexes.Count == 0)
                        {
                            indexes.Add(XY);
                            g.FillRectangle(new SolidBrush(Color.FromArgb(0, 0, 64)), new Rectangle(new Point(x * 42 + 1, y * 42 + 61), new Size(41, 41)));
                            using (var image = new Bitmap(Application.StartupPath.ToString() + "\\Resouses\\" + gameboard[x, y] + ".png"))
                            {
                                g.DrawImage(image, new Point(x * 42 + 1, y * 42 + 61));
                            }
                        }
                        //если второй выбранный шарик находится рядом с первым
                        else if ((indexes[0][0] + 1 == XY[0] && indexes[0][1] == XY[1]) ||
                                 (indexes[0][0] - 1 == XY[0] && indexes[0][1] == XY[1]) ||
                                 (indexes[0][1] + 1 == XY[1] && indexes[0][0] == XY[0]) ||
                                 (indexes[0][1] - 1 == XY[1] && indexes[0][0] == XY[0]))
                        {
                            indexes.Add(XY);
                            //поменять местами
                            DrawSwapingBalloons();
                            string bottle = gameboard[indexes[0][0], indexes[0][1]];
                            gameboard[indexes[0][0], indexes[0][1]] = gameboard[indexes[1][0], indexes[1][1]];
                            gameboard[indexes[1][0], indexes[1][1]] = bottle;
                            //поиск совпадений
                            match_indexes = game.search_matches(ref gameboard, indexes, difficulty);
                            bottle        = gameboard[indexes[0][0], indexes[0][1]];
                            gameboard[indexes[0][0], indexes[0][1]] = gameboard[indexes[1][0], indexes[1][1]];
                            gameboard[indexes[1][0], indexes[1][1]] = bottle;
                            if (match_indexes.Count == 0)
                            {
                                mistake          = true;
                                remaining_moves -= 1;
                                moves.Text       = remaining_moves.ToString();
                                //если ходы кончились
                                if (remaining_moves == 0)
                                {
                                    label1.Visible      = false;
                                    label3.Visible      = false;
                                    score.Visible       = false;
                                    moves.Visible       = false;
                                    Shop.Visible        = false;
                                    pictureBox1.Visible = false;
                                    label4.Visible      = true;
                                    Finalscore.Visible  = true;
                                    Finalscore.Text    += score.Text;
                                }
                            }
                            else
                            {
                                //проверить бомбы
                                explosion_indexes = game.define_explode_indexes(gameboard, ref match_indexes);
                                //начислить очки
                                score.Text = ((int)(Convert.ToInt32(score.Text) + 2 * match_indexes.Count * Math.Pow(1.1, match_indexes.Count) * difficulty)).ToString();
                                //нарисовать
                                DrawDestroyingBalloons();
                            }
                            return;
                        }
                        //если второй выбранный шарик НЕ находится рядом с первым
                        else
                        {
                            g.FillRectangle(new SolidBrush(Color.FromArgb(128, 128, 255)), new Rectangle(new Point(indexes[0][0] * 42 + 1, indexes[0][1] * 42 + 61), new Size(41, 41)));
                            using (var image = new Bitmap(Application.StartupPath.ToString() + "\\Resouses\\" + gameboard[indexes[0][0], indexes[0][1]] + ".png"))
                            {
                                g.DrawImage(image, new Point(indexes[0][0] * 42, indexes[0][1] * 42 + 60));
                            }
                            g.FillRectangle(new SolidBrush(Color.FromArgb(0, 0, 64)), new Rectangle(new Point(x * 42 + 1, y * 42 + 61), new Size(41, 41)));
                            using (var image = new Bitmap(Application.StartupPath.ToString() + "\\Resouses\\" + gameboard[x, y] + ".png"))
                            {
                                g.DrawImage(image, new Point(x * 42 + 1, y * 42 + 61));
                            }
                            indexes[0][0] = x;
                            indexes[0][1] = y;
                        }
                        break;
                    }
                }
            }

            pictureBox1.Image = bmp;//вывод на picturebox
        }