Page 1 of 1

Implementing a Card Class

PostPosted: 29 Nov 2010, 01:54
by lord of 13
Well, I'm well into my implementation of a card class by now, and all I have left to do is the actual effects. o_O
code_Card.cs.png
Current implementation of the card class

So, I thought I'd ask those who've done this before how they did it - store a array/list/arraylist of effects and update them each time, use a handful of overriden methods that interface with the GameEngine, or one of a million other ways.
I can try to stumble through is on my own - check out my blog to see that :P - but I'd prefer to make a guided effort to ensure the best chance of success. I would like the mid-level design to avoid being a one-man job, especially since two heads are better than one. :P

Any suggestions?

Re: Implementing a Card Class

PostPosted: 29 Nov 2010, 18:10
by MageKing17
You should probably have some sort of "Effect" class and a way to retrieve all Effects acting on a Card. Incantus does not do this; it has lots of problems as a result.

One thing Incantus does that you should do, though, is to store values as "stacked variables", which is to say, an object that returns a specific value, but uses an internal stack (which can contain "replacement values" for things like "target creature becomes a Snake", "subtractive values" for things like "target creature loses flying", and "additive values" for things like "target creature becomes a Snake in addition to its other types") to determine what that value is. There are some things we don't store as stacked variables; this is only because we haven't gotten around to making them stacked. In fact, even our functions can be stacked: a replacement effect like "if you would gain life, gain twice that much life instead" is implemented as a new function that replaces the existing life-gaining function (with a self-referential call; the stacked_function class handles not allowing the same replacement to handle the same call twice).

Re: Implementing a Card Class

PostPosted: 29 Nov 2010, 18:44
by silly freak
If you like, you could try look here what approach I took. In a nutshell, the actual characteristics are not directly stored in the card class, which allows you to implement split and flip cards later.

For effects, keep in mind that you will need to add and remove effects that apply on the object