Example #1
0
        // Fix this non-dry stuff
        public World(Options options)
        {
            if (options is null)
            {
                throw new ArgumentException($"{nameof(options)} cannot be null");
            }

            Size = options.Size;

            var center = Size.GetCenter().EnsuredWithin(Size);

            Apple = (options.Apple ?? new Point(options.AppleX ?? center.X + 1, options.AppleY ?? center.Y + 1)).EnsuredWithin(Size);

            Snake = (options.Snake ?? new List <Point>()
            {
                center
            }).EnsuredWithin(Size);

            RandomSeed = options.RandomSeed ?? new Random().Next();

            rand = new Random(RandomSeed);

            this.options = options;
        }