Example #1
0
        /// <summary>
        /// Map constructor
        /// </summary>
        public Map(int size, int nbTurn, int nbUnits, int randomSeed)
        {
            MapSize = size;
            TotalNbTurn = nbTurn;
            TotalNbUnits = nbUnits;
            Tiles = new ITile[MapSize, MapSize];

            TileFactory tileFactory = new TileFactory();
            algo = new AlgoMap();
            algo.BuildMap(MapSize, randomSeed);

            RandomSeed = (randomSeed == 0) ? algo.GetRandomSeed() : randomSeed;

            for (int y = 0; y < MapSize; y++)
            {
                for (int x = 0; x < MapSize; x++)
                {
                    Tiles[x, y] = tileFactory.CreateTile(x, y, algo.GetTileType(x, y));

                    // Square map representation
                    if (x > 0)
                    {
                        Tiles[x, y].AddAdjacentTile(Tiles[x - 1, y]);
                        Tiles[x - 1, y].AddAdjacentTile(Tiles[x, y]);
                    }
                    if (y > 0)
                    {
                        Tiles[x, y].AddAdjacentTile(Tiles[x, y - 1]);
                        Tiles[x, y - 1].AddAdjacentTile(Tiles[x, y]);
                    }
                    // Hexagonal map representation (just add top-left (odd) or top-right (even) corner tile)
                    if (y % 2 == 0) // Odd line
                    {
                        if (x > 0 && y > 0)
                        {
                            Tiles[x, y].AddAdjacentTile(Tiles[x - 1, y - 1]);
                            Tiles[x - 1, y - 1].AddAdjacentTile(Tiles[x, y]);
                        }
                    }
                    else // Even line
                    {
                        if (x < MapSize - 1 && y > 0)
                        {
                            Tiles[x, y].AddAdjacentTile(Tiles[x + 1, y - 1]);
                            Tiles[x + 1, y - 1].AddAdjacentTile(Tiles[x, y]);
                        }
                    }
                }
            }
        }
Example #2
0
 /// <summary>
 /// Call initialization of the algo after load game
 /// </summary>
 public void RefreshAlgoMap()
 {
     algo = new AlgoMap();
     algo.BuildMap(MapSize, RandomSeed);
 }