0
\$\begingroup\$

A friend and I are currently looking at developing a game. We have 648 units that need to be defined, with 22 final values.

To define the units in the game, we've created an abstract class with 44 variables and two methods. For example, if I encounter this unit in the game, I would pass a method its value, and it would look at some sort of lookup table which give all these base, final values. The problem we've encountered is finding a method of doing this effectively, and securely.

For now I have a few units defined through enumeration, and have their values stored in an array. My partner suggested to create a defining class with a plaintext lookup table. However, I see the problem with such a solution would either be the length, or quantity of lookup tables. I have searched around, but most solutions entail the use of a server. Our current goal is to just release an offline client with everything already defined.

Does anyone have any suggestions on how to store 648 units with 22 different final attributes effectively, so that such an entity could be called later and examined?

\$\endgroup\$

1 Answer 1

8
\$\begingroup\$

Read in the data from a file. 648 lines of data, one line per unit type. Store that into an array of 648 unit prototypes. Either write the data by hand, or write a tool for it. You might consider writing the values in Excel and exporting a CSV file. (parsing suggestions here.)

Once you have the data in memory as an array of unit prototypes, making units is easy. Create an uninitialised unit instance, look up the relevant unit prototype in the array, and copy the 22 values across.

\$\endgroup\$
3
  • \$\begingroup\$ Agreed. Storing the data in a compiled or encrypted data file is fine, and you can just take the time to load it in the background at the start of the program, perhaps while the intro screen is showing. \$\endgroup\$
    – DGH
    May 9, 2012 at 17:27
  • 3
    \$\begingroup\$ 648 lines with 22 values in it will probably load in under 50ms, with most of that time spent searching for the file. \$\endgroup\$
    – Kylotan
    May 9, 2012 at 18:04
  • \$\begingroup\$ Thanks, already started on learning how to work with CSV's. This is kind of what I was looking at doing. Thanks for the answer. \$\endgroup\$
    – Bry6n
    May 10, 2012 at 15:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .