コード例 #1
0
ファイル: Form1.cs プロジェクト: fayrushin/shooter
        private void button3_Click(object sender, EventArgs e)
        {
            k = 0;
            textBox1.Text = Convert.ToString(k);

            t = time + 1;
            Random rand1 = new Random();
            int sluch_chisl_o1, sluch_chisl_o2, sluch_chisl_o3;
            sluch_chisl_o1 = rand1.Next(2, 5);
            sluch_chisl_o2 = rand1.Next(2, 4);
            sluch_chisl_o3 = rand1.Next(2, 6);
            n = sluch_chisl_o1 + sluch_chisl_o2 + sluch_chisl_o3;

            int a1, a2; //a1,a2 - интервал, откуда будет браться случайное число
            int dl_intervala = _w / n;
            a1 = 0; a2 = a1 + dl_intervala;
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = rand1.Next(Math.Min(a1, Math.Abs(a2 - 30)), Math.Max(a1, Math.Abs(a2 - 30)));
                a1 = a2;
                a2 += dl_intervala;
            }

            dl_intervala = _h / n;
            a1 = 0; a2 = a1 + dl_intervala;
            int[] b = new int[n];
            for (int i = 0; i < n; i++)
            {
                b[i] = rand1.Next(Math.Min(a1, Math.Abs(a2 - 30)), Math.Max(a1, Math.Abs(a2 - 30)));
                a1 = a2;
                a2 += dl_intervala;
            }

            MessageBox.Show(Convert.ToString(n));
            objects = new Obj[n];

            double v1, v2;
            int i2;

            for (int i = 0; i < sluch_chisl_o1; i++)
            {
                v1 = rand1.Next(-11, 12);
                v2 = rand1.Next(-9, 11);
                i2 = rand1.Next(0, n - 1);
                objects[i] = new Obj_square(a[i], b[i2], v1, v2, Color.BlueViolet, 30);

            }
            for (int i = sluch_chisl_o1 - 1; i < sluch_chisl_o1 + sluch_chisl_o2; i++)
            {
                v1 = rand1.Next(-8, 7);
                v2 = rand1.Next(-9, 9);
                i2 = rand1.Next(0, n - 1);
                objects[i] = new Obj_circle(a[i], b[i2], v1, v2, Color.Green, 20);
            }
            for (int i = sluch_chisl_o1 + sluch_chisl_o2 - 1; i < n; i++)
            {
                v1 = rand1.Next(-6, 12);
                v2 = rand1.Next(-9, 11);
                i2 = rand1.Next(0, n - 1);
                objects[i] = new Obj_star(a[i], b[i2], v1, v2, Color.Orange, 30);

            }

            textBox3.Text = "";
            t = 0;
            timer1.Interval = 60;
            timer1.Start();
            timer2.Interval = 300;
            timer2.Start();
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: fayrushin/shooter
        private void Form1_Activated(object sender, EventArgs e)
        {
            pictureBox1.BackColor = Color.White;
            _w = pictureBox1.Width;
            _h = pictureBox1.Height;
            g = pictureBox1.CreateGraphics();
            k = 0;
            textBox1.Text = Convert.ToString(k);

            int sluch_chisl_o1, sluch_chisl_o2, sluch_chisl_o3;
            sluch_chisl_o1 = rand.Next(2, 5);
            sluch_chisl_o2 = rand.Next(2, 4);
            sluch_chisl_o3 = rand.Next(2, 6);
            n = sluch_chisl_o1 + sluch_chisl_o2 + sluch_chisl_o3;

            int a1, a2; //a1,a2 - интервал, откуда будет браться случайное число
            int dl_intervala = _w / n;
            a1 = 0; a2 = a1 + dl_intervala;
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = rand.Next(Math.Min(a1, Math.Abs(a2 - 30)), Math.Max(a1, Math.Abs(a2 - 30)));
                a1 = a2;
                a2 += dl_intervala;
            }

            dl_intervala = _h / n;
            a1 = 0; a2 = a1 + dl_intervala;
            int[] b = new int[n];
            for (int i = 0; i < n; i++)
            {
                b[i] = rand.Next(Math.Min(a1, Math.Abs(a2 - 30)), Math.Max(a1, Math.Abs(a2 - 30)));
                a1 = a2;
                a2 += dl_intervala;
            }

            objects = new Obj[n];

            double v1,v2;

            for (int i = 0; i < sluch_chisl_o1; i++)
            {
                v1 = rand.Next(-11, 12);
                v2 = rand.Next(-9, 11);
                objects[i] = new Obj_square(a[i], b[rand.Next(0, n - 1)], v1, v2, Color.BlueViolet, 30);

            }
            for (int i = sluch_chisl_o1 - 1; i < sluch_chisl_o1+sluch_chisl_o2; i++)
            {
                v1 = rand.Next(-8, 7);
                v2 = rand.Next(-9, 9);
                objects[i] = new Obj_circle(a[i], b[rand.Next(0, n - 1)], v1, v2, Color.Green, 20);
            }
            for (int i = sluch_chisl_o1+sluch_chisl_o2-1; i < n; i++)
            {
                v1 = rand.Next(-6, 12);
                v2 = rand.Next(-9, 11);
                objects[i] = new Obj_star(a[i], b[rand.Next(0, n - 1)], v1, v2, Color.Orange, 30);

            }
        }