Exemplo n.º 1
0
 public GridPlotter(IMapRenderArea viewport,
                    IMapNavigator <GridDirection> navigator,
                    IMapNavigator <GridDirection> screenNavigator = null)
 {
     //this.plotOperation = plotOperation ?? throw new ArgumentNullException(nameof(plotOperation));
     this.viewport        = viewport ?? throw new ArgumentNullException(nameof(viewport));
     mapAccessNavigator   = navigator ?? throw new ArgumentNullException(nameof(navigator));
     this.screenNavigator = screenNavigator ?? GridNavigation.CreateNavigator(viewport.RenderType);
 }
Exemplo n.º 2
0
        public void MatchNavigator_Fits_Cardinals()
        {
            var c      = new GameRenderingConfig(RenderType.IsoDiamond);
            var nav    = c.MatcherNavigator;
            var origin = new MapCoordinate(0, 0);
            var res    = nav.NavigateCardinalNeighbours(origin);

            var referenceNav = GridNavigation.CreateNavigator(RenderType.Grid);

            res[(int)CardinalIndex.North].Should().Be(referenceNav.NavigateUnconditionally(GridDirection.North, origin));
            res[(int)CardinalIndex.East].Should().Be(referenceNav.NavigateUnconditionally(GridDirection.East, origin));
            res[(int)CardinalIndex.South].Should().Be(referenceNav.NavigateUnconditionally(GridDirection.South, origin));
            res[(int)CardinalIndex.West].Should().Be(referenceNav.NavigateUnconditionally(GridDirection.West, origin));
        }
Exemplo n.º 3
0
        RotationGridNavigator CreateNavigator(RenderType renderType, bool wrap)
        {
            var baseNav = GridNavigation.CreateNavigator(renderType);
            if (LimitX != null || LimitY != null)
            {
                var limitX = LimitX ?? new Range(int.MinValue, int.MinValue);
                var limitY = LimitY ?? new Range(int.MinValue, int.MinValue);
                baseNav = new LimitedRangeNavigator<GridDirection>(baseNav, limitX.Min, limitY.Min, limitX.Max, limitY.Max);
            }
            else if (!wrap && (WrapAroundX != null || WrapAroundY != null))
            {
                var limitX = WrapAroundX ?? new Range(int.MinValue, int.MinValue);
                var limitY = WrapAroundY ?? new Range(int.MinValue, int.MinValue);
                baseNav = new LimitedRangeNavigator<GridDirection>(baseNav, limitX.Min, limitY.Min, limitX.Max, limitY.Max);
            }

            if (wrap)
            {
                var wrapNav = baseNav.Wrap(WrapAroundX, WrapAroundY);
                return new RotationGridNavigator(wrapNav, RotationSteps * 2);
            }

            return new RotationGridNavigator(baseNav, RotationSteps * 2);
        }
Exemplo n.º 4
0
        public StrategyGameData()
        {
            Rules         = new StrategyGameRules();
            TerrainHeight = 300;
            TerrainWidth  = 300;
            terrain       = new TerrainMap(TerrainWidth, TerrainHeight);
            Fog           = new WrappingFogMap(new FogMap(TerrainWidth, TerrainHeight), GridNavigation.CreateNavigator(RenderType.Grid).Wrap(TerrainWidth, TerrainHeight));

            Settlements = new SettlementManager();

            Players = new List <Player>
            {
                new Player("Barbarian", PlayerColor.Red, Culture.Celtic),
                new Player("Player A", PlayerColor.Green, Culture.Classical),
                new Player("Player B", PlayerColor.Blue, Culture.Celtic)
            };

            var r = new MapReader(Rules);

            r.Map = terrain;
            r.ReadTerrain(new StringReader(MapData.TerrainData), 0, 0, TerrainWidth, TerrainHeight);
            r.ReadRoads(new StringReader(MapData.RoadData), 0, 0, TerrainWidth, TerrainHeight);
            r.ReadRivers(new StringReader(MapData.RiverData), 0, 0, TerrainWidth, TerrainHeight);
            r.ReadImprovement(new StringReader(MapData.ImprovementData), 0, 0, TerrainWidth, TerrainHeight);
            r.ReadResources(new StringReader(MapData.ResourceData), 0, 0, TerrainWidth, TerrainHeight);

            AddSettlement(new Settlement("Capital City", new MapCoordinate(7, 13), 1, 4000, true));
            AddSettlement(new Settlement("Satellite Settlement", new MapCoordinate(20, 14), 2, 2000, false));

            // Explicitly set the initial visible tracker to the location of one of the cities
            // here so that the visibility marking works correctly.
            Fog.MarkRangeVisible(0, 0, 2);
            MousePosition = new MapCoordinate(7, 13);
        }
Exemplo n.º 5
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Starting");
            var terrainTypes = new TerrainTypes();
            var map          = TerrainMap.CreateMap(terrainTypes);

            var renderType = RenderType.Grid;
            var navigator  = new LimitedRangeNavigator <GridDirection>(GridNavigation.CreateNavigator(renderType), map.Width, map.Height);

            var desert       = new TextTile("Desert", '.', ConsoleColor.DarkYellow);
            var tileRegistry = new BasicTileRegistry <TextTile>()
            {
                { "terrain.grasland", new TextTile("Gras", 'g', ConsoleColor.DarkGreen) },
                { "terrain.desert", desert },
                { "terrain.hills", new TextTile("Hills", 'h', ConsoleColor.Gray) },
                { "terrain.plains", new TextTile("Plains", '_', ConsoleColor.Green) }
            };

            var list = new List <ITileMatcher <TextTile, Nothing> >
            {
                new BasicTileSelector <TextTile, Nothing>(
                    (x, y) => map[x, y].Terrain == terrainTypes.Desert,
                    navigator,
                    tileRegistry,
                    "terrain.desert"),
                new BasicTileSelector <TextTile, Nothing>(
                    (x, y) => map[x, y].Terrain == terrainTypes.Grasland,
                    navigator,
                    tileRegistry,
                    "terrain.grasland"),
                new BasicTileSelector <TextTile, Nothing>(
                    (x, y) => map[x, y].Terrain == terrainTypes.Hills,
                    navigator,
                    tileRegistry,
                    "terrain.hills"),
                new BasicTileSelector <TextTile, Nothing>(
                    (x, y) => map[x, y].Terrain == terrainTypes.Plains,
                    navigator,
                    tileRegistry,
                    "terrain.plains")
            };

            var bMatcher = new AggregateTileMatcher <TextTile, Nothing>(list);

            var viewport = new MapViewport(renderType)
            {
                SizeInTiles = new IntDimension(20, 20),
                CenterPoint = new ContinuousViewportCoordinates(0, 0)
            };

            var consoleRenderer = new ViewportRenderer <TextTile, Nothing>(viewport)
            {
                RenderTarget = new ConsoleRenderer()
            };
            var plotOp = new PlotOperation <TextTile, Nothing>(bMatcher, renderType, consoleRenderer);
            var t      = new GridPlotter(viewport, navigator);

            do
            {
                t.Draw(plotOp);
                var consoleKeyInfo = Console.ReadKey(true);
                if (consoleKeyInfo.Key == ConsoleKey.Escape || consoleKeyInfo.Key == ConsoleKey.Enter)
                {
                    break;
                }

                var center = viewport.CenterPoint;
                if (consoleKeyInfo.Key == ConsoleKey.LeftArrow)
                {
                    center += new ContinuousViewportCoordinates(-1, 0);
                }

                if (consoleKeyInfo.Key == ConsoleKey.RightArrow)
                {
                    center += new ContinuousViewportCoordinates(+1, 0);
                }

                if (consoleKeyInfo.Key == ConsoleKey.UpArrow)
                {
                    center += new ContinuousViewportCoordinates(0, -1);
                }

                if (consoleKeyInfo.Key == ConsoleKey.DownArrow)
                {
                    center += new ContinuousViewportCoordinates(0, +1);
                }

                viewport.CenterPoint = center;
            } while (true);
        }