Stack question - implementing Bottle of Suleiman
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
3 posts
• Page 1 of 1
Stack question - implementing Bottle of Suleiman
by slapshot5 » 19 Apr 2010, 01:52
Hi all,
I'm trying to implement Bottle of Suleiman. It works, but the game flow could be a bit better I think.
Basically, what I think I want to do is this:
1) activate the ability
2) put something on the Stack like "Bottle of Suleiman - flip a coin"
3) hit OK for the stack
4) pop a choice for Heads or Tails
5) Indicate in some way the result
For step 5, what is the accepted way to do something like this. I don't think it belongs on the stack. I don't think it goes in the Message Box where all the Phase info is displayed. Should this just pop a generic message box with the result?
Currently, it works as 1-4. The only indication you have of won or lost is if you have a new Djinn, or lost 5 life. And maybe this is ok.
Here is the current code:
cards.txt:
-slapshot5
I'm trying to implement Bottle of Suleiman. It works, but the game flow could be a bit better I think.
Basically, what I think I want to do is this:
1) activate the ability
2) put something on the Stack like "Bottle of Suleiman - flip a coin"
3) hit OK for the stack
4) pop a choice for Heads or Tails
5) Indicate in some way the result
For step 5, what is the accepted way to do something like this. I don't think it belongs on the stack. I don't think it goes in the Message Box where all the Phase info is displayed. Should this just pop a generic message box with the result?
Currently, it works as 1-4. The only indication you have of won or lost is if you have a new Djinn, or lost 5 life. And maybe this is ok.
Here is the current code:
cards.txt:
- Code: Select all
Bottle of Suleiman
4
Artifact
no text
- Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Bottle of Suleiman")) {
final SpellAbility ability = new Ability_Activated(card, "1") {
private static final long serialVersionUID = -5741302550353410000L;
public boolean canPlayAI() {
//should do something like ok if CompLife > 10 or something
//or life greater than 5 or have no creatures
return false;
}
public void resolve() {
String choice = "";
String choices[] = {"heads","tails"};
boolean flip = MyRandom.percentTrue(50);
if(card.getController().equals(Constant.Player.Human)) {
choice = (String) AllZone.Display.getChoice("Choose one", choices);
}
else {
choice = choices[MyRandom.random.nextInt(2)];
}
AllZone.GameAction.sacrifice(card);
if( (flip == true && choice.equals("heads")) ||
(flip == false && choice.equals("tails"))) {
CardFactoryUtil.makeToken("Djinn", "", card, "0", new String[] {"Creature", "Artifact", "Djinn"}, 5, 5, new String[] {"Flying"});
}
else{
AllZone.GameAction.addDamage(card.getController(), 5, card);
}
}
};//SpellAbility
card.addSpellAbility(ability);
ability.setDescription("1: Flip a coin. Win: Put 5/5 Djinn in play. Lose: Does 5 damage to you.");
ability.setStackDescription("Bottle of Suleiman - flip a coin");
//ability.setBeforePayMana(new Input_NoCost_TapAbility(ability));
}//*************** END ************ END **************************
-slapshot5
- slapshot5
- Programmer
- Posts: 1391
- Joined: 03 Jan 2010, 17:47
- Location: Mac OS X
- Has thanked: 25 times
- Been thanked: 68 times
Re: Stack question - implementing Bottle of Suleiman
by DennisBergkamp » 19 Apr 2010, 02:30
I would use JOptionPane.showMessageDialog in this case (check GUI_WinLose.java, a bunch of them are used in there, you can use one with fewer parameters since you probably won't need an imageIcon).
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: Stack question - implementing Bottle of Suleiman
by slapshot5 » 19 Apr 2010, 03:24
Thanks Dennis. I think that works well.
Here is the updated code. Works well for me.
-slapshot5
Here is the updated code. Works well for me.
- Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Bottle of Suleiman")) {
/*
* Sacrifice Bottle of Suleiman: Flip a coin. If you lose the flip,
* Bottle of Suleiman deals 5 damage to you. If you win the flip,
* put a 5/5 colorless Djinn artifact creature token with flying
* onto the battlefield.
*/
final SpellAbility ability = new Ability_Activated(card, "1") {
private static final long serialVersionUID = -5741302550353410000L;
@Override
public boolean canPlayAI() {
PlayerLife life = AllZone.GameAction.getPlayerLife(Constant.Player.Computer);
if( life.getLife() > 10 ) {
return true;
}
CardList play = new CardList(AllZone.Computer_Play.getCards());
play = play.getType("Creature");
if( play.size() == 0 ) {
return true;
}
return false;
}
@Override
public void resolve() {
final String player = AllZone.Phase.getActivePlayer();
String choice = "";
String choices[] = {"heads","tails"};
boolean flip = MyRandom.percentTrue(50);
if(card.getController().equals(Constant.Player.Human)) {
choice = (String) AllZone.Display.getChoice("Choose one", choices);
}
else {
choice = choices[MyRandom.random.nextInt(2)];
}
AllZone.GameAction.sacrifice(card);
if( (flip == true && choice.equals("heads")) || (flip == false && choice.equals("tails"))) {
JOptionPane.showMessageDialog(null, "Bottle of Suleiman - Win! - "+player+" puts a 5/5 Flying Djinn in play.", "Bottle of Suleiman", JOptionPane.PLAIN_MESSAGE);
CardFactoryUtil.makeToken("Djinn", "", card, "0", new String[] {"Creature", "Artifact", "Djinn"}, 5, 5, new String[] {"Flying"});
}
else{
JOptionPane.showMessageDialog(null, "Bottle of Suleiman - Lose - Bottle does 5 damage to "+player+".", "Bottle of Suleiman", JOptionPane.PLAIN_MESSAGE);
AllZone.GameAction.addDamage(card.getController(), 5, card);
}
}
};//SpellAbility
card.addSpellAbility(ability);
ability.setDescription("1: Flip a coin. Win: Put 5/5 Djinn in play. Lose: Does 5 damage to you.");
ability.setStackDescription("Bottle of Suleiman - flip a coin");
}//*************** END ************ END **************************
- Code: Select all
bottle_of_suleiman.jpg http://www.wizards.com/global/images/magic/general/bottle_of_suleiman.jpg
-slapshot5
- slapshot5
- Programmer
- Posts: 1391
- Joined: 03 Jan 2010, 17:47
- Location: Mac OS X
- Has thanked: 25 times
- Been thanked: 68 times
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 23 guests