Пример #1
0
        public bool Move()
        {
            bool res;
            var  foodPoint = _food.points;

            res = _snake.Move(ref foodPoint);
            // Добавление еды на карту
            if (foodPoint.Count < FoodCount)
            {
                for (int i = 0; i < FoodCount - foodPoint.Count; i++)
                {
                    Random rand = new Random(unchecked ((int)DateTime.Now.Millisecond));
                    int    x;
                    int    y;
                    var    points = GetAllPoints();
                    do
                    {
                        x = rand.Next(_width);
                        y = rand.Next(_height);
                    } while (points.Exists(p => p.X == x && p.Y == y && p.Figure != Figures.EmptySpace));
                    _food.AddFood(x, y);
                }
            }

            if (AutoPilot)
            {
                AutoFindWay();
            }
            return(res);
        }
Пример #2
0
        private void FoodCollision()
        {
            // Finds last snakePixel in the list
            PictureBox lastPixel = snake.snakePixels[snake.snakePixels.Count - 1];

            //Declare by one variable the first list element
            PictureBox head = snake.snakePixels[0];

            // If snake head cross food borders creates new food and adds new snakePixel
            if (head.Bounds.IntersectsWith(food.Bounds))
            {
                food.AddFood();
                snake.AddPixel(lastPixel.Left, lastPixel.Top);
                snake.Render(this);
            }
        }