Beispiel #1
0
        public IReadOnlyList <Coordinate> GetFlattenCoordinates(MapConfig mapConfig)
        {
            var toReturn = new List <Coordinate>();

            for (var i = 0; i < mapConfig.GetTotalMapSize(); i++)
            {
                toReturn.Add(GetCoordinateFromFlattenArrayIndex(i, mapConfig));
            }

            return(toReturn);
        }
Beispiel #2
0
            public void WhenIndexOutOfRange_ThrowArgumentOutOfRangeException()
            {
                var outOfRangeIndex = _3X3Config.GetTotalMapSize() + 1;

                void CallWithIndexOutOfRange()
                {
                    _coordinateService.GetCoordinateFromFlattenArrayIndex(outOfRangeIndex, _3X3Config);
                }

                Assert.That(CallWithIndexOutOfRange, Throws.TypeOf <ArgumentOutOfRangeException>());
            }
Beispiel #3
0
        public Coordinate GetCoordinateFromFlattenArrayIndex(int index, MapConfig config)
        {
            if (index > config.GetTotalMapSize() || index < 0)
            {
                throw new ArgumentOutOfRangeException($"{index} is out of range of the given config: ${config}");
            }

            var nestedArrayZ = index / config.GetMap2DActualHeight();
            var nestedArrayX = index - nestedArrayZ * config.GetMap2DActualWidth();

            return(GetAxialCoordinateFromNestedArrayIndex(nestedArrayX, nestedArrayZ));
        }
Beispiel #4
0
        public static LevelData GetEmptyLevelData(MapConfig config)
        {
            var mapSize   = config.GetTotalMapSize();
            var tileDatas = Enumerable.Repeat <TileData>(
                null,
                mapSize
                )
                            .ToArray();
            var constructDatas = Enumerable.Repeat <ConstructData>(
                null,
                mapSize
                )
                                 .ToArray();

            var unitDatas = Enumerable.Repeat <UnitData>(
                null,
                mapSize
                )
                            .ToArray();

            var strongholdDatas = Enumerable.Repeat <StrongholdData>(
                null,
                mapSize
                )
                                  .ToArray();

            GameObjectFactory[] GetEmptyGoFactories()
            {
                return(Enumerable.Repeat <GameObjectFactory>(
                           null,
                           mapSize
                           )
                       .ToArray());
            }

            return(new LevelData(
                       tileDatas,
                       GetEmptyGoFactories(),
                       constructDatas,
                       GetEmptyGoFactories(),
                       unitDatas,
                       GetEmptyGoFactories(),
                       strongholdDatas,
                       new GameObjectFactory[mapSize],
                       new GameObjectFactory[mapSize]
                       ));
        }
        private ValidationResult AllDataOfCorrectSize(LevelDataScriptable levelData, MapConfig mapConfiguration)
        {
            var arraysSize = mapConfiguration.GetTotalMapSize();

            var testTileDatasResult = CheckDataIsOfCorrectSize(
                levelData.TileDatas,
                arraysSize,
                nameof(levelData.TileDatas)
                );

            var testTileGameObjectProvidersResult = CheckDataIsOfCorrectSize(
                levelData.TileGameObjectFactories,
                arraysSize,
                nameof(levelData.TileGameObjectFactories)
                );

            var testConstructDatasResult = CheckDataIsOfCorrectSize(
                levelData.ConstructDatas,
                arraysSize,
                nameof(levelData.ConstructDatas)
                );

            var testConstructGameObjectProvidersResult = CheckDataIsOfCorrectSize(
                levelData.ConstructGameObjectFactories,
                arraysSize,
                nameof(levelData.ConstructGameObjectFactories)
                );

            var testUnitDatasResult = CheckDataIsOfCorrectSize(
                levelData.UnitDatas,
                arraysSize,
                nameof(levelData.UnitDatas)
                );

            var testUnitGameObjectProvidersResult = CheckDataIsOfCorrectSize(
                levelData.UnitGameObjectFactories,
                arraysSize,
                nameof(levelData.UnitGameObjectFactories)
                );

            var testStrongholdDatasResult = CheckDataIsOfCorrectSize(
                levelData.StrongholdDatas,
                arraysSize,
                nameof(levelData.StrongholdDatas)
                );

            var testStrongholdUnitGameObjectProvidersResult = CheckDataIsOfCorrectSize(
                levelData.StrongholdUnitGameObjectFactories,
                arraysSize,
                nameof(levelData.StrongholdUnitGameObjectFactories)
                );

            var testStrongholdConstructGameObjectProvidersResult = CheckDataIsOfCorrectSize(
                levelData.StrongholdConstructGameObjectFactories,
                arraysSize,
                nameof(levelData.StrongholdConstructGameObjectFactories)
                );

            var summaries = SummarizeValidationResult(
                testTileDatasResult,
                testTileGameObjectProvidersResult,
                testConstructDatasResult,
                testConstructGameObjectProvidersResult,
                testUnitDatasResult,
                testUnitGameObjectProvidersResult,
                testStrongholdDatasResult,
                testStrongholdUnitGameObjectProvidersResult,
                testStrongholdConstructGameObjectProvidersResult
                );

            return(summaries);
        }
Beispiel #6
0
 private static bool IsMapHaveTiles(MapConfig c) => c.GetTotalMapSize() != 0;