Esempio n. 1
0
        public Dictionary <int, string> ClassList()
        {
            string strmRes = null;
            string url     = String.Format("http://dnd5eapi.co/api/classes");

            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();

            DnDClass dnDClass = (DnDClass)serializer.Deserialize(strmRes, typeof(DnDClass));

            int i = 0;

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

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

            return(pairs);
        }
Esempio n. 2
0
        public Dictionary <string, int> IsSpellcaster(int index)
        {
            string strmRes = null;
            string path    = String.Format($"http://dnd5eapi.co/api/classes/{index}");

            WebRequest request = WebRequest.Create(path);

            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();

            DnDClass specificClass = (DnDClass)serializer.Deserialize(strmRes, typeof(DnDClass));

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


            if (specificClass.SpellCasting == null)
            {
                pairs.Add("no_spell", specificClass.Hit_die);
            }
            else
            {
                pairs.Add("spell", specificClass.Hit_die);
            }

            return(pairs);
        }