Exemplo n.º 1
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);
         }
     }
 }
Exemplo n.º 2
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();
 }
Exemplo n.º 3
0
        private void timer1_Tick(object sender, EventArgs e) //whats going to happen when timer begins
        {
            snakeScoreLabel.Text = Convert.ToString(score);  //actual score

            if (down)
            {
                snakes.moveDown(); //checking wich ones are true from above
            }
            if (up)
            {
                snakes.moveRight(); //method from snake.cs to where the snake is going
            }
            if (right)
            {
                snakes.moveLeft();
            }
            if (left)
            {
                snakes.moveLeft();
            }

            this.Invalidate(); //drawing the snake again

            colision();        //if snake crashes if not it grows


            for (int i = 0; i < snakes.SnakeRec.Length; i++)         //actual size of snake
            {
                if (snakes.SnakeRec[i].IntersectsWith(food.foodrec)) //if snake touch food
                {
                    player.SoundLocation = "C:/dev/github/SnakeGame/snake game/snake game\resources/power";
                    player.Play();

                    score += 1;                 //score 1 plus 1
                    snakes.addSnake();
                    food.foodLocation(ranfood); //random food position
                }
            }
        }