示例#1
0
 public Form1()
 {
     InitializeComponent();
     papel       = canvas.CreateGraphics();
     cabeza      = new ColaSerpiente(10, 10);
     manzana     = new Comida(canvas.Width, canvas.Height);
     ext         = new Extra(canvas.Width, canvas.Height);
     label1.Text = "Score: ";
     label2.Text = "0";
     label3.Text = "Level";
     label4.Text = Convert.ToString(nivel);
     aleatorio   = new Random();
     bucle.Start();
 }
示例#2
0
 private void Reset()
 {
     xdir        = 0;
     ydir        = 0;
     puntos      = 0;
     label2.Text = "0";
     ejex        = true;
     ejey        = true;
     cabeza      = new ColaSerpiente(10, 10);
     manzana     = new Comida(canvas.Width, canvas.Height);
     MessageBox.Show("Superaste el nivel");
     nivel++;
     label4.Text = Convert.ToString(nivel);
 }
示例#3
0
        private void bucle_Tick(object sender, EventArgs e)
        {
            DibujarTodo();
            MoverTodo();
            ChocarPared();
            ChocarCuerpo();
            ChocarObstaculo(ob1);
            ChocarObstaculo(ob2);
            ChocarObstaculo(ob3);

            if (cabeza.Colision(manzana))
            {
                manzana.Mover(canvas.Width, canvas.Height);
                cabeza.Agregar();
                puntos++;
                label2.Text = puntos + "";
            }
            if (cabeza.Colision(ext))
            {
                FinDelJuego();
            }

            if (ext.Colision(manzana))
            {
                ext = new Extra(canvas.Width, canvas.Height);
            }

            if (puntos == 5 && nivel == 1)
            {
                Reset();
            }

            if (puntos == 5 && nivel == 2)
            {
                Reset();
            }

            if (nivel > 2)
            {
                bucle.Interval = 100 - 4 * puntos;
            }

            if (puntos == 5 && nivel == 3)
            {
                Reset();
            }

            if (puntos == 5 && nivel == 4)
            {
                Reset();
            }

            if (puntos == 5 && nivel == 5)
            {
                xdir        = 0;
                ydir        = 0;
                puntos      = 0;
                label2.Text = "0";
                ejex        = true;
                ejey        = true;
                cabeza      = new ColaSerpiente(10, 10);
                manzana     = new Comida(canvas.Width, canvas.Height);
                MessageBox.Show("Felicidades, terminaste el juego");
                Application.Exit();
            }
        }