Hi,
I’m creating a geography quiz in which questions will be drawn randomly, about the flag, capital, population and other data.
How can I store all this data in array structure and then randomly select questions from selected categories?
For example, if the player selects questions about “population” in the “europe” category, how do I “pull them out”
I would like to create the entire database in one file.
I think you’re asking about text files? Which I wouldn’t recommend :
For one I think JSON is better…
But you’re probably better off just making classes that contain the data. Say a parent class called “Countries” and then each child class from that is “America.cs, Argentina.cs, etc…”.
Then in specific questions, that would require said country, you have a setup that gets each country you define. And in the particular facts you want from said country would just be pulled from said country class(dateOfOrigin, grossPopulation, incomePerCapita, etc…).
That way each child class of Countries can be used easily for multiple questions, you just give parameters of which countries and which data type you want from them.
Sounds like an awful lot of typing, I tip my hat to you good sir.
Yes, JSON is usually the way to go as most sources for this kind of information will already provide you the data in JSON. Some sources offer CSV files, but I would always prefer json. It’s a better and more sophisticated standard (CSV is not). A 10 second google search brought up this static data collection. Though there are usually other sources, often by governments, which are updated regularly. So that data could be pulled from a web source dynamically and cached locally. You can find a lot such sources by just looking around. Here’s another one. Though always make sure you check the license