// Private methods private void AddCostsForType( MovementType type, Dictionary <TerrainType, int> movementCostsToTerrain ) { var missingTypes = GetAllTerrainTypes().Except(movementCostsToTerrain.Keys).ToArray(); if (missingTypes.Any()) { var missingTypesEnumerationString = CreateTypesEnumerationString(missingTypes); throw new ArgumentException( $"Error when adding movement type '{type.GetName()}': missing movement costs to {missingTypesEnumerationString}"); } var excessTypes = movementCostsToTerrain.Keys.Except(GetAllTerrainTypes()).ToArray(); if (excessTypes.Any()) { var excessTypesEnumerationString = CreateTypesEnumerationString(excessTypes); throw new ArgumentException( $"Error when adding movement type '{type.GetName()}': movement costs contain unknown {excessTypesEnumerationString}"); } foreach (var terrainAndCost in movementCostsToTerrain) { var terrain = terrainAndCost.Key; var costValue = terrainAndCost.Value; Costs.Add(new Cost { TerrainType = terrain, MovementType = type, MovementCost = costValue }); } }
public int GetMovementCost(MovementType pawnMovementType, TerrainType terrainType) { if (!ContainsMovementType(pawnMovementType)) { throw new ArgumentException( $"Unknown movement type: '{pawnMovementType.GetName()}'"); } if (!ContainsTerrainType(terrainType)) { throw new ArgumentException( $"Unknown terrain type: '{terrainType.GetName()}'"); } selectedMovementType = pawnMovementType; selectedTerrainType = terrainType; var costValue = int.MaxValue; foreach (var cost in Costs) { if (!cost.TerrainType.Equals(selectedTerrainType) || !cost.MovementType.Equals(selectedMovementType)) { continue; } costValue = cost.MovementCost; break; } return(costValue); }