示例#1
0
 public HexTile(TileMap tileMap, HexTileCoord coord, string name, TileSpecialResourceType specialResource)
 {
     TileMap         = tileMap;
     Coord           = coord;
     Name            = name;
     SpecialResource = specialResource;
 }
示例#2
0
        public void RemoveTileObject(string typeName, HexTileCoord coord)
        {
            if (!IsValidCoord(coord))
            {
                return;
            }

            if (!_onTileMapObjects.TryGetValue(coord, out var objs))
            {
                return;
            }

            if (!objs.ContainsKey(typeName))
            {
                return;
            }

            objs.Remove(typeName);

            // Remove dictionary if there is no object left
            if (objs.Count == 0)
            {
                _onTileMapObjects.Remove(coord);
            }
        }
示例#3
0
 public IOnHexTileObject AddTileObjectWithName(string typeName, string name, HexTileCoord coord)
 {
     switch (typeName)
     {
     default:
         return(null);
     }
 }
示例#4
0
        public int GetDistanceOfTwoTile(HexTileCoord c1, HexTileCoord c2)
        {
            if (!IsValidCoord(c1) || !IsValidCoord(c2))
            {
                return(-1);
            }

            return((Math.Abs(c1.Q - c2.Q) + Math.Abs(c1.Q + c1.R - c2.Q - c2.R) + Math.Abs(c1.R - c2.R)) / 2);
        }
示例#5
0
        public void AddTileObject(IOnHexTileObject obj, HexTileCoord coord)
        {
            if (!_onTileMapObjects.ContainsKey(coord))
            {
                _onTileMapObjects.Add(coord, new Dictionary <string, IOnHexTileObject>());
            }

            var objDict = _onTileMapObjects[coord];

            if (objDict.ContainsKey(obj.TypeName))
            {
                return;
            }

            objDict[obj.TypeName] = obj;
        }
示例#6
0
        public HexTile GetHexTile(HexTileCoord coord)
        {
            if (!IsValidCoord(coord))
            {
                return(null);
            }

            var q = coord.Q;
            var r = coord.R;

            if (r < Radius)
            {
                q = q - Radius + r;
            }

            return(_tileMap[r][q]);
        }
示例#7
0
        public (float x, float y) ToCartesian(HexTileCoord coord)
        {
            if (!IsValidCoord(coord))
            {
                return(0, 0);
            }

            var q = coord.Q - Radius;
            var r = coord.R - Radius;

            var sqrt3 = (float)Math.Sqrt(3);

            var x = sqrt3 * q + sqrt3 / 2 * r;
            var y = 1.5f * r;

            return(x, y);
        }
示例#8
0
        public bool DoAction(HexTileCoord coord)
        {
            if (!IsAvailable)
            {
                return(false);
            }
            if (NeedCoordinate && !AvailableTiles.Contains(coord))
            {
                return(false);
            }
            if (!_owner.CheckSpecialActionCost(GetCost(coord)))
            {
                return(false);
            }

            _owner.ConsumeSpecialActionCost(GetCost(coord));
            _core.DoAction(_owner, coord);

            return(true);
        }
示例#9
0
 public IReadOnlyList <IOnHexTileObject> GetAllTileObjects(HexTileCoord coord) =>
 !_onTileMapObjects.TryGetValue(coord, out var result)
         ? new List <IOnHexTileObject>()
         : result.Values.ToList();
示例#10
0
 /// <summary>
 ///     Is it valid coordinate on this tile map?
 /// </summary>
 public bool IsValidCoord(HexTileCoord coord) => coord.Q + coord.R >= Radius && coord.Q + coord.R <= 3 * Radius;
示例#11
0
 public bool IsTileObjectExists(string typeName, HexTileCoord coord) =>
 _onTileMapObjects.TryGetValue(coord, out var objDict) && objDict.ContainsKey(typeName);
示例#12
0
 public bool IsInRange(HexTileCoord coord) => _infos.Values.Any(info => info.Tiles.Contains(coord));
示例#13
0
 public IReadOnlyDictionary <string, int> GetCost(HexTileCoord coord) => _core.GetCost(_owner, coord);