コード例 #1
0
        public static MatchType GetMatchType(Match match)
        {
            var gender = match.TeamA.TeamPlayers.First().Gender;

            if (match.TeamA.TeamPlayers.Count == 2 && match.TeamB.TeamPlayers.Count == 2)
            {
                return match.GetMatchPlayers().Any(x => x.Gender != gender) ? MatchType.MixedDouble : MatchType.Double;
            }

            if (match.TeamA.TeamPlayers.Count == 1 && match.TeamB.TeamPlayers.Count == 1 && match.GetMatchPlayers().All(x => x.Gender == gender))
            {
                return MatchType.Single;
            }

            return MatchType.Other;
        }
コード例 #2
0
ファイル: Rating.cs プロジェクト: j4kobbech/RankTangle
        public static void ModifyMatchRatings(ref Match match)
        {
            var winningTeam = match.GetWinningTeam();
            var losingTeam = match.GetLosingTeam();
            var overAllModifer = GetRatingModifier(winningTeam.GetTeamRatings.OverAll, losingTeam.GetTeamRatings.OverAll);
            winningTeam.TeamPlayers.ForEach(x => x.Ratings.OverAll += overAllModifer);
            losingTeam.TeamPlayers.ForEach(x => x.Ratings.OverAll -= overAllModifer);

            if (match.Type == MatchType.Single)
            {
                var modifier = GetRatingModifier(winningTeam.GetTeamRatings.Single, losingTeam.GetTeamRatings.Single);
                winningTeam.TeamPlayers.ForEach(x => x.Ratings.Single += modifier);
                losingTeam.TeamPlayers.ForEach(x => x.Ratings.Single -= modifier);
            }

            if (match.Type == MatchType.Double)
            {
                var modifier = GetRatingModifier(winningTeam.GetTeamRatings.Double, losingTeam.GetTeamRatings.Double);
                winningTeam.TeamPlayers.ForEach(x => x.Ratings.Double += modifier);
                losingTeam.TeamPlayers.ForEach(x => x.Ratings.Double -= modifier);
            }
        }
コード例 #3
0
        public static Match CreateMatch(Player user, FormCollection formValues)
        {
            var newMatch = new Match
            {
                CreationTime = new BsonDateTime(DateTime.Now),
                GameOverTime = new BsonDateTime(DateTime.MinValue),
                Created = new BsonDateTime(DateTime.Now),
                CreatedBy = user.Id
            };

            var playerCollection = Dbh.GetCollection<Player>("Players");
            const string MatchPlayerRegEx = "^team-(a|b)-player-[0-9]+$";
            const string MatchTeamARegEx = "^team-a-player-[0-9]+$";

            foreach (var formValue in formValues.Keys)
            {
                var formElementName = formValue.ToString();
                var formElementValue = formValues.GetValue(formElementName).AttemptedValue;

                if (Regex.IsMatch(formElementName, MatchPlayerRegEx) && !string.IsNullOrEmpty(formElementValue))
                {
                    var player = playerCollection.FindOne(Query.EQ("_id", BsonObjectId.Create(formElementValue)));

                    if (Regex.IsMatch(formElementName, MatchTeamARegEx))
                    {
                        newMatch.TeamA.TeamPlayers.Add(player);
                    }
                    else
                    {
                        newMatch.TeamB.TeamPlayers.Add(player);
                    }
                }
            }

            return newMatch;
        }