private void CreateNearHexes(Map <T> map, T baseHex, List <T> nextCircle) { foreach (HexDirection hd in SixDirections.Get()) { T newHex; Coords coords = baseHex.GetNearbyHexCoords(hd); if (!map.IsHex(coords)) { newHex = CreateHex(coords, map.Hexes.Count); map.AddHex(newHex); ConnectToHexes(newHex, map); nextCircle.Add(newHex); } } }
public JObject ToJson(GameUnitsManager um) { JObject jsonHex; JArray hexes = new JArray(); JArray units = new JArray(); foreach (T h in Hexes) { units = new JArray(); foreach (Unit u in h.GetUnits()) { units.Add(um.GetUnitId(u)); } jsonHex = new JObject(new JProperty(MapJsonStrings.HexId, h.Id), new JProperty(MapJsonStrings.XCoord, h.Coords.X), new JProperty(MapJsonStrings.YCoord, h.Coords.Y), new JProperty(MapJsonStrings.UnitsId, units)); foreach (HexDirection hd in SixDirections.Get()) { AddNearHex(jsonHex, h, hd); } hexes.Add(jsonHex); } int maxX = GetMaxX(); int minX = GetMinX(); int maxY = GetMaxY(); int minY = GetMinY(); int sizeX = maxX - minX + 1; int sizeY = maxY - minY + 1; int offsetX = _center.Coords.X - minX; int offsetY = _center.Coords.Y - minY; return(new JObject(new JProperty(MapJsonStrings.Hexes, hexes), new JProperty(MapJsonStrings.LengthY, sizeX), new JProperty(MapJsonStrings.LengthX, sizeY), new JProperty(MapJsonStrings.OffsetY, offsetX), new JProperty(MapJsonStrings.OffsetX, offsetY))); }
private void ConnectToHexes(T hex, Map <T> map) { T targetHex; foreach (HexDirection hd in SixDirections.Get()) { targetHex = hex.nearHexes.GetValueOrDefault(hd) as T; if (targetHex == null) { targetHex = map.GetHex(hex.GetNearbyHexCoords(hd)); if (targetHex != null) { hex.nearHexes.Add(hd, targetHex); targetHex.nearHexes.Add(hd.GetOposite(), hex); } } } }