Implementing a Card Class
General Discussion of the Intricacies
Moderator: CCGHQ Admins
Implementing a Card Class
by lord of 13 » 29 Nov 2010, 01:54
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
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 - 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.
Any suggestions?
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 - 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.
Any suggestions?
><><><><><><><
Currently developing Mindgames, for playing a rules-enforced game of MtG.
RECENT PROJECTS
->XMLScript
->Zwiel Platformer
Currently developing Mindgames, for playing a rules-enforced game of MtG.
RECENT PROJECTS
->XMLScript
->Zwiel Platformer
-
lord of 13 - DEVELOPER
- Posts: 79
- Joined: 06 Jan 2010, 01:36
- Has thanked: 0 time
- Been thanked: 0 time
Re: Implementing a Card Class
by MageKing17 » 29 Nov 2010, 18:10
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).
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).
-
MageKing17 - Programmer
- Posts: 473
- Joined: 12 Jun 2008, 20:40
- Has thanked: 5 times
- Been thanked: 9 times
Re: Implementing a Card Class
by silly freak » 29 Nov 2010, 18:44
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
For effects, keep in mind that you will need to add and remove effects that apply on the object
___
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
- silly freak
- DEVELOPER
- Posts: 598
- Joined: 26 Mar 2009, 07:18
- Location: Vienna, Austria
- Has thanked: 93 times
- Been thanked: 25 times
3 posts
• Page 1 of 1
Return to Magic Rules Engine Programming
Who is online
Users browsing this forum: No registered users and 4 guests