Exemplo n.º 1
0
        public Food(aForm form, PictureBox super, PictureBox pic, SnakeBody snake)
        {
            this.form     = form;
            picture       = pic;
            rand          = new Random();
            picture.Image = dishes[rand.Next(dishes.Count())];
            picture.BringToFront();


            do
            {
                remakeFood       = false;
                x                = rand.Next(26);
                y                = rand.Next(26);
                picture.Location = new Point(x * 20 + 10, y * 20 + 10);
                foodLocator      = new Rectangle(picture.Location.X + picture.Width / 2, picture.Location.Y + picture.Height / 2, 2, 2);
                for (int i = 0; i < snake.tail.Count - 1; i++)
                {
                    if (snake.tail[i].Bounds.IntersectsWith(foodLocator))
                    {
                        remakeFood = true;
                        break;
                    }
                }
            } while (remakeFood);

            if (rand.Next(4) == 1)
            {
                MakeSuperFood(super, snake);
            }
        }
Exemplo n.º 2
0
        public SnakeBody(Label scoreLabel, Label recordLabel, aForm form, params PictureBox[] tail)
        {
            this.form            = form;
            this.scoreLabel      = scoreLabel;
            this.scoreLabel.Text = "0";
            this.recordLabel     = recordLabel;

            head      = tail[0];
            speed     = head.Height;
            this.tail = new List <PictureBox> {
                head
            };
            for (int i = 1; i < tail.Length; i++)
            {
                this.tail.Add(tail[i]);
            }
        }