Beispiel #1
0
 private static void addLabels(PokeType type, JArray otherTypes, Effectiveness level)
 {
     foreach (JToken otherTypeToken in otherTypes)
     {
         String   otherName = (string)otherTypeToken["name"];
         PokeType otherType = cachedTypeNames[otherName];
         effectivenessMatrix[type.Id, otherType.Id] = level;
     }
 }
Beispiel #2
0
        public static async Task <PokeType> Get(int id)
        {
            PokeType result = new PokeType(id);

            if (!cachedTypes.ContainsKey(id))
            {
                cachedTypes[id] = await result.InitializeAsync();

                cachedTypeNames[cachedTypes[id].Name] = cachedTypes[id];
            }

            return(cachedTypes[id]);
        }
Beispiel #3
0
        private async Task <Pokemon> InitializeAsync()
        {
            Task <byte[]> imageTask = Utilities.GetPokemonImage(id);
            JObject       data      = await Utilities.GetPokemon(id);

            if (data == null)
            {
                throw new KeyNotFoundException("Pokemon ID #" + id + " does not exist");
            }



            name         = (string)data["name"];
            resourcePath = (string)data["resource_uri"];
            stats        = new Stats(data);
            foreach (JToken type in (JArray)data["types"])
            {
                types.Add(await PokeType.Get((string)type["name"]));
            }

            image = await imageTask;

            return(this);
        }