Example #1
0
    private void Drive(object sender, EventArgs e)
    {
        screen.Text = "Energy: " + life;

        if (startis)
        {
            tx = 520;
            ty = y + 100;
        }
        try
        {
            g.DrawImage(auto, tx, ty, 50, 50);
        }
        catch (Exception ex)
        {
            int vx;
        }

        try
        {
            g.DrawImage(bg, x, 0, canvas.Width, canvas.Height);
        }
        catch (Exception ex)
        {
            int vx;
        }

        try
        {
            g.DrawImage(bg, x - 1280, 0, canvas.Width, canvas.Height);
        }
        catch (Exception ex)
        {
            int vx;
        }

        if (x < 0)
        {
            x = 1300;
        }
        x -= 60;

        int v  = 0;
        int w  = 0;
        int xx = rnd.Next(5000);

        if (xx < 2500)
        {
            v = rnd.Next(2) * (rnd.Next(20) + 30);
        }
        else if (xx > 2500)
        {
            w = rnd.Next(2) * (rnd.Next(20) + 30);
        }
        y += v;
        y -= w;

        if (y < 100)
        {
            y += 60;
        }

        if (y > 700)
        {
            y -= 60;
        }

        Row row = new Row();

        row.SetLocation(1280, y);
        int xy = rnd.Next(10);

        if (xy == 0)
        {
            Other car = new Other();
            car.x = 1280;
            car.y = y;
            others.Add(car);
        }
        int px = rnd.Next(10);

        if (px == 0)
        {
            row.AddBlockAbove();
        }
        if (px == 1)
        {
            row.DelBlockAbove();
        }
        if (px == 2)
        {
            row.AddBlockBelow();
        }
        if (px == 3)
        {
            row.DelBlockBelow();
        }
        if (rows.Count != 0)
        {
            rows.Insert(rows.Count - 1, row);
        }
        else
        {
            rows.Add(row);
        }
        for (int i = 0; i < rows.Count; i++)
        {
            System.Collections.Generic.List <Block> blocks = rows[i].blocks;
            for (int j = 0; j < blocks.Count; j++)
            {
                int   k     = j + 1;
                int   l     = blocks.Count / 2;
                Block block = blocks[j];
                block.x -= 100;
                try
                {
                    g.FillRectangle(new SolidBrush(Color.Gray), block.x, block.y, width, height);
                    if (k == l + 1)
                    {
                        g.FillRectangle(new SolidBrush(Color.White), block.x, block.y, 40, 6);
                    }
                    //g.DrawImage(bloc, block.x, block.y, width, height);
                }
                catch (Exception ex)
                {
                    int vx;
                }
            }
            for (int k = 0; k < others.Count; k++)
            {
                Other car = others[k];
                car.x -= 100;
                g.DrawImage(other, car.x, car.y, 30, 30);
            }
        }

        if (!startis)
        {
            Block block = rows[-14 + count].blocks[0];
            int   they  = block.y;
            if (ty < they)
            {
                life--;
            }
            block = rows[-14 + count].blocks[rows[-14 + count].blocks.Count - 1];
            they  = block.y;
            if (ty > they)
            {
                life--;
            }
        }

        if (life <= 0)
        {
            Application.Exit();
        }

        count++;
    }