I'm currently writing a trivia game for someone in VB.net (will follow similar pattern to TriviaCrack). My question is, what is the best way to contain the questions to have them display in a multiple choice fashion on the screen and their sequence to be randomized? Right now, I am thinking an array of each category, and each array randomly sequenced. I'm not sure if this would be best. Any ideas/suggestions?

Recommended Answers

All 5 Replies

Vb.net is an OOP language. So model the real world and create your classes that way.

Right.....but to point out that VB.net is OO is like saying water is wet. That's a given. However, there are some ways that are more efficient than others.

I would start by creating a class which has a string property for the question, a string list for the possible answers, and a property (your choice of type) that identifies which of the answers is the correct one. You could create a list (or Array) to contain the instances of your custom class. Unless you are talking about thousands of questions (all to be loaded at the same time) I think efficiency is irrellevent. Focus more on clear code.

Was originally thinking about all questions and the corresponding categories be loaded in the begining. Maybe that won't be fully necessary after all. This is modeled after the game TriviaCrack, to a degree. Thanks.

Jim is spot on "efficiency is irrellevent. Focus more on clear code" - that's exactly the mindset to be in.

Also in a real trivia game you have a Deck of used questions and a Deck of unused questions so you could model it that way maybe.

So if you have a Deck class you can then implement IEnumberable and your deck is then both a collection of questions and has other properties and methods too - eg GetNextQuestion

https://msdn.microsoft.com/en-us/library/dd145423.aspx?f=255&MSPPError=-2147217396

If you model things in this kind of way then your client or orchestration code will be clear, elegant and beautiful! Easy to understand and easy to maintain.

Finally if you have the time and desire then this is a great case for TDD http://www.codeproject.com/Articles/560137/NET-TDD-Test-Driven-Development-by-example-Part

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.