Ejemplo n.º 1
0
 //dùng timer để điều chỉnh tốc độ rắn
 private void timer2_Tick(object sender, EventArgs e)
 {
     toolStripLabel1.Text = score.ToString();
     if (down == true)
     {
         snake.moveDown();
     }
     if (up == true)
     {
         snake.moveUp();
     }
     if (left == true)
     {
         snake.moveLeft();
     }
     if (right == true)
     {
         snake.moveRight();
     }
     for (int i = 0; i < snake.SnakeRec.Length; i++)
     {
         if (snake.SnakeRec[i].IntersectsWith(food.foodRec))
         {
             Random rd = new Random();
             score += rd.Next(5, 30);
             snake.growSnake();
             food.foodLocation(randFood);
         }
     }
     collision();
     this.Invalidate();
 }
Ejemplo n.º 2
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     snakeScoreLabel.Text = Convert.ToString(score);
     if (down)
     {
         snakes.moveDown();
     }
     if (up)
     {
         snakes.moveUp();
     }
     if (right)
     {
         snakes.moveRight();
     }
     if (left)
     {
         snakes.moveLeft();
     }
     this.Invalidate();
     collision();
     for (int i = 0; i < snakes.SnakeRec.Length; i++)
     {
         if (snakes.SnakeRec[i].IntersectsWith(food.foodRec))
         {
             score += 1;
             snakes.growSnake();
             food.foodlocation(randFood);
         }
     }
 }