   Game classes
    I got a question about player pieces in a game. I just want to make sure I am doing this right. Basicly what you want to do is create a class for each unit and have a pointer in the class that points to the graphic. I got two questions on this  1. When the game starts up should I open the unit file and fill all the structures for the game or should I open it fill a few of the structures then close then open the file again when I need more units? 2. When a unit may have two graphics and stats is it better to have two different classes for the unit one for each graphic or should I put some type of statement in the class and just change the graphic the pointer points to and change the other states? 
  i do not understand your first question, but for the second you basically want a switch. Your unit will often have some kind of state like IDLE, FIGHTING, RUNNING, or whatever. so then you just put in a switch where each state has an attached graphic.switch (state) { /* case statement for each state/pose */ }look up animation trees or similar topics in the AI folder (of all places)In my structures, the first time one is created (and only the first time) it goes and grabs all the necessary files off the hard drive and converts them to to static member graphic surfaces (all objects can share them while only having one copy in memory). ;  I am sorry thats what I get for not thinking the question thro before posting.  What I got is a game that uses two sided playing pieces and each unit has an attack strength, defens and movement value and the unit graphic and values change per side.  Now what I did was create a unit class and put all the info for the units in a text file. When the game starts the text file will open and fill the classes.  The first question I have is should I open the file once at the begining of the game and fill all the classes for the 500+ units or should I just fill the ones I need for a few turns close the file then reopen/cloase the file ever few turns?   The secound question was with the changing of the graphic and the values. I was not sure if I should just create two class for each unit (one front and one back) but I am quessing I could use the switch statement mentioned in the above post to set the variables and the graphic pointer to the right stuff ;  if your difference is just which side it''s on, i think it''s too trivial to warrant seperate classes. Just have this:class Unit {   // variables and whatnot // draw function   void Draw() {  if (side == 0) {   DrawGraphicA();   }  if (side == 1) {   DrawGraphicB();   }  }   }  For loading stats, if memory is no concern, just load them all up on startup. If each unit has only attack, defense, life a few other integer stats, x500 units, that''s still a rather petty amount of information. Lets look at it this way: Let''s say each unit has 6 basic integer stats. That''s 4 bytes x 6 = 24 bytes p/ unit * 500 = 12kb. "12kb!?!?!" you say? Yes! all that data fits into something smaller than a single user interface bitmap! sure, load up 500 units with info. Heck, load up 5,000, or even 50,000 with little impact on performance. Now if each unit has a special graphic as well, no we run into problems. One thing you might consider is doing an "overlay" graphic. For instance, each unit type has it''s asociated graphic. Then, to show sides, overlay that unit with some kind of transparent color overlay to show side. Basically you are building the graphic dynamically before the user sees it. In my game, i have 8 basic unit types, each unit type also has an associated 5 different attack types and 5 defense types. Each type of each thing needs a graphic, so instead of creating 8*5*5 = 200 graphics, i created 8, then 5, then another 5 = 18 and then just overlayed the images dynamically when they are needs to create a final graphic on the screen.   ;  oh, and this little bit works good too:class Unit {   static bool data_loaded;    Unit::Unit() { if (!data_loaded) {    LoadMyDataFromFile( "some_file.txt" );    data_loaded = true;    } }   }  that way, it''s loaded on the first run without your stopping to chek whether or not it has been done already and it only loads the info when needed. ;  You may want to have a look at derived classes as well, they will help a lot I''m sure. That way you can have 1 class for the basices that everything will have and then you can have derived classes for  other units. 