Improving Pokémon Quiz
After the success of my previous effort, I realized there was a lot left undone. I wasn’t happy with the quality of the PokemonQuiz
code, and there were some bugs that I had found.
6f2ceb3ce707c227a3da8b25b46d2f4f1a486408
My first priority here was to figure out why pokeApiClient.GetNamedResourcePageAsync<Pokemon>()
was returning a .Count
of 1,200+. I suspected it had something to do with variations, such as different types of Burmy, and looking at the docs, I was right. I want to select a random species and then from each species, select a random variety (of which there are usually just one).
This doubles my number of network calls since I have to request the species and variety separately. Perhaps we can make it up by making the similar groups of network calls in parallel? Done. This is possible thanks to Tasks.WhenAll()
from the System.Threading.Tasks
namespace.
Now that we’re dealing with the Pokemon
in arrays, we can just store the PokemonSpecies[]
and Pokemon[]
we’re using and let go of the rightPokemon
variable.
fd153e42d4a43fa6cabb413f34effd327cfc66e4
I’m getting intermittent crashing where the PokeApiNet library is getting null
for base_experience
, so I’d better update my dependency. That’s pretty easy, but now I’ve gone and reformatted my PokemonQuiz.csproj
file with proper line-endings. Well, that’s progress.
With that done, I’m going to look at the units that the API is returning, like hectograms and decimetres. Nobody uses those, so let’s switch to kilograms and metres.
Sometimes the Sprites
come back with a null
entry, so rather than crashing, we should show a ? or something. This will do that.
I have a bug where the cursor stays as an arrow while the SilhouetteForm
is being dismissed (for two seconds!) so let’s fix that.
4777612cb9627f07c7269bf97725c3e9f2d098e7
I’ve noticed that I’m asking which species a Pokémon is, which is silly, so I’ll convert it to asking which egg groups it’s from. This is all just silly, anyway. Done.
While I’m at it, I’ll stop using StringBuilder
and instead use string.Join()
to build my lists. Looking fine!
Finally, the Bitmap
code I wrote before doesn’t actually work with the placeholder filename. I’m using the wrong constructor. Done.
Takeaways
C# and the CLR have come a long way in ten years. We have simple task execution, lambda functions, and a great package ecosystem to save time programming. While this won’t make me switch back to being a .NET developer, it’s certainly interesting to watch the direction Microsoft is going with it.