Ejemplo n.º 1
0
        protected override void OnInitialize(List <Entity> entities)
        {
            var snake = SnakeGame.Instance.GameService <GameData>().Snake;

            var entity = new SnakePartEntity {
                Position = snake.Head.Position
            };

            entities.Add(entity);
        }
Ejemplo n.º 2
0
        protected override void OnProcess(List <Entity> entities, int width, int height)
        {
            if (_food == null)
            {
                _food = new Food();

                _food.Position   = new Position();
                _food.Position.X = new Random().Next(0, _width);
                _food.Position.Y = new Random().Next(0, _height);

                var entity = new FoodEntity();
                entity.Position = _food.Position;
                entity.Initialize();

                entities.Add(entity);
            }
            else
            {
                var bodyPart = _snake.Eat(_food);
                if (bodyPart == null)
                {
                    return;
                }

                _food = null;

                var foodEntity = entities.OfType <FoodEntity>().First();
                entities.Remove(foodEntity);

                var bodyPartEntity = new SnakePartEntity {
                    Position = bodyPart.Position
                };
                bodyPartEntity.Initialize();
                entities.Add(bodyPartEntity);
            }
        }