I'm working on a loot-based dungeon crawler. For those that don't play games, that basically means the game involves exploring rooms or areas in search of items, be it weapons, armor, and so on. I have a system in place that randomizes what kind of "loot" is generated for each area, which is based on how far the player is in the game, and what their level is. In this particular case, the "loot" happens to be books. For each book that is generated, I need to identify the author.
In a spreadsheet I have a list of about 120 authors, with about 30 authors in 4 separate "Classes", which includes their name, a range of book values, and the years they wrote (used for setting date of the book)
I'd like to know the best method of saying "If book 1's author class is A..... go pick one of these class A guys at random."
The way I've handled this in the past is by using a switch. So I would get a random
int i
and say:
1 2 3 4 5 6 7 8 9 10 11 12
|
switch(i)
{
case 1: bookAuthor = "Johnny Babaganoush";
bookValue = valueCalc(4000, 5000);
bookYear = yearCalc(1941, 1965);
break;
case 2: bookAuthor = "That guy over there";
bookValue = valueCalc(2000, 3000);
bookYear = yearCalc(1921, 1945);
break;
}
|
... yadda yadda yadda. I'm still pretty new to c++, so I haven't learned anything about databases or referencing other files, but at the same time I don't want to go through the trouble of creating 4 massive 30-case switch functions if I'm going to learn a better technique anyway. So my question is: what way would you accomplish this? How would you set all of that information you've already established in code? Is using these switch classes totally amateurish?
edit: wording