1. Program each card directly into the programming language.
2. Use text or XML.
3. Combine options one and two. First you use option two and then you generate the source code from the text or XML.
Let me explain each option in more detail. I use option one in MTG Forge. I write out the functionality of each Magic card directly in Java. This option is the most inflexible because you can’t easily change cards.
Option two is the most flexible and I use it in the cards.txt file. I can easily add creatures that only need a few keywords. I’ll show you a sample of cards.txt in case you have never seen it.
3 W W
Option three is complicated. In essence you are adding another step every time you compile. First the source code is generated and then you compile everything. I include it here strictly as a theoretical option.
Now for the summary. I’m going to get technical so it is ok to skip this part. Option 1 creates cards at compile time while option 2 creates cards at runtime. As a programmer we all know that runtime is generally good. The trick is how do you condense a Magic card into reusable parts that can be written as text?
Everywhere I say text I mean plaintext but I didn’t want to confuse people. Does the average person know what plaintext means?
p.p.s. The Firemox project uses XML for all of its cards.
The other main problem when trying to program Magic is how to layout the screen. Even the folks at Wizards are having a tough time with that.
Here is an example of option one, a card hard coded in Java. This is the actual code for Stone Rain (2R, sorcery, destroy target land) taken from MTG Forge. I stripped out the AI routines, but they are pretty good. If you have 2 Forest and 1 Mountain in play, the AI will target the Mountain.
if(cardName.equals("Stone Rain") )
SpellAbility spell = new Spell(card)
public void resolve()
//is target card in play?
};//end - SpellAbility
}//end Stone Rain