Wednesday, October 22, 2008

Phase Stops

Letting the user select which phases stop, so a card or ability can be played, is trickier than it seems. Programming phase stops is actually pretty hard because it is easy to get it wrong. I thought I was done with the phase stop code in version 2, but after testing it, the code didn’t quite work correctly. The good news is that I’ve written new code and version 2 has all the phases and the phase stops work.

The original phase stop code comes from a previous attempt at version 2 that I was working on a year ago and it had three buttons: OK, Cancel, and Reset. Each button is supposed to be very simple but they didn’t work correctly. The OK button saves your choices. The Cancel button doesn’t save your choices but it still has to reset graphic checkbox components that show you which checkboxes are selected. And the Reset button stops only during your two Main phases. (The program always lets you declare your attackers and blockers, you cannot accidentally skip those phases.)

So the phase stop code works and hopefully I won’t have to update it for a long awhile. Version 2 just cycles through the phases but this is an important step. This means that the Phase object is correctly going to the next phase, which seems minor but it is very important.

In MTG Forge, the reason that the computer can’t be the first player is because there is a problem with the phase cycle. I accidentally forgot to test if the computer could go first. In conclusion, phases and phase stops are hard to code but very important.

p.s. What are the default phase stops for Magic Online?

This is how the phase stop menu looks in version 2.

8 comments:

  1. Hi, first time comment here! I really like what you've been doing with Forge, and I'm thinking of starting a similar project, just for the fun of it, and reading your blog is very helpful for me.

    On Magic Online default stops, IIRC, they are:
    Your turn:
    Main Phases (Obviously)
    Declare Blockers (If you attacked)

    Opponent's Turn:
    Declare Blockers (If there was an attack)
    End Phase

    ReplyDelete
  2. Ideally, a player should be able to have a chance to act/react 3 times during each phase.
    At the start, in response to cards or effects played by the opponent and at the end of a phase.
    Needed phases:
    -->Untap (no cards/effects can be played here)
    -->Upkeep (example: using the ability of a card in play to tap a land controled by opponent)
    -->Draw
    -->1st main phase
    -->Combat (as opponent declares attackers, you can react by turning a land like "Forbidding Watchtower" into a land and block with it. Which MTGForge does not allow right now)
    -->2nd main phase
    -->End of turn (all effects that last "until end of turn" end here)
    -->Clean up (No cards can be played here, usually only checks for the "no more than 7 cards in hand" rule I think)

    ReplyDelete
  3. Untap, Upkeep Step, Draw Step, Main Phase 1, Declare Combat, Declare Attackers, After Declare Attackers, Declare Blockers, After Declare Blockers, First Strike (and Double Strike) damage goes on the stack, FS damage resolves, after FS damage resolves, normal damage goes on the stack, after damage resolves, End of Combat, Main Phase 2, End of Turn, Clean Up.

    I believe these are all the possible steps/phases available in magic. At the very least the game needs to check during each of these steps for appropriate actions/events.

    ReplyDelete
  4. Hi Gabriel, I'm glad that you like reading my blog and hopefully it inspires you and other people to start up their own project, even though it is a ton of work.

    First strike is a pain to add since it requires extra phases. I know phases may not seem important, but phases are very crucial when programming Magic. Magic is all about moving carding and advancing to the next phase.

    Mr Chaos,

    Yes your 3 times per phase mean to me: in response to a spell or ability, or during that phase. But I understand what you are saying.

    ReplyDelete
  5. Why bother if you aren't going to get it right though? First strike is a vital part of Magic. If I were you Id think about it some more before deciding not to include it in V2.

    ReplyDelete
  6. i think keyboard input wuld help much, as it takes much less time than moving and clicking the mouse.

    //f is the frame your game is running in

    f.addKeyListener(new KeyAdapter(){

    public void keyPressed(KeyEvent e){

    if(e.getKeyCode() == VK_ENTER){
    //Do some confirming stuff
    } else if(e.getKeyCode() == VK_BACK_SPACE){
    //Do some cancelling stuff
    }

    }

    });

    ReplyDelete
  7. I agree with the keyboard input being used as a substitute for mouse clicking ok/cancel.

    ReplyDelete
  8. Gando the Wandering Fool said...
    If I were you I'd think about it some more before deciding not to include it in V2.

    I think you misunderstood me. I was just talking about phase stops in general and they are already working in version 2.

    ReplyDelete

Note: Only a member of this blog may post a comment.