Monday, April 19, 2010

What is a Card?

What is a card is a complicated question. In real life a card is a physical object. In Forge a card is a class, a piece of code. At first the card object started out simple. It had the basic methods: getName(), getManaCost(), getOwner(), getController() and getAttack(), getDefense(). But as Forge grew the card class grew as well. Now the card class has two pages of variables and around 200 methods. (I’m not saying that the Card class is too big, I’m just saying that it is big.)

The Card class keeps track of lots of information such as “is this card tapped”, “does this creature have summoning sickness”, and “which keywords does this creature have”. The Card class also keeps track of other obscure data like “who dealt damage to me”, “is this card uncastable”, “did this creature attack or block this turn”, “is this a morphed creature”, “should this card be sacrificed at end of turn” and “how much damage does this card deal damage during the upkeep”.

Other convential Card attributes include keywords and Forge implements a whole number of Magic keywords such as flying, haste, wither and as well as other “internal keywords” that correspond to spells and abilities, which makes it much easier to add cards like Shock and Ancestral Recall. Forge’s “interal keyword” system has gotten very sophisticated and implements such cards as Blossoming Wreath. A full list of keywords can be found on the forum here.

Blossoming Wreath
G
Instant
no text
spGainLife:X:You gain life equal to the number of creature cards in your graveyard.:Blossoming Wreath - player gains X life
SVar:X:Count$TypeInYourYard.Creature

In real life Magic if a card creates or copies a card, a token is created. In Forge the same thing happens except that a token has special properties like it cannot go to the graveyard or be bounced to your hand. One of the first “extra” methods that I ever added to the card class was setToken(boolean) and isToken() which simply answers the question, “Is this card a token?”.

The first card that created tokens was probably Future Sight’s Llanowar Mentor. An odd thing happened when I used its ability. A token was created but I was surprised to see that the token had the picture for Llanowar Elves. The second token maker I coded was Raise the Alarm which makes two 1/1 tokens for 1W. And the third card was probably the awesome, fan-favorite Kiki-Jiki, Mirror Breaker.

WOW, I just realized the Forge now has 11 cards with unearth. (1R: Return this card from your graveyard to the battlefield. It gains haste. Exile it at the beginning of the next end step or if it would leave the battlefield. Unearth only as a sorcery.)

You can see the full Java source code for the Card class here.

p.s.
Technically the methods getAttack() and getDefense() should be named getPower() and getToughness but I like the terms attack and defense better.

p.p.s.
In case you don’t understand, the words “object” and “class” they just mean “lines of Java source code”.

2 comments:

  1. "In Forge the same thing happens except that a token has special properties like it cannot go to the graveyard or be bounced to your hand!

    Minor correction - the token does go to your hand/graveyard momentarily before it vanished forever.

    Enjoying the blog! :)

    ReplyDelete
  2. "The first card that created tokens was probably Future Sight’s Llanowar Mentor."

    How about Rukh Egg from Arabian Nights? There were token creatures around almost from the start.

    ReplyDelete

Note: Only a member of this blog may post a comment.