/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (DiseaseName != null) { hashCode = hashCode * 59 + DiseaseName.GetHashCode(); } if (CountryName != null) { hashCode = hashCode * 59 + CountryName.GetHashCode(); } if (Population != null) { hashCode = hashCode * 59 + Population.GetHashCode(); } if (PrevalanceFactor != null) { hashCode = hashCode * 59 + PrevalanceFactor.GetHashCode(); } return(hashCode); } }
/// <summary> /// Returns true if Prevalence instances are equal /// </summary> /// <param name="other">Instance of Prevalence to be compared</param> /// <returns>Boolean</returns> public bool Equals(Prevalence other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( DiseaseName == other.DiseaseName || DiseaseName != null && DiseaseName.Equals(other.DiseaseName) ) && ( CountryName == other.CountryName || CountryName != null && CountryName.Equals(other.CountryName) ) && ( Population == other.Population || Population != null && Population.Equals(other.Population) ) && ( PrevalanceFactor == other.PrevalanceFactor || PrevalanceFactor != null && PrevalanceFactor.Equals(other.PrevalanceFactor) )); }
public static string GetValueOrDefaultNoname(Language currentLanguage, DiseaseName diseaseName) { var primaryName = LocalizationHelper.GetValueOrDefaultNoname(currentLanguage, diseaseName.Primary); var prefix = LocalizationHelper.GetValue(currentLanguage, diseaseName.PrimaryPrefix); var secondaryName = LocalizationHelper.GetValue(currentLanguage, diseaseName.Secondary); var subject = LocalizationHelper.GetValue(currentLanguage, diseaseName.Subject); return($"{secondaryName} {prefix}{primaryName} {subject}".Trim()); }
public override bool Equals(Object obj) { if (obj == this) { return(true); } Type type = typeof(Disease); if (obj != null && obj.GetType() != type) { return(false); } var m = (Disease)obj; return(DiseaseName.Equals(m?.DiseaseName)); }
public IDisease Create() { var roll = _dice.RollD6(); if (roll <= 1) { var nameGenerationAttempt = 0; do { var primaryName = _dice.RollFromList(DiseaseNames.Primary); ILocalizedString prefix = null; var rollPrefix = _dice.RollD6(); if (rollPrefix >= 4) { prefix = _dice.RollFromList(DiseaseNames.PrimaryPreffix); } ILocalizedString secondary = null; var rollSecondary = _dice.RollD6(); if (rollSecondary >= 4) { secondary = _dice.RollFromList(DiseaseNames.Secondary); } ILocalizedString subject = null; var rollSubject = _dice.RollD6(); if (rollSubject >= 6) { subject = _dice.RollFromList(DiseaseNames.Subject); } var diseaseName = new DiseaseName(primaryName, prefix, secondary, subject); // Проверяем, была ли уже такая болезнь. var isDuplicate = CheckDuplicates(diseaseName); if (isDuplicate) { nameGenerationAttempt++; continue; } var rolledSymptoms = RolledSymptoms(); var progressSpeed = RollDiseaseProgressSpeed(); var disease = new Disease(diseaseName, rolledSymptoms, progressSpeed); _usedDiseases.Add(diseaseName); return(disease); } while (nameGenerationAttempt < 10); // Не удалось сгенерировать уникальное имя. Значит вообще не генерируем болезнь. return(null); } else { return(null); } }
private bool CheckDuplicates(DiseaseName checkingDisease) { var nameFound = _usedDiseases.Any(x => x == checkingDisease); return(nameFound); }