Friday, November 20, 2009

Code online!

I don't have anything runnable, but I understand that talking about something you can't touch doesn't draw much interest. Well, "touching" over the internet is a vague concept, and code isn't physical, but putting my code online is as close as it can get. you can find it at http://code.google.com/p/laterna-magica/, and download it via SVN. The code is located in svn/trunk/laterna.

Well, as i said, it's not a runnable game or something, but you can still see something:
magica.card.utils.LaternaMagica shows a JTextPane that is filled with a String including mana symbols.
magica.card.impl.MagicObjectImpl features the layer system. It applies some effects to a simplified Llanowar Elves (just a 1/1 Elf for G):


//nothing runs without a game!
Game g = new GameImpl();





//The matcher defines a set of cards to be affected
Matcher m1 = getCardMatcher(getMatcher(ENCHANTMENT));

/* Then, an effect is registered in the game with that matcher.

 * In sum, this represents a static ability saying,
 *  "All enchantments are green."
 * Well, not exactly. It's more like,
 *  "All enchantment cards in all zones are green."
 */

g.getGlobalEffects().getEffects().put(new ColorChangingEffectImpl(g, ADDING, GREEN), m1);


/* 

 * This creates a Llanowar elves card (currently,
 * CardTemplateImpl implements a Green 1/1 Elf)

 */

MagicObject card = new MagicObjectImpl(g, new CardTemplateImpl());
 

//Here are some effects - should be obvious
//The order matters here - the effects get timestamps

CharacteristicEffect e1 = new PTSwitchingEffectImpl(g);
CharacteristicEffect e2 = new PTChangingEffectImpl(g, 0, 2);
CharacteristicEffect e3 = new TypeChangingEffectImpl(g, ADDING, ARTIFACT);
CharacteristicEffect e4 = new TypeChangingEffectImpl(g, SETTING, ENCHANTMENT);
CharacteristicEffect e5 = new OverridingCharacteristicEffectImpl(g, L3, MANA_COST,
        ManaFactoryImpl.INSTANCE.parseSequence("{R/W}"));


//All these effects are added to the card.

card.getEffects().add(e1);
card.getEffects().add(e2);
card.getEffects().add(e3);
card.getEffects().add(e4);
card.getEffects().add(e5);


//now, the result is printed out

CardCharacteristics c = card.getCharacteristics().get(0);
System.out.printf("%s - %s%n", c.getName(), c.getManaCost());
System.out.println(c.getColorCharacteristic());
System.out.printf("%s %s - %s%n", c.getSuperTypeCharacteristic(), c.getTypeCharacteristic(),
        c.getSubTypeCharacteristic());
System.out.printf("%d/%d%n", c.getPower(), c.getToughness());



Running this will give you the following output:
Llanowar Elves - {R/W}
+[White, Red, Green]
+[] +[Enchantment] - +[]
0/0
The card's name is Llanowar Elves, and it costs R/W. Red and white come from it's mana cost, and it's green again because it's an enchantment. Because It's not a creature, if doesn't have the "Elf" subtype, and also no P/T

3 comments:

nantuko84 said...

\0/ java!! very very interesting

at what stage is your development?
Could you say what of these cards can be implemented now:

1. Mutavault (all creature types)
2. Double Negative (counterspell, two targets in the stack)
3. Fileblast (alternative cost)
4. Violent Eruption (madness, dividing damage)
5. Mindslaver (control another turn)
6. Sen Triplets (several opponents, plays with revealed, can't play, you play spells)
7. Twincast (copy, new targets)
8. Ajani Vengeant (planeswalkers, redirect damage)
9. Gigantiform (kicker, put directly into play, attach to creature with shroud)
10. Madrush Cyclops and Act of Treason (giving haste effect, stealing creature and haste effect)
11. Marble Titan (replace usual untap)
12. Ruby Medallion (cost reducing)
13. Baloth Cage Trap (alternative cost, information about spells played)
14. Lavaball Trap + Ruby Medallion (reduce alternative cost)
15. Aquemoeba + Vampires (1/3 -> 3/1 + +3/+0 -> 3/4)
16. Exotic Orchard (change mana that can be produced)
17. Ancient Ziggurat (pay mana only for creatures)
18. Unstable Frontier (change land type and mana that it can produce)

or at least would be possible in nearest future?

Silly Freak said...

the first question is easy... none... it's a bit depressing, but well...

okay, let's think it through. i'm skipping the hard ones to save space ;)

Mutavault: doable; layers work already, abilities with limited time don't
Double Negative: Countering shouldn't be too hard, but i haven't thought about targeting too much yet
Fireblast: Costs are similar to targets here...
Vengeant: Possibly one of the harder ones, noncombat damage redirect is not easy, too
Gigantiform: Additional cost is hard, and auras are very special, too
Madrush: not too hard once haste works
Act of treason: stealing could be a problem, dunno
Ruby Medaillion, Baloth Cage Trap, Lavaball Trap: you like alternate costs, do you?
Aquamoeba, Vampires: "easy"
Exotic Orchard, Ancient Ziggurat: not easy...
Unstable Frontier: not that hard

you're a tough guy, you could as good have asked for grizzly bears, and I still can't do it yet...

nantuko84 said...

ha!
my friend, when read my comment with 18 cards, wrote "where did you get this list of horror?!?! you should have asked him about 1-2 easy spells too"
I know, I know. don't blame me a lot ;) just wanted to know if you keep in mind all such *horror* stuff. that will save your time in future (have I already said how I hate hacks I need to apply time to time?)

keep up the good work! it's showing great promise