Advertisement

Stupid untits and vectors

Started by May 15, 2006 01:09 PM
2 comments, last by kevtimc 18 years, 9 months ago
Hello, im a bit of a n00b so please try and give an exapmle where possible. I need a way to keep track of units in a game, would a vector like this be a good way to do it? Vector<ship*> mShips; (sorry if it has invalid syntax) [Edited by - danharibo on May 15, 2006 2:22:59 PM]
I'm not sure that this is the right forum for this sort of question - it sounds more like a technical coding problem than a gameplay design issue.

In any case, your question is a rather vague and I'm not entirely sure what you're asking for. If you could clarify it a bit I'll move it to the appropriate forum.
Advertisement
Yes, you could use a vector. It's possibly your best bet (either that or a list). Check out the documentation for STL.

(Also, wrong forum :) )

Check out my new game Smash and Dash at:

http://www.smashanddashgame.com/

Quote:
Original post by danharibo
Hello, im a bit of a n00b so please try and give an exapmle where possible.
I need a way to keep track of units in a game, would a vector like this be a good way to do it?
Vector<ship*> mShips; (sorry if it has invalid syntax)


First you should declare <vector> at the top, figure out what type of vector it will be (ill use <string>) and walla ...

vector<string> vGameUnits;

if you ever want to display these units, use and iterator.

vector<string>::iterator Iter;

for(Iter = vGameUnits.begin(); Iter != vGameUnits.end(); ++Iter) {
cout << *Iter << endl; // I use a "*" to tell the compiler to print the reference of Iter, otherwise it would always print vGameUnits.begin()
}

This topic is closed to new replies.

Advertisement