• Advertisement

Archived

This topic is now archived and is closed to further replies.

Weird Question

This topic is 6249 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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);

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement