// vim:syntax=javascript

// Master Exploder

class Master extends MovieClip {
    var sequence_no : Number;
    var next_level : Number;

    var blast_meter_mc : MovieClip;
    var title_mc : MovieClip;
    var end_mc : MovieClip;

    static var BLOCK_SIZE : Number = 20;
    static var TITLE_PROMPT_DEPTH : Number = 11;
    static var TITLE_DEPTH : Number = 10;
    static var BLAST_METER_DEPTH : Number = 3;
    static var BORDER_DEPTH : Number = 2;
    static var GAME_DEPTH : Number = 1;

    var doNextLevel : Function;

    function onLoad() {
        var static_this = this;

        sequence_no = 0;
        next_level = 0;

        var levels = [LevelB,
                      LevelA,
                      LevelC,
                      LevelE,
                      LevelD,
                      LevelF,
                      LevelI,
                      LevelH,
                      LevelG,
                      LevelJ,
                      LevelK,
                      LevelL];

        attachMovie("border", "border_mc", BORDER_DEPTH);
        attachMovie("blast_meter", "blast_meter_mc", BLAST_METER_DEPTH,
            {_x:10,_y:0});

        var parent_config : Object = {
            mc : this,
            depth : GAME_DEPTH,
            sequence_no : sequence_no,
            level_rect : new Rectangle(10,10,380,280),
            block_size : BLOCK_SIZE,
            blast_meter_mc : static_this.blast_meter_mc,
            whenDone : function () {static_this.doNextLevel();}
        };

        doNextLevel = function () {
            if (static_this.next_level >= levels.length) {
                static_this.attachMovie("end", "end_mc", Master.TITLE_DEPTH);
            } else {
                new levels[static_this.next_level](parent_config);

                static_this.next_level ++;
            }
        }

        attachMovie("title", "title_mc", TITLE_DEPTH, {
            onPress : function () {
                    this.removeMovieClip();
                },
            onUnload : function () {
                    static_this.doNextLevel();
                }});

    }
}
