That first card…

I almost have it… my first instant (Shock)! It took longer than I thought. I had to implement mana payment and targeting, from the engine to the UI client, as well as define the way cards are going to be declared. I also wrote a light oracle parser to ease up the integration of the cards. I’m really happy with the result though, it is pretty straightforward to add cards, provided that you are equipped with the basic building blocks for the game.. which I don’t have a whole lot of yet πŸ™‚ Here is the whole code for Shock:

    public class ShockCardFactory : MTGCardFactory
        #region Abilities

        private class ShockAbility : PlayCardAbility
            #region Overrides of Ability

            protected override IEnumerable<Cost> PlaySpecific(Spell spell)
                TargetCost target = Target.PlayerOrCreature();
                yield return target;

                spell.Effect = delegate
                    Player player = (Player)target.Result;



        #region Overrides of MTGCardFactory

        protected override PlayCardAbility CreatePlayCardAbility(Card card)
            return card.Manager.CreateAbility<ShockAbility>(card);


It only handles targeting a player for now (I don’t have a very strong creature concept right now). Still a bit long, but I think it is more due to my maniacal way of regionizing every class… I don’t think I could get the actual logic code to be any smaller. As you can see, I took an approach very similar to Incantus, where there is only one method per ability, which returns a list of costs to be played using the yield keyword. It allows the effects to then use some result discovered during that cost (in this case, the target the player chose). That’s a very clever trick, actually πŸ™‚ So thank you Incantus! You can also notice that I use a C# attribute to mark the class as the factory for the Shock card. I hope this will help me avoid the very long switch that we can find in MTGForge or Incantus and be a bit more organized about it.

If you had asked me a couple of years ago how cards should be defined, I would have answered “Xml” and would have pointed you to the “Magic Project”, now known as Firemox. Looking back at it, though, I think it really only complicates the implementation of cards and is utterly unreadable compared to code. I bet a non-coder has as much a hard time reading a Firemox card than reading it in Incantus or in Mox.

So now, I can almost shock myself with the UI (still have a couple of things to tweak out before I can actually use the card). When I can do that, I’ll take a second screenshot!


About fparadis2

Lead Game programmer
This entry was posted in Mox. Bookmark the permalink.

2 Responses to That first card…

  1. wacko says:

    So i would agree that code is awesome… and doing it the way you have is awesome, the only issue I have is that writing code for data is really not the most efficient way to do things. I think a combination of both xml and c# would have been the way to go, I was looking over your code and I think I have a pretty goof solution on how to solve this issue and make is more flexible and easy to add and remove cards.

    Like the fact that really the card has to know about this shockAbility is really going to hurt the flexibility in the long run and the level of abstraction is just bad. Because really Shock is no different then fireball or Prodigal Mage in its ability they all do damage and some are a triggered cost and some are not. I almost think this is much more complicated then it needs to be 😦

  2. Pingback: I’m on a roll | Mox

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s