GPWiki.org
GPWiki.org
It is currently Sat May 25, 2013 10:30 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Card Game Help
PostPosted: Thu Aug 23, 2012 8:17 pm 
Rookie

Joined: Thu Aug 23, 2012 8:04 pm
Posts: 3
Hey guys, this is my first time posting here...

I would you like some ideas for the following situation. In a card game like pokémon, for example, suppose there is a class called OptionCard derived from another class Card. OptionCard is responsible for adding specific effects to the gaming scene. Instances of OptionCard obviously represent different cards with different effects, ie instructions that specify such an effect. Well, the question is: how can I do to create different instances of OptionCard where each of them have different effects? It's like a single member function of a class execute different effects according to their instances. Any idea?


Top
 Profile  
 
 Post subject: Re: Card Game Help
PostPosted: Thu Aug 23, 2012 8:57 pm 
Dexterous Droid
User avatar

Joined: Wed Aug 18, 2004 7:40 pm
Posts: 3735
Location: South Africa
You'll have to define a bunch of modifiers at some point. Like +Strength or +HitPoints. These modifiers can be subclasses of an abstract Modifier class. Then your OptionCard can have a Modifier. Based on the kind of OptionCard (read in from a file?) you assign it a specific Modifer like StrengthModifier and go Modifier.setAmount(5). That gives a +5 Strength boost.

Maybe that's over-engineering it. You could have a giant select statement and an enum of different types of modifiers right in your OptionCard class. Then you can have a setAmount() function on the OptionCard and figure out the modifier like that.

The amount of "engineering" you should do depends on how you're dealing with other classes. Generally, moving things that are volatile and likely to change a lot out into other classes will make development and maintenance easier.

_________________
Whatever the mind can conceive and believe, it can achieve


Top
 Profile  
 
 Post subject: Re: Card Game Help
PostPosted: Thu Aug 23, 2012 9:43 pm 
Rookie

Joined: Thu Aug 23, 2012 8:04 pm
Posts: 3
Hey, IGTHORN. Thanks for your help! I really like the first idea, and I will try it.
if I have new problems, I would post here! =)


Top
 Profile  
 
 Post subject: Re: Card Game Help
PostPosted: Fri Aug 24, 2012 4:35 pm 
Bytewise

Joined: Sun Oct 16, 2011 3:09 pm
Posts: 277
Location: Here (where else?)
You can also add all the effects to ordinary cards, and control the effect with an amount, eg normal cards can have strength 1 and special cards a higher amount.
This will of course allow a card with lots of additional effects, but nobody says you have to use all possibilities of the cards that you have.

The advantage of the above is that you don't have special cases anymore.

Like most problems, there is not a single best solution, it all depends on how you see the problem, and what you are most comfortable with.

_________________
My project: Messing about in FreeRCT, dev blog, and IRC #freerct at oftc.net


Top
 Profile  
 
 Post subject: Re: Card Game Help
PostPosted: Fri Aug 24, 2012 5:01 pm 
Rookie

Joined: Thu Aug 23, 2012 8:04 pm
Posts: 3
I think this idea is good if the cards have more unique effects, right? If not, using modifiers seems more advantageous.
My program doesn't use complex effects, so I think modifiers is okay yet.

But, if I had to create complex effects, the best solution would be to create a class for each Card?
For example:
I have a class named ItemCard with a virtual and abstract function effect(...). Then I create a class Sword and implement this function according to my need.
I can do this for each of the ItemCards with a bit more freedom when it comes to implement effects.

The question is, this is big problem? (Since I have a huge number of classes, one for each card in the game).

Btw, sorry for my bad english.


Top
 Profile  
 
 Post subject: Re: Card Game Help
PostPosted: Fri Aug 24, 2012 5:52 pm 
Bytewise

Joined: Sun Oct 16, 2011 3:09 pm
Posts: 277
Location: Here (where else?)
The code for each effect has to be written no matter what.
The question however is how to reduce the clutter around that.

For each class you have to write a class definition, and perhaps some constructors and destructors.
Also instantiation will take a lot of code if each card is unique due to unique class names.

I would stop earlier, and have a limited number of Card classes, and some enum to indicate the card precisely. The effects then need to be wrapped in a switch, but there is much less other clutter in this setup.

_________________
My project: Messing about in FreeRCT, dev blog, and IRC #freerct at oftc.net


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group