Пример #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            //updates score
            lblSnakeScore.Text = Convert.ToString(Globals.CurrentScore);
            //keyboard events to make snake move
            if (down)
            {
                snake.down();
            }
            if (up)
            {
                snake.up();
            }
            if (right)
            {
                snake.right();
            }
            if (left)
            {
                snake.left();
            }

            for (int i = 0; i < snake.snakeRec.Length; i++)
            {
                //if snake eats the food then
                //add new block onto snake
                //else if food gets spawned inside snake then randomize location of food again until it doesnt spawn inside snake

                if ((food.rec).IntersectsWith(snake.snakeRec[i]))
                {
                    food = new Food(r);
                    Globals.FoodBrush     = new SolidBrush(foodColorDialog.Color);
                    Globals.CurrentScore += 10;
                    changeFoodLocation();
                }
                else if (snake.snakeRec[i].IntersectsWith(food.rec))
                {
                    Globals.CurrentScore += 10;
                    changeFoodLocation();
                }
            }
            //checks if snake has crashed
            crash();
            this.Invalidate();
        }
Пример #2
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     lblSnakeScore.Text = Convert.ToString(Globals.CurrentScore);
     if (down)
     {
         snake.down();
     }
     if (up)
     {
         snake.up();
     }
     if (right)
     {
         snake.right();
     }
     if (left)
     {
         snake.left();
     }
     for (int i = 0; i < snake.snakeRec.Length; i++)
     {
         if ((food.rec).IntersectsWith(snake.snakeRec[i]))
         {
             food = new Food(r);
             Globals.FoodBrush     = new SolidBrush(colorDialog1.Color);
             Globals.CurrentScore += 10;
             changeFoodLocation();
         }
         else if (snake.snakeRec[i].IntersectsWith(food.rec))
         {
             Globals.CurrentScore += 10;
             changeFoodLocation();
         }
     }
     crash();
     this.Invalidate();
 }