My previous pseudocode looks correct but there were a still a few errors I had to fix. First, you have to internally reverse the mana cost because otherwise the colorless part will “eat” the colored mana the rest of the cost needs. For example, 2WW needs to be reversed to WW2. So when you add mana, the white mana part is checked first. In other words, when you pay W toward the cost 2WW the result should be 2W not 1WW. And when you display the cost to the user, the output has to be reversed again.
Below I will example how to use my Python code that handles mana costs. Some examples of valid mana costs are
2
1 W
X U
GW
RB RB
2/G 2/G 2/G
Each part is separated with a space, which just makes it easier to split up. GW means you can pay G or W and 2/G means that you can pay either 2 or G. The class ManaCost is the class that you will be using. ManaCost is low level and a graphical component is supposed to use ManaCost and allow the user to select the appropriate land or mana. The graphical component would also tap the land if the mana was needed. An example of how to use ManaCost is given below.
c = ManaCost()
c.setManaCost(“2 W W”)
c.isNeeded(“W”) #true
c.addMana(“W”)
print c.toString() #2 W
c.addMana(“W”)
c.addMana(“U”)
c.addMana(“U”)
print c.isPaid() #true
Feel free to use this in your own projects. This has been tested thoroughly comes with a wide variety of test cases: TestManaCost and TestManaPart.
Download Python Code
Monday, April 21, 2008
Subscribe to:
Post Comments (Atom)
1 comment:
In any case is it possable to SHRINK the letters and number in mana cost in apprentice because the hybred mana has cause one problem reading the cards name and also while reading a card the over whelming ammount of mana for a creature or something like a triple hybred for example could cause the problem of being able to see the true mana cost in words meaning total knock out of the name and seeing the true amount of mana if they could convert to symbols that would be nice but not hoping on that anytime soon but in anycase I would just like to have the text smaller than norm just so these HUGE letters span so far it's un readable one day I hope they make a apprentace download that has all pics of each card and has all that you need because the ability of apprentace is still highly capable in these times to handle the big stuff like that and in the latter some of us just can't program sadly and I'm one of them
Post a Comment