예제 #1
0
 //Checks whether snake ate the feed or not
 bool isFeedCheckTrue()
 {
     if (snakeParts[0].Bounds.IntersectsWith(pb_feed.Bounds))
     {
         score++;
         label2.Text = score.ToString();
         mySnake.Grow();
         Array.Resize(ref snakeParts, snakeParts.Length + 1);
         snakeParts[snakeParts.Length - 1] = AddPictureBox(Color.Black);
         feedCheck = false;
         panel1.Controls.Remove(pb_feed);
     }
     return(feedCheck);
 }
예제 #2
0
        private void Update(object sender, EventArgs e)
        {
            this.Text = string.Format("Snake - Score: {0}", score);
            snake.Move(direction);

            for (int i = 1; i < snake.Body.Length; i++)
            {
                if (snake.Body[0].IntersectsWith(snake.Body[i])) //Death by cannibalism..
                {
                    Restart();
                }
                if (snake.Body[0].X < 0 || snake.Body[0].X < 290 || snake.Body[0].Y < 0 || snake.Body[0].Y < 190) //hitting the wall..
                {
                    Restart();
                }
                if (snake.Body[0].IntersectsWith(food.Piece))  //Eating food and growing..
                {
                    score++;
                    snake.Grow();
                    food.Generate(rand);
                }
            }
            this.Invalidate();
        }