Thread: Strategy game -- Forming units.

  1. #1
    Registered User
    Join Date
    Jan 2005

    Strategy game -- Forming units.

    I'm doing this text-based strategy game. Anyway, one aspect is that you can form X number of soldiers into a unit. Obviously I'm going to have a unit class for this, but like, okay, I can't really have a pre-define amount of unit OBJECTS because there's never really going to be a stable amount of units present. My initial thought is to use NEW to create a new one and then delete it whenever said unit is killed. Is there a better way to do this?

  2. #2
    Registered User
    Join Date
    Apr 2002
    I would use either a STL vector or list container depending on your requirements. If you haven't used the STL before I would suggest googling for some tutorials but it is very easy once you get the hang of it.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User
    Join Date
    Jan 2005
    Alright, I figured I'd probably end up using a vector here. Just curious, but don't vectors dynamically allocate... stuff? I'm assuming here that instead of having a vector of pointers to unit object, I'd just have a vector of units directly; at this point, I'd need to modify unit at vector position i to have whatever values I want the new pointer to have, correct? And if I needed to remove a unit, I'd knock it out of the vector, and on creating a new one... I'd search through for the first non knocked out value, I assume?

    (I can think of several ways of making a value knocked out. Don't take that too heavily).

    I guess my next goal is finding a method of manipulating the buggers. I can do that on my own (ORganize them by some method, I guess, or rather, search througfh them based on a certain variable). I'm just not really sure HOW to differentiate them.

    On actually executing stuff during a turn I wouldn't really need this. It's more for assigning actions. Would I have them assume the variable marking their position in the vector as an ID number, and simply have a "Enter unit ID" prompt somewhere, and a "Show ID" command elsewhere?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please comment on my c++ game
    By MegaManZZ in forum Game Programming
    Replies: 10
    Last Post: 01-22-2008, 10:03 AM
  2. craps game & dice game..
    By cgurl05 in forum C Programming
    Replies: 3
    Last Post: 03-25-2006, 06:58 PM
  3. C++ Game of Life Program
    By rayrayj52 in forum C++ Programming
    Replies: 16
    Last Post: 09-26-2004, 03:58 PM
  4. Try my game
    By LuckY in forum A Brief History of
    Replies: 14
    Last Post: 09-15-2004, 11:58 AM
  5. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 04:19 AM
Website Security Test