Esempio n. 1
0
        // Event: go is clicked. Gets data for summoner and region and populates
        //        champions. The alphabetically first champion is chosen and
        //        champions_TextChanged() is called.
        private void go_Click(object sender, EventArgs e)
        {
            overallWin.Text = String.Empty;
            overallWin.Refresh();

            status.Text    = String.Empty;
            status.Visible = true;
            status.Refresh();

            champions.Items.Clear();
            champions.Text = String.Empty;
            champions.Refresh();

            data.DataSource = null;
            data.Refresh();

            String regionLower = region.Text.ToLower();

            model = new Model(regionLower);
            String summonerIdUrl = Coder.GetSummonerIdUrl(regionLower, summoner.Text);

            // invalid summoner name and or region
            if (model.reader.Request(summonerIdUrl).Equals(String.Empty))
            {
                System.Windows.Forms.MessageBox.Show("invalid summoner name and or region");
                return;
            }

            String summonerIdJson = model.reader.Request(summonerIdUrl);

            model.StorePersonalHistory(summoner.Text, status);
            model.StoreGlobalHistory(status);
            model.CalcChampionStats();

            foreach (int championId in model.championStats.Keys)
            {
                champions.Items.Add(model.championNames[championId]);
            }

            champions.SelectedIndex = 0;
            champions_SelectedIndexChanged(String.Empty, new EventArgs());
            champions.Visible = true;

            status.Text = "done with " + model.CountMatches() + " games";
            status.Refresh();
        }
Esempio n. 2
0
        public Model(String region)
        {
            reader      = new Reader();
            this.region = region;

            // populate championNames and championIds
            String          champions   = reader.Request(Coder.GetChampionNamesUrl());
            Regex           regexId     = new Regex("\"id\":(\\d+)");
            MatchCollection idMatches   = regexId.Matches(champions);
            Regex           regexName   = new Regex("\"name\":\"([^\"]+)\"");
            MatchCollection nameMatches = regexName.Matches(champions);

            for (int i = 0; i < idMatches.Count; i++)
            {
                int    id   = Convert.ToInt32(idMatches[i].Groups[1].Value);
                String name = nameMatches[i].Groups[1].Value;
                championNames[id] = name;
                championIds[name] = id;
            }
        }