Programming a card - a short intro
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
1 post
• Page 1 of 1
Programming a card - a short intro
by 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 {}.
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.
- 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 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
1 post
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 48 guests