It is currently 03 Sep 2025, 22:51
   
Text Size

Programming a card - a short intro

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Programming a card - a short intro

Postby mtgrares » 21 Jun 2010, 20:52

I'll give you the brief tour of the source code. Most of the card code is in one of the CardFactory classes. CardFactory creates and returns new card objects. CardFactory is a little insane and is basically one big method, each card has its own "variable scope" because each card object is enclosed is separate brackets {}.

Code: Select all
CardFactory.getCard(String cardName, String playerOwner)
{
  if(cardName.equals("Forest"))
  {
      //create Forest card object and return it
  }

  if(cardName.equals("Mountain"))
  {
      //create Mountain card object and return it
  }
  etc...
}
Cards that have "state effects" like Glorious Anthem, Slivers, Goblin King are in two places CardFactory and GameActionUtil.checkStateEffects(). State effect cards are more complicated but you can copy and paste most of the code from an existing card.

Cards must also have their "basic information" in cards.txt, which stores the cards name, mana cost, and some of the text.

Feel free to ask any questions. We are just a bunch of guys who like Magic and programming. Forge doesn't really have any documentation, so people try to find a card that is similar to a new card that they want to program. The planeswalkers are exceptionally complicated because they were written before Forge had the concept of counters.

Sooner or later the Input class will probably become a problem. I wrote extensively about it here: viewtopic.php?f=52&t=1461 The simple way to "turn on" or "turn off" the Input button OK and Cancel is by using ButtonUtil.

Cards that have effects that you may want to copy and modify:
Gravedigger - when creature is played - target graveyard
Flametongue Kavu - when creature is played - target creature
Aven Fisher - when destroyed, draw a card
Mudbutton Torchrunner - when destroyed, target creature or player
Giant Growth - end of turn effect
Wrath of God - destroy all creatures

Also read the file "Readme - Source Code.html" in case you never have. It has longer examples. You can view it online here.
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 48 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 48 users online :: 0 registered, 0 hidden and 48 guests (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 48 guests

Login Form