Exemplo n.º 1
0
        private void ImportPokemon(object obj)
        {
            var dialog = new ImportPokemon();

            if (dialog.ShowDialog().Value)
            {
                using (var client = new WebClient())
                {
                    try
                    {
                        var json       = client.DownloadString(dialog.Url);
                        var pokemonSdk = JsonConvert.DeserializeObject <JsonPokemon>(json);

                        var pokemon = PokemonCreator.CreateCardFromSdkCard(pokemonSdk);

                        PokemonCards.Add(new PokemonViewModel(pokemon));
                        SelectedCard             = PokemonCards.Last();
                        SelectedCard.Card.CardId = NetworkId.Generate();
                    }
                    catch
                    {
                    }
                }
            }
        }
Exemplo n.º 2
0
        private async Task ImportPokemonSet(object arg)
        {
            using (var client = new WebClient())
            {
                var json = await client.DownloadStringTaskAsync($"https://api.pokemontcg.io/v1/cards?setCode={SelectedSet.SetCode}&supertype=Pok%C3%A9mon").ConfigureAwait(false);

                var headers = client.ResponseHeaders;

                int cardsFound = int.Parse(headers.Get("Count"));
                int pageSize   = int.Parse(headers.Get("Page-Size"));

                if (cardsFound > pageSize)
                {
                    //TODO
                    MessageBox.Show("There are more cards!!!");
                }
                var pokemons = new List <PokemonViewModel>();
                foreach (var card in JsonConvert.DeserializeObject <JsonPokemonList>(json).Cards)
                {
                    var pokemon = PokemonCreator.CreateCardFromSdkCard(card);

                    var model = new PokemonViewModel(pokemon);
                    model.Card.CardId = NetworkId.Generate();
                    pokemons.Add(model);
                }

                foreach (var pokemon in pokemons.OrderBy(x => x.Card.Name))
                {
                    PokemonCards.Add(pokemon);
                }

                SelectedCard = PokemonCards.First();
            }
        }
Exemplo n.º 3
0
        public void TestBuilder()
        {
            //Blastoise!
            var blastoiseCreator = new PokemonCreator(new BlastoiseBuilder());

            blastoiseCreator.CreatePokemon();

            var blastoise = blastoiseCreator.GetPokemon();

            Assert.AreEqual("Blastoise", blastoise.Name);
            Assert.AreEqual(PokemonRegion.Kanto, blastoise.Origin);
            Assert.AreEqual(PokemonType.Water, blastoise.Type);

            //Incineroar!
            var incineroarCreator = new PokemonCreator(new IncineroarBuilder());

            incineroarCreator.CreatePokemon();

            var incineroar = incineroarCreator.GetPokemon();

            Assert.AreEqual("Incineroar", incineroar.Name);
            Assert.AreEqual(PokemonType.Water, incineroar.Weakness);
            Assert.AreEqual(180, incineroar.HealthPoints);
        }