Exemplo n.º 1
0
        private GameResult GetGameResult()
        {
            var team1FinalScore = GameRoundList
                                  .Where(g => g.RoundResult != null)
                                  .Sum(g => g.RoundResult.Team1FinalScore);
            var team2FinalScore = GameRoundList
                                  .Where(g => g.RoundResult != null)
                                  .Sum(g => g.RoundResult.Team2FinalScore);
            // TODO: Maybe also count results from the current round to end early
            var endScore = Rules.EndScore;
            var hasEnded = team1FinalScore >= endScore || team2FinalScore >= endScore;

            if (!hasEnded)
            {
                return(null);
            }

            TeamInfo winner;
            var      bothOverEndScore = team1FinalScore >= endScore && team2FinalScore >= endScore;

            if (bothOverEndScore)
            {
                winner = GameRoundList
                         .Where(g => g.RoundResult != null)
                         .Last()
                         .RoundResult
                         .WinningTeam;
            }
            else
            {
                winner = team1FinalScore > team2FinalScore
                    ? PlayerGroupInfo.Team1
                    : PlayerGroupInfo.Team2;
            }
            var gameResult = new GameResult
            {
                WinningTeam     = winner,
                PlayerGroupInfo = PlayerGroupInfo,
                Team1FinalScore = team1FinalScore,
                Team2FinalScore = team2FinalScore
            };

            return(gameResult);
        }