Jump to content
  • Advertisement

Archived

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

BradDaBug

Question

This topic is 6199 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

If I were creating a game, say an RPG, and it had several items that were mostly alike, but a tiny bit different, like maybe some food. Say some different food types were, cheeseburger, pepsi, pizza, fries, raisins...junk like that. Would I create several different classes, like a class for cheeseburgers, one for pepsi, one for pizza...etc, or would I just create one general class like CFood, then have a Type field? Lets say the only difference between these different items is their cost, their sprite, and their name.

Share this post


Link to post
Share on other sites
Advertisement
example:


class ph00d
{
public:
short type;
short cost;
short value;
char *sprite;
};


then just use a switch statement:


switch(ph00d.type)
{
case HAMBURGER:
cost = 1$;
value = 10;
sprite = "sprites/hamburger.spr";
break;
case PEPSI:
cost = 0.5$;
value = 3;
sprite = "sprites/sprite.spr";
break;
default:
cost = 0$;
value = -100;
sprite = "sprites/poo.spr";
}


perhaps...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I didn''t know that was an option.

Share this post


Link to post
Share on other sites
I''d go with the CFood class that Tjoppen gave an example for, just not sure that the case statement would be necessary since the types attributes are already fixed and should be hard coded or accessed from a file, then in the process phase of the game the case statement could be used to get (not set) the attribute data dependant in the type gathered.

Just a thought.

Share this post


Link to post
Share on other sites
I just wrote some crap, but i suppose you just set all those values with a constructor

ph00d::ph00d(short type)
{
(that case statement)
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!