private void GenerateTeamScores() { int order = 1; foreach (Team team in _teams) { TeamScore teamScore = new TeamScore() { TeamID = team.TeamID, CurrentScore = 0, Order = order }; teamScore.TeamName = team.Players.Count % 2 == 0 ? string.Format("{0} / {1}", team.Players.Select(e => e.PlayerName).ToArray()) : team.Players.FirstOrDefault().PlayerName; foreach (PointValue pv in _pointValues) { PointValueHit pvh = new PointValueHit() { PointValueID = pv.PointValueID, Points = pv.Points, Completed = false, HitLastRound = false }; teamScore.PointValuesHit.Add(pvh); } _teamScores.Add(teamScore); order++; } }
private void RefreshTeamScore(int teamID) { // Get the backend data objects Team team = _game.Teams.SingleOrDefault(e => e.TeamID == teamID); IEnumerable <RoundScore> teamRoundScores = _game.RoundScores.Where(e => e.TeamID == teamID).OrderBy(e => e.Round); // Get the Displayed Data Object TeamScore teamScore = _teamScores.SingleOrDefault(e => e.TeamID == teamID); // Set the current score teamScore.CurrentScore = teamRoundScores.Sum(e => e.Points); // Reset the points hit foreach (PointValueHit pvh in teamScore.PointValuesHit) { pvh.Completed = false; pvh.HitLastRound = false; } // Get the distinct points hit IEnumerable <int> pointsHit = teamRoundScores.Select(e => e.Points).Distinct(); foreach (int points in pointsHit) { PointValueHit pvh = teamScore.PointValuesHit.SingleOrDefault(e => e.Points == points); if (pvh != null) { pvh.Completed = true; } } // Get the points hit in the latest round if (teamRoundScores.Count() > 0) { int maxRound = teamRoundScores.Max(e => e.Round); IEnumerable <int> pointsHitLastRound = teamRoundScores.Where(e => e.Round == maxRound).Select(e => e.Points); foreach (int points in pointsHitLastRound) { PointValueHit pvh = teamScore.PointValuesHit.SingleOrDefault(e => e.Points == points); if (pvh != null) { pvh.HitLastRound = true; } } } }
private void UpdateTeamScore(int teamID, int round) { TeamScore teamScore = _teamScores.SingleOrDefault(e => e.TeamID == teamID); List <RoundScore> roundScores = _game.RoundScores.Where(e => e.TeamID == teamID).ToList(); foreach (PointValueHit pv in teamScore.PointValuesHit) { pv.HitLastRound = false; } teamScore.CurrentScore = roundScores.Sum(e => e.Points); foreach (RoundScore rs in roundScores.Where(e => e.Round == round)) { PointValueHit pvh = teamScore.PointValuesHit.SingleOrDefault(e => e.Points == rs.Points); if (pvh != null) { pvh.Completed = true; pvh.HitLastRound = true; } } if (teamScore.CurrentScore == _scoreToWin) { System.Windows.Forms.MessageBox.Show(string.Format("{0} Win!", teamScore.TeamName)); } else if (teamScore.CurrentScore > _scoreToWin) { RoundScore negRoundScore = new RoundScore() { GameID = _game.GameID, TeamID = teamID, Round = round }; negRoundScore.Points = _fallbackScoreOnBust - teamScore.CurrentScore; _game.RoundScores.Add(negRoundScore); _dataManager.SaveChanges(); teamScore.CurrentScore = roundScores.Sum(e => e.Points) + negRoundScore.Points; } }