Advertisement

Weird Question

Started by January 12, 2001 07:24 PM
3 comments, last by Peon 24 years ago
I was thinking of making a turn based strategy game going with classes or structs for the unit data. however, when I create a new unit, I want a new class/struct to be created. Ex: Unit1, Unit2, etc... The problem is, can I create a new class/struct where the last number is incremeted one from the last time? So I can create archer, and then archer2 is created next time, then archer3... Or is there a better way to handle units? Sorry if this is a dumb question Thanks in advance, Peon
Peon
why dont u make each unit inherit from a generic type..

such as archer inherit from bowman ....

then make the characteristics of archer attributes of bowman.

CBowman archer = new CBowman();

archer.setProp(SHOOT_DIRECTLY);

CBowman archer2 = new CBowman();

archer.setProp(SHOOT_WILDLY);
Advertisement
i would should use a linked list for each type. that way there''s just 1 list w/ it''s own count. or u could use an array(i.e. archer[0], archer[1]...). u could have a set max # or u could make a default size for the array and just resize it as needed. i hope this helps.
--I don't judge, I just observeStuck in the Bush's, Florida
At risk of insulting your programming ability (and mine), I am going to ask a stupid question. Are you trying to hard-code every single unit in the game? I am going to continue as if that is the case, but if it isn''t, disregard this post . How would the player build new units if the unit names are all written directly in the source code. Your example seems to show you making the names of the objects change depending on what unit is being made. To my knowledge, that isn''t possible. You need to make an array, then you don''t need to deal with names at all. Just have an index number somewhere that tells you where in the array to add the next unit.

--------------------


You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming


You are unique. Just like everybody else.

Yanroy@usa.com

Visit the ROAD Programming Website for more programming help.

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

I considered an array, it would just be so big

ex:

mage 45HP 50MP 1AT 1DF 1RN etc...

and that would be only one unit It would be slow I think, but then again I don''t really know a thing about speed, hehe. It''s easy enough though.

I think linked lists sound good, I''ve just never used em. Anyone have a good site w/ a linked list tutorial?

Oh yeah, I''m going to *try* to have each base unit have a text file defining the base stats (change w/o recompile, easy to add expansion, etc...)

Thanks,

Peon
Peon

This topic is closed to new replies.

Advertisement