protected override void calcScore() { this.Score = 0; int numAces = 0; foreach (Card card in Hand) { int value; string cardValue = card.GetValue(); // 2 - 10 if (int.TryParse(cardValue, out value)) { Score += value; } // jack, queen, king else if (!cardValue.ToLower().Equals("ace")) { Score += 10; } // ace else { numAces++; Score += 11; } } if (this.Score > 21) { while (numAces > 0) //has 1 or more aces { Score -= 10; if (this.Score > 21) { numAces--; continue; } break; } if (this.Score > 21) { hasBusted = true; } } //Check for blackjack condition if (this.Score == 21) { if (Hand.Count == 2) { if ((Hand[0].GetValue() == "jack") && ((Hand[0].GetSuit() == "spades") || (Hand[0].GetSuit() == ("clubs")))) { AchievementMonitor.GetInstance().AddBlackjackAchievement(); frmTitle.getInstance().UpdateAchievements(); } else if ((Hand[1].GetValue() == "jack") && ((Hand[0].GetSuit() == "spades") || (Hand[1].GetSuit() == ("clubs")))) { AchievementMonitor.GetInstance().AddBlackjackAchievement(); frmTitle.getInstance().UpdateAchievements(); } } } }
public static AchievementMonitor GetInstance() { return(instance ?? (instance = new AchievementMonitor())); }