The code showed below is for “Super Card.” It is an artifact that lets you tap to draw a card or tap and pay 1 to gain a life. Super Card has 3 SpellAbilities added to the card: 1. so it comes into play as a permanent, 2. gain 1 life, and 3. draw a card. As you may or not remember, the SpellAbility class is used for all spells and abilities, hence its name. The life gaining effects costs 1 mana of any color while the draw card ability only taps the card. The resolve method of SpellAbility does the main function of any card or ability. The card’s controller is the one who gains life. If your opponent steals it during the game the effect will still work correctly and you will still own the card, but your opponent would control it. If it is put into a graveyard, it will go into its owner’s graveyard.
The setDescription method of SpellAbility sets the text that is show text box of the card on screen. The setStackDescription, also a part of SpellAbility, is the text that the stack displays. These two abilities require a different argument for the setBeforePayMana function. The setBeforePayMana function optionally lets a user do some action before choosing any targets and before paying for mana, it is the first thing that is checked when a card is clicked on. The setBeforePayMana function makes the user pay for the mana cost when gaining life, and just taps the card when drawing another card. You can put anything into the setBeforePayMana method and I added “tap abilities” late in development. setBeforePayMana accepts Input objects. Input objects process all user input through the mouse and allows the user choose targets. This way of doing abilities and tap abilities is not every elegant but it works.
AllZone is a global (static) object that can be accessed from anywhere in the program and GameAction does some logical actions like drawing a card, gaining life, discarding, etc... When this card is clicked on the user is given the choice of playing either of the two abilities.
Card card = new Card();
final SpellAbility a = new Ability_Tap(card, "1")
public void resolve()
setStackDescription(card.getController() +" gains 1 life.");
a.setDescription("1, tap: You gain 1 life.");
final SpellAbility b = new Ability_Tap(card, "0")
public void resolve()
setStackDescription(card.getController() +" draws a card");
b.setDescription("tap: You draw a card.");
b.setBeforePayMana(new Input_NoCost_TapAbility((Ability_Tap) b));