Exemple #1
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values.Length != 2)
            {
                return(null);
            }

            Matchup    matchup    = values[0] as Matchup;
            Tournament tournament = values[1] as Tournament;

            if (matchup == null || tournament == null)
            {
                return(null);
            }

            string[] tags = new string[matchup.Player1Tags.Count];
            int      i    = 0;

            foreach (var kv in matchup.Player1Tags)
            {
                var tag = kv.Key;

                tags[i] = string.Format("{0} {1}/{2}", tag, matchup.Player1Tags[tag], matchup.Player2Tags[tag]);
                i++;
            }
            return(string.Join(", ", tags));
        }
Exemple #2
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values.Length != 2)
            {
                return(null);
            }

            Matchup    matchup    = values[0] as Matchup;
            Tournament tournament = values[1] as Tournament;

            if (matchup == null || tournament == null)
            {
                return(null);
            }

            if (matchup.CurrentResult == Result.STILL_PLAYING)
            {
                return("Jugando");
            }
            else if (matchup.CurrentResult == Result.DRAW)
            {
                return("Empate");
            }
            else
            {
                int winner = matchup.CurrentResult == Result.PLAYER1_WIN ? matchup.Player1Id : matchup.Player2Id;
                return(string.Format("Victoria para {0}", tournament.Players[winner].Name));
            }
        }
        public Matchup Clone()
        {
            Matchup clone = new Matchup();

            clone.Table         = Table;
            clone.Round         = Round;
            clone.CurrentResult = CurrentResult;
            clone.Player1Id     = Player1Id;
            clone.Player1Tags   = new Dictionary <string, int>(Player1Tags);
            clone.Player2Id     = Player2Id;
            clone.Player2Tags   = new Dictionary <string, int>(Player2Tags);

            return(clone);
        }
 public static bool TestPlayerScoreFormulaValid(Tournament tournament)
 {
     try
     {
         Dictionary <string, int> scorePerTag = new Dictionary <string, int>();
         foreach (var tag in tournament.Config.Tags)
         {
             scorePerTag[tag.Name] = 0;
         }
         // Calculated tags may depend on previous values to we have to iterate two times
         foreach (var tag in tournament.Config.Tags)
         {
             scorePerTag[tag.Name] = Matchup.CalculateTag(tag, scorePerTag, scorePerTag);
         }
         CalculatePlayerTotalScore(tournament, 0, scorePerTag);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemple #5
0
        public ViewMatchup(Matchup _sourceMatchup, Tournament _sourceTournament)
        {
            SourceMatchup    = _sourceMatchup;
            SourceTournament = _sourceTournament;

            IndexCurrentResult = (int)SourceMatchup.CurrentResult;
            Tags = new DataTable();
            var column = Tags.Columns.Add("Tag", typeof(string));

            column.ReadOnly = true;
            Tags.Columns.Add(Player1Name, typeof(int));
            Tags.Columns.Add(Player2Name, typeof(int));

            foreach (var tag in SourceTournament.Config.Tags)
            {
                if (tag.Type == TagType.Calculated)
                {
                    continue;
                }

                Tags.Rows.Add(tag.Name, SourceMatchup.Player1Tags[tag.Name], SourceMatchup.Player2Tags[tag.Name]);
            }
        }
Exemple #6
0
        public void UpdateMatchupWithView()
        {
            SourceMatchup.CurrentResult = (Result)IndexCurrentResult;
            foreach (DataRow row in Tags.Rows)
            {
                var tagname = (string)row["Tag"];
                var player1 = (int)row[Player1Name];
                var player2 = (int)row[Player2Name];
                SourceMatchup.Player1Tags[tagname] = player1;
                SourceMatchup.Player2Tags[tagname] = player2;
            }
            foreach (var tag in SourceTournament.Config.Tags)
            {
                if (tag.Type != TagType.Calculated)
                {
                    continue;
                }
                SourceMatchup.Player1Tags[tag.Name] = Matchup.CalculateTag(tag, SourceMatchup.Player1Tags, SourceMatchup.Player2Tags);
                SourceMatchup.Player2Tags[tag.Name] = Matchup.CalculateTag(tag, SourceMatchup.Player2Tags, SourceMatchup.Player1Tags);
            }
            SourceTournament.UpdateRanking();

            SourceTournament.Save();

            // Band aid because there should be no need to execute this
            // to make the datagrid refresh
            var round            = SourceTournament.Rounds[SourceMatchup.Round - 1];
            var updated_matchups = new List <Matchup>();

            foreach (var matchup in round.Matchups)
            {
                updated_matchups.Add(matchup);
            }
            round.Matchups = updated_matchups;
            round.OnPropertyChanged("Matchups");
        }