// TODO Optimize public HexagonNode(HexagonPosition position1, HexagonPosition position2, HexagonPosition position3) { if (position1 == position2 || position1 == position3 || position2 == position3) { throw new ArgumentException("The hexagon positions have to be distinct from one another "); } var positions = new[] { position1, position2, position3 }; positions = positions.OrderBy(p => p.X).ThenBy(p => p.Y).ThenBy(p => p.Z).ToArray(); Position1 = positions[0]; Position2 = positions[1]; Position3 = positions[2]; IsYShape = false; int singleZ = positions.Unique(p => p.Z).First(); foreach (var hexagonPosition in positions) { if (hexagonPosition.Z != singleZ) { IsYShape = hexagonPosition.Z <= singleZ; break; } } }
public Hexagon GenerateHexagonAt(HexagonPosition hexagonPosition) { var alreadyRevealed = HexagonManager.Count(); Hexagon hexagon = null; if (hexagonPosition == HexagonPosition.Zero) { hexagon = new Hexagon(ResourceType.DiamondOre, GetPayoutIntervalFor(ResourceType.DiamondOre), hexagonPosition); } else if (alreadyRevealed == 1) { hexagon = new Hexagon(ResourceType.PureWater, GetPayoutIntervalFor(ResourceType.PureWater), hexagonPosition); } else if (alreadyRevealed == 2) { hexagon = new Hexagon(ResourceType.CoalOre, GetPayoutIntervalFor(ResourceType.CoalOre), hexagonPosition); } else { var waterProbability = GameplaySettings.WaterSigmoid(hexagonPosition.DistanceToOrigin); if (HexMexRandom.NextDouble() < waterProbability) { hexagon = new Hexagon(ResourceType.PureWater, 0, hexagonPosition); } else { var resourceType = GetNextResourceType(); var dieSum = GetPayoutIntervalFor(resourceType); hexagon = new Hexagon(resourceType, dieSum, hexagonPosition); } } return(hexagon); }
public Hexagon GetHexagonAtPosition(HexagonPosition hexagonPosition) { if (!Hexagons.ContainsKey(hexagonPosition)) { return(null); } return(Hexagons[hexagonPosition]); }
public Hexagon RevealHexagonAt(HexagonPosition hexagonPosition) { if (Hexagons.ContainsKey(hexagonPosition)) { throw new InvalidOperationException($"The hexagon was already revealed. Use Indexer or {nameof(GetHexagonAtPosition)} instead."); } var hexagon = HexagonRevealer.GenerateHexagonAt(hexagonPosition); Hexagons.Add(hexagonPosition, hexagon); HexagonRevealed?.Invoke(this, hexagon); return(hexagon); }
public void Initialize() { var p1 = HexagonPosition.Zero; var p2 = new HexagonPosition(0, 1, -1); var p3 = new HexagonPosition(1, 0, -1); HexagonManager.RevealHexagonAt(p1); HexagonManager.RevealHexagonAt(p2); HexagonManager.RevealHexagonAt(p3); StructureManager.CreateStrucuture(new Building(new HexagonNode(p1, p2, p3), this, GameSettings.BuildingDescriptionDatabase.ByNameKey("diamondExtractorName"))); StructureManager.CreateStrucuture(new Building(new HexagonNode(new HexagonPosition(1, 1, -2), p2, p3), this, GameSettings.BuildingDescriptionDatabase.ByNameKey("haborName"))); StructureManager.CreateStrucuture(new Building(new HexagonNode(new HexagonPosition(1, 1, -2), new HexagonPosition(2, 0, -2), p3), this, GameSettings.BuildingDescriptionDatabase.ByNameKey("coalPowerPlantName"))); IsInitialized = true; }
public bool CanReachThrough(HexagonPosition pos1, HexagonPosition pos2) { var h1 = this[pos1]; var h2 = this[pos2]; if (h1 == null || h2 == null) { return(false); } if (h1.ResourceType.IsPassable() || h2.ResourceType.IsPassable()) { return(true); } return(false); }
public Hexagon(ResourceType resourceType, float payoutInterval, HexagonPosition position) { PayoutInterval = payoutInterval; ResourceType = resourceType; Position = position; }
public bool Equals(HexagonPosition other) { return(X == other.X && Y == other.Y && Z == other.Z); }
public Hexagon this[HexagonPosition hexagonPosition] => GetHexagonAtPosition(hexagonPosition);