Monday, June 27, 2011

Forge - the Beginning

In the beginning there was no Forge and the world was sad.  The only software available at the time was Shandalar, which ran quite well despite being written in 1997.  The very first part of Forge that I wrote was a simple user interface (ui) because I knew that the whole project was basically a videogame and videogames need to have a good ui. 

My ui skills (and still are) limited and I didn’t know how to show a tapped card.  At the time cards on the battlefield were displayed only as colored boxes, which you can see if Forge cannot find the card picture.  My solution was to stick the word “tapped” inside of the colored box.  In a way it was very ugly but at least the user wouldn’t confuse tapped and untapped cards.

After I got a basic ui working, I knew that I needed a strategy to handle the mouse and it was going to be a pain in the neck.  How was I supposed to restrict targeting possibilities for cards like Terror – no black or artifact creatures or Assissinate – destroy target tapped creature?  And how do I combine the card code and the mouse code?  Thankfully I found the state pattern.  At first the state pattern was a little hard to understand (grok) but after writing some simple code and running it, everything made perfect sense. 

(I wondered how other Magic programs handled the mouse and did they also use the state pattern?  More than likely they didn’t but I have no idea how to handle the mouse without using the state pattern.  You can read more about the state pattern and how I applied it to the mouse here, here and here.)

After I got a basic user interface and mouse working, I added the phases which only consisted of a message stating the phase name.  Just clicking the OK button and watching Forge cycle through the phases was very exciting even though the program didn’t actually do anything yet.  After that I worked on the card class and the “card detail window” which is on the right side and shows all of the card information.  (Ideally the card picture would be created on-the-fly like Magic Online and would have all of correct text information like if your creature was pumped up with Giant Growth.)

Even though the user could see all of the card information, without seeing the actual card picture the user interface was especially bland.  Since I couldn’t display the card picture on the battlefield because I didn’t know how, I had the bright idea to show the card picture in a panel by itself.  While this was only a small step, it really made Forge seem like a real program. 

Tanks for reading,
mtgrares

p.s.
--Actually I did know how to resize the card pictures and put them on the battlefield but I couldn’t figure out how to rotate them.  Thankfully, after a few months somebody sent me a nifty one line fix.

--I tried to use as many design patterns as I could.  “End of turn” effects used the command pattern.  The quest data was saved using the memento pattern.  My advice is to always save data as primitives (ints, Strings) instead of saving whole objects.  That way when you want to change how your data is saved, you can easily read the primitives versus trying to read an older version of an object.

--Forge is probably my 4th iteration at programming Magic.  The first three projects collapsed because of fundamental archetecture problems.

6 comments:

Pridwen said...

Thank you very much for the great work!
Forge - a wonderful project and I wanted to developed and he became even better, please do not leave it, and at least a little bit, but still moving forward.
I wish you all the best and success in all spheres of life. I apologize for my "English", it is not my native language :)

Ivo Carvalho said...

Are you programing card by card?

Forge said...

"Are you programing card by card?"

Only if the card is very complicated like planeswalkers. Usually cards are added "in bulk" by using scripted keywords. Shock is shown below and is implemented using just text.

Name:Shock
ManaCost:R
Types:Instant
Text:no text
A:SP$ DealDamage | Cost$ R | Tgt$ TgtCP | NumDmg$ 2 | SpellDescription$ CARDNAME deals 2 damage to target creature or player.

Joshua Smith said...

Thanks for programming tips and detailed helpful review.

It is true that nowadays all serious applications should pass quality assurance and testing. The best direction is connected with iphone custom apps that allows to develop some kinds of applications for cells.

Joshua Smith said...

It's well done info. Let me mention about home insurance with discounts home insurance companies. Save on online quotes on homeowners insurance.

Joshua Smith said...

Thank you for writing this great info. You have nice possibility to choose gaming affiliate program. The most common casino programs such as 32 Red and great poker rooms such as red bet affiliates.