예제 #1
0
파일: DnDController.cs 프로젝트: ragwap/DnD
        public int[] RaceList(int index)
        {
            string url = $"http://dnd5eapi.co/api/races/{index}";

            int[]  abilityScores = new int[6];
            string strmRes       = null;

            WebRequest request = WebRequest.Create(url);

            request.Method = "GET";

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            using (Stream stream = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(stream);
                strmRes = reader.ReadToEnd();
                reader.Close();
            }

            var serializer = new JavaScriptSerializer();

            DnDRace dnDRace = (DnDRace)serializer.Deserialize(strmRes, typeof(DnDRace));

            for (int i = 0; i < 6; ++i)
            {
                abilityScores[i] = dnDRace.Ability_bonuses[i];
            }

            return(abilityScores);
        }
예제 #2
0
파일: DnDController.cs 프로젝트: ragwap/DnD
        public Dictionary <int, string> RaceList()
        {
            string strmRes = null;
            string url     = String.Format("http://dnd5eapi.co/api/races");

            WebRequest request = WebRequest.Create(url);

            request.Method = "GET";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            using (Stream stream = response.GetResponseStream())
            {
                StreamReader streamReader = new StreamReader(stream);
                strmRes = streamReader.ReadToEnd();
                streamReader.Close();
            }

            var serializer = new JavaScriptSerializer();

            DnDRace dnDRaces = (DnDRace)serializer.Deserialize(strmRes, typeof(DnDRace));

            int i = 0;
            Dictionary <int, string> pairs = new Dictionary <int, string>();

            foreach (Results dRace in dnDRaces.Results)
            {
                string name = dRace.Name;
                ++i;
                pairs.Add(i, name);
            }

            return(pairs);
        }