Ejemplo n.º 1
0
        protected List <HexSpriteTileInfo> CreateRandomCenterIndexes()
        {
            List <HexSpriteTileInfo> hexSpriteTiles = new List <HexSpriteTileInfo>();

            System.Random cellRandomizer;
            cellRandomizer = new System.Random(X * Y);
            HexSpriteTileInfo t = new HexSpriteTileInfo(false, hexTileSet);
            int randomTileIndex;

            if (cellRandomizer.Next(100) < 70 && hexTileSet.centerHexTiles.Length > 2)
            {
                randomTileIndex = cellRandomizer.Next(3);
            }
            else
            {
                randomTileIndex = cellRandomizer.Next(hexTileSet.centerHexTiles.Length);
            }
            t.AddIndex(randomTileIndex);
            hexSpriteTiles.Add(t);
            return(hexSpriteTiles);
        }
Ejemplo n.º 2
0
        protected static List <HexSpriteTileInfo> CalculateHexTiles(HashSet <int> indexes, HexTileSet hexTileSet)
        {
            List <HexSpriteTileInfo> hexSpriteTiles = new List <HexSpriteTileInfo>();

            int iterationCount = 0;

            while (indexes.Count > 0)
            {
                HexSpriteTileInfo t = new HexSpriteTileInfo(true, hexTileSet);
                FillTileSpriteIndexes(t, indexes, hexTileSet);

                hexSpriteTiles.Add(t);

                iterationCount++;
                if (iterationCount > 100)
                {
                    throw new System.Exception();
                }
            }

            if (hexTileSet.HasAdditional3WeightSprites && hexSpriteTiles.Count > 2)
            {
                HexSpriteTileInfo t = new HexSpriteTileInfo(true, hexTileSet);
                t.FullCell = true;
                if (hexSpriteTiles[0].StarterIndex == 0)
                {
                    t.AddIndexes(new int[] { 0, 2, 4 });
                }
                else
                {
                    t.AddIndexes(new int[] { 1, 3, 5 });
                }

                hexSpriteTiles.Clear();

                hexSpriteTiles.Add(t);
            }

            return(hexSpriteTiles);
        }
Ejemplo n.º 3
0
        protected static void FillTileSpriteIndexes(HexSpriteTileInfo t, HashSet <int> indexes, HexTileSet hexTileSet)
        {
            if (hexTileSet.HasAdditional3WeightSprites && indexes.Count == 6)
            {
                t.AddIndexes(0, 1, 2);
                indexes.Remove(0);
                indexes.Remove(1);
                indexes.Remove(2);
                return;
            }

            int startIndex = indexes.First();
            int step       = 1;

            for (int i = 0; i < 5; i++)
            {
                bool isCurrentIndexTrue = indexes.Contains(startIndex);

                if (!isCurrentIndexTrue)
                {
                    break;
                }

                startIndex -= step;

                //make iteration cycled
                if (startIndex > 5) // must be lesser 5
                {
                    startIndex = 0;
                }

                if (startIndex < 0) // must be bigger 2
                {
                    startIndex = 5;
                }
            }

            int index = startIndex;

            while (t.CanAddMoreIndexes) //max 3 indexes
            {
                bool isCurrentIndexTrue = indexes.Contains(index);

                if (isCurrentIndexTrue)
                {
                    t.AddIndex(index);
                    indexes.Remove(index);
                }
                else
                {
                    if (!t.HasNoAnyIndex)
                    {
                        break;
                    }
                }

                index += step; //nextStep

                //make iteration cycled
                if (index > 5) // must be lesser 5
                {
                    index = 0;
                }

                if (index < 0) // must be bigger 2
                {
                    index = 5;
                }
            }
        }