示例#1
0
        public void NotEnoughSpaceForPlanetsCausesException(int size, int planets, int minDistance)
        {
            var generator = new GalaxyGenerator();

            var settings = new GalaxyGeneratorSettings()
            {
                GalaxySize  = size,
                PlanetCount = planets,
                MinimumDistanceBetweenPlanets = minDistance,
            };

            Assert.Throws <OutOfSpaceException>(() => generator.Generate(settings));
        }
示例#2
0
        public void EachPlanetHasADistinctPosition()
        {
            var generator = new GalaxyGenerator();

            var settings = new GalaxyGeneratorSettings()
            {
                GalaxySize  = 800,
                PlanetCount = 100,
            };

            var galaxy = generator.Generate(settings);

            Assert.Equal(galaxy.Planets.Count, galaxy.Planets.Select(planet => planet.Position).Distinct().Count());
        }
示例#3
0
        public void GalaxyHasCorrectSize(int size)
        {
            var generator = new GalaxyGenerator();

            var settings = new GalaxyGeneratorSettings()
            {
                GalaxySize  = size,
                PlanetCount = 0,
            };

            var galaxy = generator.Generate(settings);

            Assert.Equal(size, galaxy.Bounds.Size);
        }
示例#4
0
        public void GalaxyHasCorrectNumberOfPlanets(int planets)
        {
            var generator = new GalaxyGenerator();

            var settings = new GalaxyGeneratorSettings()
            {
                GalaxySize  = 1000,
                PlanetCount = planets,
            };

            var galaxy = generator.Generate(settings);

            Assert.Equal(planets, galaxy.Planets.Count);
        }
示例#5
0
        public void MinDistanceBetweenPlanetsIsValid(int size, int planets, int minDistance)
        {
            var generator = new GalaxyGenerator();

            var settings = new GalaxyGeneratorSettings()
            {
                GalaxySize  = size,
                PlanetCount = planets,
                MinimumDistanceBetweenPlanets = minDistance
            };

            var galaxy = generator.Generate(settings);

            Assert.All(galaxy.Planets, planet => Assert.True(MinDistanceKept(planet)));

            bool PassesSocialDistancingRule(Planet p1, Planet p2) => p1 != p2?p1.Position.DistanceTo(p2.Position) >= minDistance : true;
            bool MinDistanceKept(Planet planet) => galaxy.Planets.All(otherPlanet => PassesSocialDistancingRule(planet, otherPlanet));
        }
示例#6
0
        public void PlanetsHaveValidPositions(int size, int planets, int padding)
        {
            var generator = new GalaxyGenerator();

            var settings = new GalaxyGeneratorSettings()
            {
                GalaxySize  = size,
                PlanetCount = planets,
                Padding     = padding,
            };

            var galaxy = generator.Generate(settings);
            var bounds = new GalaxyBounds(size);
            var min    = bounds.Min + padding;
            var max    = bounds.Max - padding;

            Assert.All(galaxy.Planets, planet => Assert.True(PointInRange(planet.Position)));

            bool CoordInRange(int coord) => coord >= min && coord <= max;
            bool PointInRange(Position position) => CoordInRange(position.X) && CoordInRange(position.Y);;
        }
示例#7
0
        static void Main(string[] args)
        {
            _rootConsole = new RLRootConsole("terminal8x8.png", _rootConsoleWidth, _rootConsoleHeight, _fontSize, _fontSize, 1.5f, "Test Console");

            _starMapConsole   = new RLConsole(_starMapConsoleWidth, _starMapConsoleHeight);
            _logConsole       = new RLConsole(_logConsoleWidth, _logConsoleHeight);
            _galaxyMapConsole = new RLConsole(_galaxyMapConsoleWidth, _galaxyMapConsoleHeight);
            _loreLogConsole   = new RLConsole(_loreLogConsoleWidth, _loreLogConsoleHeight);

            loreBox = new LoreBox(null, 40, 30, "Genesis");

            Galaxy            = GalaxyGenerator.Generate();
            currentSystem     = 0;
            currentWindowView = CurrentView.Log;

            _rootConsole.Update += RootConsoleUpdate;
            _rootConsole.Render += RootConsoleRender;

            isRenderRequired = true;

            _rootConsole.Run();
        }
示例#8
0
        private static void DisplayGalaxyLog()
        {
            _galaxyMapConsole.SetBackColor(0, 0, _galaxyMapConsole.Width, _galaxyMapConsole.Height, RLColor.Black);

            DisplayBorder(_galaxyMapConsole);

            Galaxy g = GalaxyGenerator.Generate();

            _galaxyMapConsole.Print(2, 2, "Galaxy Logs", RLColor.White);

            _galaxyMapConsole.Print(5, 5, g.Name, RLColor.White);

            for (int i = 0; i < 8; i++)
            {
                SpaceSystem temp = (SpaceSystem)g.Systems[i];
                string      NoP  = $"Number of Planets - {temp.Bodies.Length}";

                _galaxyMapConsole.Print(5, 7 + 2 * i, temp.Name, temp.Star.Color);
                _galaxyMapConsole.Print(12, 7 + 2 * i, NoP, temp.Star.Color);
            }


            RLConsole.Blit(_galaxyMapConsole, 0, 0, _galaxyMapConsole.Width, _galaxyMapConsole.Height, _rootConsole, 0, 0);
        }