コード例 #1
0
        private GroupEntryViewModel GetGroupEntry(GroupTeam team, IEnumerable<Game> games)
        {
            var players = new List<string>();
            if (team.Player1 == null)
                players.Add("Computer");
            else
            {
                players.Add(team.Player1.Name);
                if (team.Player2 != null)
                    players.Add(team.Player2.Name);
            }

            var model = new GroupEntryViewModel
            {
                TeamName = team.Team.Name,
                PlayerNames = players,
            };

            foreach (var game in games.Where(g => g.Status != GameStatus.NotPlayed))
            {
                if (game.Team1.Equals(team.Team))
                    model = CalculateTeamStats(model, game.Team1Score, game.Team2Score);
                else if (game.Team2.Equals(team.Team))
                    model = CalculateTeamStats(model, game.Team2Score, game.Team1Score);
            }

            return model;
        }
コード例 #2
0
        // simple isclinched function
        private bool IsClinched(GroupEntryViewModel teamStat, IEnumerable<GroupEntryViewModel> standings)
        {
            int numLower = 0;
            foreach (var standing in standings)
            {
                if (standing.TeamName == teamStat.TeamName)
                    continue;

                int gamesLeft = 3 - standing.PlayedGames;
                int maxPoints = standing.Points + (3 * gamesLeft);
                if (teamStat.Points > maxPoints)
                    numLower++;
            }

            return teamStat.IsPromoted = numLower >= 2;
        }
コード例 #3
0
        private GroupEntryViewModel CalculateTeamStats(GroupEntryViewModel model, int myTeamScore, int theirTeamScore)
        {
            model.GoalsFor += myTeamScore;
            model.GoalsAgainst += theirTeamScore;

            if (myTeamScore > theirTeamScore)
                model.Wins++;
            else if (myTeamScore == theirTeamScore)
                model.Draws++;
            else
                model.Losses++;

            return model;
        }