Frame 1
_global.Preloader = function () {
super();
this.bytes_total = _root.getBytesTotal();
};
Preloader.prototype = new MovieClip();
Object.registerClass("preloader", Preloader);
Preloader.prototype.onEnterFrame = function () {
var load_percent = Math.round((100 * _root.getBytesLoaded()) / this.bytes_total);
this.load_bar._width = load_percent;
if (load_percent == 100) {
_root.gotoAndPlay("init");
}
};
Frame 24
_root.stop();
Frame 25
_global.Container = function () {
super();
this.mc_counter = 0;
};
Container.prototype = new MovieClip();
Container.prototype.add_mc = function (symbol, x, y) {
var mc_name = ("mc" + this.mc_counter);
this.attachMovie(symbol, mc_name, this.mc_counter);
this.mc_counter++;
var mc = this[mc_name];
mc._x = x;
mc._y = y;
return(mc);
};
Container.prototype.empty = function () {
for (var k in this) {
this[k].removeMovieClip();
}
this.mc_counter = 0;
};
Container.prototype.get_next_mc = function (mc, dir) {
var depth = mc.getDepth();
var next_mc = mc;
for (var k in this) {
var mc2 = this[k];
if ((mc2 != mc) && (typeof(mc2) == "movieclip")) {
var new_depth = mc2.getDepth();
var old_depth = next_mc.getDepth();
if (dir == 1) {
if ((new_depth > depth) && ((new_depth < old_depth) || (old_depth == depth))) {
next_mc = mc2;
}
} else if ((new_depth < depth) && ((new_depth > old_depth) || (old_depth == depth))) {
next_mc = mc2;
}
}
}
return(next_mc);
};
Object.registerClass("container", Container);
_global.focus = _root;
_global.BasicButton = function () {
super();
this.stop();
this.label = "";
this.is_enabled = 1;
this.hitArea = this.hit_area_mc;
this.hit_area_mc._visible = false;
};
BasicButton.prototype = new MovieClip();
BasicButton.prototype.onRollOver = function () {
if (this.is_enabled) {
this.gotoAndStop("over");
}
};
BasicButton.prototype.onDragOver = function () {
if (this.is_enabled) {
this.gotoAndStop("over");
this.gotoAndStop("down");
}
};
BasicButton.prototype.onRollOut = (BasicButton.prototype.onDragOut = function () {
if (this.is_enabled) {
this.gotoAndStop("up");
}
});
BasicButton.prototype.onPress = function () {
if (this.is_enabled) {
this.gotoAndStop("down");
}
};
BasicButton.prototype.onRelease = function () {
if (this.is_enabled) {
this.gotoAndStop("over");
this.onClick();
}
};
BasicButton.prototype.enable = function () {
this.is_enabled = 1;
if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
this.gotoAndStop("over");
} else {
this.gotoAndStop("up");
}
this.useHandCursor = true;
};
BasicButton.prototype.disable = function () {
this.is_enabled = 0;
this.gotoAndStop("disabled");
this.useHandCursor = false;
};
Object.registerClass("basic_button", BasicButton);
_global.Window = function () {
super();
};
Window.prototype = new MovieClip();
Window.prototype.close = function () {
this.onClose();
this.removeMovieClip();
};
_global.WorkingWindow = function () {
super();
this.stop();
this.message = "";
this.close_delay = -1;
this.open_delay = -1;
};
WorkingWindow.prototype = new Window();
WorkingWindow.prototype.onEnterFrame = function () {
if (this.open_delay > 0) {
this.open_delay--;
} else if (this.open_delay == 0) {
this.open_delay--;
this.gotoAndStop("show");
} else if (this.close_delay > 0) {
this.close_delay--;
} else if (this.close_delay == 0) {
this.close();
}
};
WorkingWindow.prototype.set_open_delay = function (delay) {
if (delay > 0) {
this.gotoAndStop("hide");
}
this.open_delay = delay;
};
WorkingWindow.prototype.get_open_delay = function () {
return(this.open_delay);
};
WorkingWindow.prototype.set_close_delay = function (delay) {
this.close_delay = delay;
};
WorkingWindow.prototype.get_close_delay = function () {
return(this.close_delay);
};
_global.MessageWindow = function () {
super();
this.label = "";
this.message = "";
};
MessageWindow.prototype = new Window();
_global.ConfirmWindow = function () {
super();
this.label = "";
this.message = "";
};
ConfirmWindow.prototype = new Window();
Object.registerClass("message_window", MessageWindow);
Object.registerClass("working_window", WorkingWindow);
_global.CheckBox = function () {
super();
this.stop();
this.label = "";
this.enabled = 1;
this.checked = 0;
this.hitArea = this.hit_area_mc;
this.hit_area_mc._visible = false;
};
CheckBox.prototype = new MovieClip();
CheckBox.prototype.set_label = function (label) {
this.label = label;
};
checkBox.prototype.get_label = function () {
return(this.label);
};
CheckBox.prototype.get_checked = function () {
return(this.checked);
};
checkBox.prototype.get_enabled = function () {
return(this.enabled);
};
CheckBox.prototype.check = function () {
this.checked = 1;
this.gotoAndStop("up_checked");
};
CheckBox.prototype.uncheck = function () {
this.checked = 0;
this.set_status("up");
};
CheckBox.prototype.set_status = function (status) {
if (status == "disabled") {
this.gotoAndStop("up");
this.gotoAndStop("disabled");
} else if (this.enabled) {
if (status == "up") {
this.gotoAndStop("up");
if (this.checked) {
this.gotoAndStop("up_checked");
}
} else if (status == "over") {
this.gotoAndStop("up");
this.gotoAndStop("over");
if (this.checked) {
this.gotoAndStop("up_checked");
this.gotoAndStop("over_checked");
}
} else if (status == "down") {
this.gotoAndStop("up");
this.gotoAndStop("over");
this.gotoAndStop("down");
if (this.checked) {
this.gotoAndStop("up_checked");
this.gotoAndStop("over_checked");
this.gotoAndStop("down_checked");
}
}
}
};
CheckBox.prototype.onRollOver = function () {
this.set_status("over");
};
CheckBox.prototype.onDragOver = function () {
this.set_status("down");
};
CheckBox.prototype.onRollOut = (CheckBox.prototype.onDragOut = function () {
this.set_status("up");
});
CheckBox.prototype.onPress = function () {
this.set_status("down");
};
CheckBox.prototype.onRelease = function () {
if (this.enabled) {
this.checked = !this.checked;
this.set_status("over");
this.onClick();
if (this.checked) {
this.onCheck();
} else {
this.onUncheck();
}
}
};
CheckBox.prototype.enable = function () {
this.enabled = 1;
if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
this.set_status("over");
} else {
this.set_status("up");
}
this.useHandCursor = true;
};
CheckBox.prototype.disable = function () {
this.enabled = 0;
this.set_status("disabled");
this.useHandCursor = false;
};
_global.MoveRowButton = function () {
super();
this.row_id;
this.dir = 1;
};
MoveRowButton.prototype = new BasicButton();
Object.registerClass("move_row_button", MoveRowButton);
MoveRowButton.prototype.set_row_id = function (row_id) {
this.row_id = row_id;
this.row_mc = row_mc;
};
MoveRowButton.prototype.get_row_id = function () {
return(this.row_id);
};
MoveRowbutton.prototype.get_dir = function () {
return(this.dir);
};
MoveRowButton.prototype.set_dir = function (dir) {
this.dir = dir;
if (this.dir > 0) {
this._xscale = 100;
} else {
this._xscale = -100;
}
};
MoveRowButton.prototype.onClick = function () {
this._parent._parent.move_row(this.row_id, this.dir);
};
Object.registerClass("move_row_button", MoveRowButton);
_global.Shape = function () {
super();
this.stop();
this.pos_x = 0;
this.pos_y = 0;
};
Shape.prototype = new MovieClip();
Shape.prototype.get_x = function () {
return(this._x);
};
Shape.prototype.set_x = function (x) {
this._x = x;
};
Shape.prototype.get_y = function () {
return(this._y);
};
Shape.prototype.set_y = function (y) {
this._y = y;
};
Shape.prototype.get_pos_x = function () {
return(this.pos_x);
};
Shape.prototype.set_pos_x = function (x) {
this.pos_x = x;
};
Shape.prototype.get_pos_y = function () {
return(this.pos_y);
};
Shape.prototype.set_pos_y = function (y) {
this.pos_y = y;
};
_global.Box = function () {
super();
};
Box.prototype = new Shape();
Box.prototype.show_edge = function () {
this.gotoAndStop("edge");
};
Box.prototype.hide_edge = function () {
this.gotoAndStop("no_edge");
};
_global.LeftEndBox = function () {
super();
};
LeftEndBox.prototype = new Shape();
_global.RightEndBox = function () {
super();
};
RightEndBox.prototype = new Shape();
_global.Ball = function () {
super();
};
Ball.prototype = new Shape();
_global.GoldBall = function () {
super();
};
GoldBall.prototype = new Ball();
_global.Bar = function () {
super();
};
Bar.prototype = new Shape();
Bar.prototype.set_stack_pos = function (stack_pos) {
if (stack_pos == "top") {
this.gotoAndStop("top");
} else if (stack_pos == "bottom") {
this.gotoAndStop("bottom");
} else {
this.gotoAndStop("middle");
}
};
_global.RightBar = function () {
super();
};
RightBar.prototype = new Bar();
_global.LeftBar = function () {
super();
};
LeftBar.prototype = new Bar();
Object.registerClass("box", Box);
Object.registerClass("ball", Ball);
Object.registerClass("gold_ball", GoldBall);
Object.registerClass("end_box_left", LeftEndBox);
Object.registerClass("end_box_right", RightEndBox);
Object.registerClass("bar_left", LeftBar);
Object.registerClass("bar_right", RightBar);
_global.Level = function () {
this.id = id;
this.play_on = 0;
this.animations_on = 1;
this.num_cols = 0;
this.rows = new Array();
this.shape_vx = 4;
this.shape_vy = 5;
this.row_spacing = 20;
this.col_spacing = 20;
this.num_dropped_balls = 0;
this.num_gold_balls_left = 0;
this.moving_shapes_x = new Array();
this.moving_shapes_y = new Array();
this.num_moves = 0;
this.left_bar_x = 0;
this.right_bar_x = 0;
this.attachMovie("container", "shapes_mc", 0);
this.attachMovie("container", "move_row_buttons_mc", 1);
};
Level.prototype = new MovieClip();
Level.prototype.box_id = 1;
Level.prototype.ball_id = 2;
Level.prototype.gold_ball_id = 3;
Level.prototype.set_id = function (id) {
this.id = id;
};
Level.prototype.get_id = function () {
return(this.id);
};
Level.prototype.set_play_on = function (play_on) {
this.play_on = play_on;
this.disable_move_row_buttons();
if (play_on) {
this.drop_balls();
if (!this.animations_on) {
this.reset_move_row_buttons();
}
}
};
Level.prototype.get_play_on = function () {
return(this.play_on);
};
Level.prototype.set_animations_on = function (animate) {
this.animations_on = animate;
};
Level.prototype.get_animations_on = function () {
return(this.animations_on);
};
Level.prototype.get_center_x = function () {
return((this.col_spacing * ((this.right_bar_x + this.left_bar_x) + 1)) / 2);
};
Level.prototype.set_num_cols = function (cols) {
this.num_cols = cols;
};
Level.prototype.get_num_cols = function () {
return(this.num_cols);
};
Level.prototype.get_num_rows = function () {
return(this.rows.length);
};
Level.prototype.set_col_spacing = function (col_spacing) {
this.col_spacing = col_spacing;
};
Level.prototype.get_col_spacing = function () {
return(this.col_spacing);
};
Level.prototype.set_row_spacing = function (row_spacing) {
this.row_spacing = row_spacing;
};
Level.prototype.get_row_spacing = function () {
return(this.row_spacing);
};
Level.prototype.get_num_dropped_balls = function () {
return(this.num_dropped_balls);
};
Level.prototype.get_num_gold_balls_left = function () {
return(this.num_gold_balls_left);
};
Level.prototype.get_num_moving_shapes_x = function () {
return(this.moving_shapes_x.length);
};
Level.prototype.get_num_moving_shapes_y = function () {
return(this.moving_shapes_y.length);
};
Level.prototype.get_num_moves = function () {
return(this.num_moves);
};
Level.prototype.get_right_bar_x = function () {
return(this.right_bar_x);
};
Level.prototype.set_right_bar_x = function (x) {
this.right_bar_x = x;
};
Level.prototype.get_left_bar_x = function () {
return(this.left_bar_x);
};
Level.prototype.set_left_bar_x = function (x) {
this.left_bar_x = x;
};
Level.prototype.add_shape = function (symbol, x, y) {
this.remove_shape(x, y);
var mc = this.shapes_mc.add_mc(symbol, x * this.col_spacing, y * this.row_spacing);
mc.set_pos_x(x);
mc.set_pos_y(y);
this.set_shape(mc, x, y);
return(mc);
};
Level.prototype.remove_shape = function (x, y) {
var mc;
if ((mc = this.get_shape(x, y))) {
mc.removeMovieClip();
this.set_shape(null, x, y);
return(1);
}
return(0);
};
Level.prototype.set_shape = function (mc, x, y) {
this.rows[y][x] = mc;
};
Level.prototype.get_shape = function (x, y) {
return(this.rows[y][x]);
};
Level.prototype.shape_is_moving = function (x, y) {
var mc;
return(((mc = this.get_shape(x, y))) && (((mc.get_pos_x() * this.col_spacing) != mc.get_x()) || ((mc.get_pos_y() * this.row_spacing) != mc.get_y())));
};
Level.prototype.is_shape_at = function (x, y) {
return(this.get_shape(x, y) instanceof Shape);
};
Level.prototype.is_ball_at = function (x, y) {
return(this.get_shape(x, y) instanceof Ball);
};
Level.prototype.is_gold_ball_at = function (x, y) {
return(this.get_shape(x, y) instanceof GoldBall);
};
Level.prototype.is_box_at = function (x, y) {
var mc = this.get_shape(x, y);
return(((mc instanceof Box) || (mc instanceof LeftEndBox)) || (mc instanceof RightEndBox));
};
Level.prototype.add_ball = function (x, y) {
return(this.add_shape("ball", x, y));
};
Level.prototype.add_gold_ball = function (x, y) {
this.num_gold_balls_left++;
return(this.add_shape("gold_ball", x, y));
};
Level.prototype.add_box = function (x, y) {
return(this.add_shape("box", x, y));
};
Level.prototype.add_end_box = function (x, y, x_pos) {
var symbol = ((x_pos == "left") ? "end_box_left" : "end_box_right");
var mc = this.add_shape(symbol, x, y);
return(mc);
};
Level.prototype.add_bar = function (y, x_pos, stack_pos) {
if (x_pos == "left") {
var x = this.left_bar_x;
} else {
var x = this.right_bar_x;
x_pos = "right";
}
var mc = this.shapes_mc.add_mc("bar_" + x_pos, x * this.col_spacing, y * this.row_spacing);
mc._name = (("bar_" + y) + "_") + x_pos;
mc.set_pos_x(x);
mc.set_pos_y(y);
mc.set_stack_pos(stack_pos);
return(mc);
};
Level.prototype.get_bar = function (y, x_pos) {
return(this.shapes_mc[(("bar_" + y) + "_") + x_pos]);
};
Level.prototype.ball_can_move = function (x, y, dir_x, dir_y) {
var dx = ((dir_x > 0) ? 1 : (((dir_x < 0) ? -1 : 0)));
var dy = ((dir_y > 0) ? 1 : (((dir_y < 0) ? -1 : 0)));
var next_x = (x + dx);
var next_y = (y + dy);
if ((this.shape_is_ball(x, y) && (!this.shape_is_box(next_x, next_y))) && ((!this.get_ball(next_x, next_y)) || (this.ball_can_move(next_x, next_y, dx, dy)))) {
return(1);
}
return(0);
};
Level.prototype.move_shape = function (x, y, dir_x, dir_y) {
var dx = ((dir_x > 0) ? 1 : (((dir_x < 0) ? -1 : 0)));
var dy = ((dir_y > 0) ? 1 : (((dir_y < 0) ? -1 : 0)));
var new_x = (x + dx);
var new_y = (y + dy);
var num_rows = this.get_num_rows();
if ((((dx != 0) || (dy != 0)) && (this.is_shape_at(x, y))) && (!this.is_shape_at(new_x, new_y))) {
if ((dx != 0) && (this.is_ball_at(x, y - 1))) {
this.move_shape(x, y - 1, dir_x, dir_y);
} else if (dy > 0) {
var k = (new_y + 1);
while ((k < num_rows) && (!this.is_shape_at(new_x, k))) {
new_y = k;
k++;
}
}
var shape_mc = this.get_shape(x, y);
shape_mc.set_pos_x(new_x);
shape_mc.set_pos_y(new_y);
this.set_shape(null, x, y);
if (new_y < num_rows) {
this.set_shape(shape_mc, new_x, new_y);
}
if (new_y == (num_rows - 1)) {
if (shape_mc instanceof GoldBall) {
this.num_gold_balls_left--;
} else if (shape_mc instanceof Ball) {
this.num_dropped_balls++;
}
}
if (!this.animations_on) {
shape_mc.set_x(new_x * this.col_spacing);
shape_mc.set_y(new_y * this.row_spacing);
} else if (dx != 0) {
this.moving_shapes_x.push(shape_mc);
} else if (dy != 0) {
this.moving_shapes_y.push(shape_mc);
}
return(1);
}
return(0);
};
Level.prototype.drop_balls = function () {
this.reset_shape_depths(0);
var num_rows = this.get_num_rows();
var y = (num_rows - 1);
while (y >= 0) {
var x = this.left_bar_x;
while (x <= this.right_bar_x) {
if (this.is_ball_at(x, y)) {
this.move_shape(x, y, 0, 1);
}
x++;
}
y--;
}
if (!this.animations_on) {
this.reset_shape_depths(1);
this.reset_move_row_buttons();
}
};
Level.prototype.update_shapes = function () {
for (var k in this.moving_shapes_x) {
var shape_mc = this.moving_shapes_x[k];
var next_x = (shape_mc.get_pos_x() * this.col_spacing);
var curr_x = shape_mc.get_x();
if ((Math.abs(next_x - curr_x) < this.shape_vx) || (!this.animations_on)) {
shape_mc.set_x(next_x);
} else if (curr_x < next_x) {
shape_mc.set_x(curr_x + this.shape_vx);
} else if (curr_x > next_x) {
shape_mc.set_x(curr_x - this.shape_vx);
}
if (next_x == shape_mc.get_x()) {
this.moving_shapes_x.splice(k, 1);
}
}
for (var k in this.moving_shapes_y) {
var shape_mc = this.moving_shapes_y[k];
var next_y = (shape_mc.get_pos_y() * this.row_spacing);
var curr_y = shape_mc.get_y();
if ((Math.abs(next_y - curr_y) < this.shape_vy) || (!this.animations_on)) {
shape_mc.set_y(next_y);
} else if (curr_y < next_y) {
shape_mc.set_y(curr_y + this.shape_vy);
} else if (curr_y > next_y) {
shape_mc.set_y(curr_y - this.shape_vy);
}
if (next_y == shape_mc.get_y()) {
this.moving_shapes_y.splice(k, 1);
}
}
};
Level.prototype.reset_shape_depths = function (horizontal) {
var depth = 0;
var mc;
var start_y = (this.get_num_rows() - 1);
var start_x = (this.get_num_cols() - 1);
if (horizontal) {
var y = start_y;
while (y >= 0) {
var left_end_box_mc;
var x = start_x;
while (x >= 0) {
if ((mc = this.get_shape(x, y))) {
if (mc instanceof LeftEndBox) {
this.get_bar(y, "left").swapDepths(depth);
depth++;
this.get_bar(y, "right").swapDepths(depth);
depth++;
}
mc.swapDepths(depth);
depth++;
}
x--;
}
y--;
}
} else {
var x = start_x;
while (x >= 0) {
var y = start_y;
while (y >= 0) {
if ((mc = this.get_shape(x, y))) {
mc.swapDepths(depth);
depth++;
}
y--;
}
if ((x == this.right_bar_x) || (x == this.left_bar_x)) {
var side = ((x == this.right_bar_x) ? "right" : "left");
var y = start_y;
while (y >= 0) {
this.get_bar(y, side).swapDepths(depth);
depth++;
y--;
}
}
x--;
}
}
};
Level.prototype.add_row = function (row_str, pos_x, stack_pos) {
var y = this.rows.length;
var box_row = 0;
this.rows[y] = new Array();
var x = 0;
while (x < row_str.length) {
var ch = row_str.charAt(x);
if (ch == this.box_id) {
var box_mc = this.add_box(x + pos_x, y);
box_row = 1;
if (row_str.charAt(x + 1) != this.box_id) {
box_mc.show_edge();
}
} else if (ch == this.ball_id) {
var ball_mc = this.add_ball(x + pos_x, y);
} else if (ch == this.gold_ball_id) {
this.add_gold_ball(x + pos_x, y);
}
x++;
}
if (box_row) {
this.add_end_box(pos_x - 1, y, "left");
this.add_end_box(row_str.length + pos_x, y, "right");
var left_bar_mc = this.add_bar(y, "left", stack_pos);
var right_bar_mc = this.add_bar(y, "right", stack_pos);
var button1 = this.add_move_row_button(y, "left", -1);
button1.disable();
var button1 = this.add_move_row_button(y, "right", 1);
button2.disable();
}
};
Level.prototype.remove_row = function (y) {
var x = 0;
while (x < this.shapes[y].length) {
this.remove_shape(x, y);
x++;
}
if ((y < 0) || (y > this.shapes.length)) {
return(0);
}
this.rows_splice(y, 1);
return(1);
};
Level.prototype.get_row = function (y) {
if ((y < 0) || (y >= this.rows.length)) {
return(0);
}
return(this.rows[y]);
};
Level.prototype.row_can_move = function (y, dir) {
var dx = ((dir > 0) ? 1 : -1);
var row;
if ((row = this.get_row(y))) {
var x_min = row.length;
var x_max = 0;
var x = 0;
while (x < row.length) {
if (this.is_box_at(x, y)) {
x_min = Math.min(x_min, x);
x_max = x;
}
x++;
}
if (((x_min + dx) < this.left_bar_x) && ((x_max + dx) > this.right_bar_x)) {
return(1);
}
}
return(0);
};
Level.prototype.move_row = function (y, dir) {
var dx = ((dir > 0) ? 1 : -1);
var row;
if (((row = this.get_row(y))) && (this.row_can_move(y, dir))) {
var start_x = ((dx > 0) ? (row.length - 1) : 0);
var end_x = ((dx > 0) ? 0 : (row.length - 1));
var x = start_x;
while (((dx > 0) && ((x - end_x) >= 0)) || ((dx < 0) && ((end_x - x) >= 0))) {
this.move_shape(x, y, dx, 0);
x = x - dx;
}
var x = end_x;
while (((dx > 0) && ((start_x - x) >= 0)) || ((dx < 0) && ((x - start_x) >= 0))) {
if (this.is_ball_at(x, y)) {
this.move_shape(x, y, -dx, 0);
}
x = x + dx;
}
if (!this.animations_on) {
this.drop_balls();
} else {
this.disable_move_row_buttons();
}
this.num_moves++;
return(1);
}
return(0);
};
Level.prototype.add_move_row_button = function (y, pos, dir) {
var mc;
if (pos == "left") {
mc = this.move_row_buttons_mc.add_mc("move_row_button", 0, y * this.row_spacing);
} else {
mc = this.move_row_buttons_mc.add_mc("move_row_button", this.col_spacing * this.get_num_cols(), y * this.row_spacing);
}
mc.set_row_id(y);
mc.set_dir(dir);
};
Level.prototype.disable_move_row_buttons = function () {
for (var k in this.move_row_buttons_mc) {
var mc = this.move_row_buttons_mc[k];
if (mc instanceof MoveRowButton) {
mc.disable();
}
}
};
Level.prototype.reset_move_row_buttons = function () {
for (var k in this.move_row_buttons_mc) {
var mc = this.move_row_buttons_mc[k];
if (mc instanceof MoveRowButton) {
if (this.row_can_move(mc.get_row_id(), mc.get_dir())) {
mc.enable();
} else {
mc.disable();
}
}
}
};
Level.prototype.set_shapes = function (row_data) {
var y = 0;
while (y < row_data.length) {
this.num_cols = Math.max(this.num_cols, (row_data[y].shapes.length + this.left_bar_x) + 1);
y++;
}
var num_box_rows = 0;
var y = 0;
while (y < row_data.length) {
var shapes_str = row_data[y].shapes;
var stack_pos = ((y == (row_data.length - 1)) ? "bottom" : "middle");
if (shapes_str.indexOf(this.box_id) >= 0) {
if (num_box_rows == 0) {
stack_pos = "top";
}
num_box_rows++;
}
this.add_row(shapes_str, row_data[y].x, stack_pos);
y++;
}
this.add_row("", 0, "middle");
this.reset_shape_depths(1);
};
Level.prototype.update_move = function () {
if (!this.play_on) {
return(0);
}
if (this.get_num_moving_shapes_x() > 0) {
this.update_shapes();
if (this.get_num_moving_shapes_x() == 0) {
this.drop_balls();
if (this.get_num_moving_shapes_y() == 0) {
this.reset_shape_depths(1);
this.reset_move_row_buttons();
}
}
} else if (this.get_num_moving_shapes_y() > 0) {
this.update_shapes();
if (this.get_num_moving_shapes_y() == 0) {
this.reset_shape_depths(1);
this.reset_move_row_buttons();
}
}
};
Level.prototype.get_status = function () {
if ((this.get_num_moving_shapes_y() == 0) && (this.get_num_moving_shapes_x() == 0)) {
if (this.num_dropped_balls > 0) {
return("lose");
}
if (this.num_gold_balls_left == 0) {
return("win");
}
}
};
Object.registerClass("level", Level);
_global.Game = function (start_level) {
this.level_id = start_level;
this.max_level_id = start_level;
this.curr_level;
this.level_moves = new Array();
};
Game.prototype.set_level_id = function (id) {
this.level_id = id;
};
Game.prototype.get_level_id = function () {
return(this.level_id);
};
Game.prototype.set_max_level_id = function (id) {
this.max_level_id = id;
};
Game.prototype.get_max_level_id = function () {
return(this.max_level_id);
};
Game.prototype.set_level = function (level_mc) {
this.curr_level = level_mc;
};
Game.prototype.get_level = function () {
return(this.curr_level);
};
Game.prototype.set_level_moves = function (level_id, moves) {
this.level_moves[level_id] = moves;
};
Game.prototype.get_level_moves = function (level_id) {
return(this.level_moves[level_id]);
};
Game.prototype.get_num_levels = function () {
return(this.level_moves.length);
};
Game.prototype.win_level = function () {
var old_moves = this.level_moves[this.level_id];
var new_moves = this.curr_level.get_num_moves();
if ((new_moves < old_moves) || (old_moves <= 0)) {
this.level_moves[this.level_id] = new_moves;
}
this.curr_level = null;
this.level_id++;
if (this.level_id > this.max_level_id) {
this.max_level_id = this.level_id;
}
};
Game.prototype.lose_level = function () {
this.curr_level = null;
};
_global.level_data = new Array();
_global.level_data[1] = new Object();
_global.level_data[1].left_bar_x = 2;
_global.level_data[1].right_bar_x = 5;
_global.level_data[1].rows = new Array();
_global.level_data[1].rows[0] = {x:2, shapes:"302"};
_global.level_data[1].rows[1] = {x:1, shapes:"10101"};
_global.level_data[1].rows[2] = {x:2, shapes:"10101"};
_global.level_data[1].rows[3] = {x:2, shapes:"11011"};
_global.level_data[2] = new Object();
_global.level_data[2].left_bar_x = 3;
_global.level_data[2].right_bar_x = 7;
_global.level_data[2].rows = new Array();
_global.level_data[2].rows[0] = {x:4, shapes:"302"};
_global.level_data[2].rows[1] = {x:2, shapes:"1101011"};
_global.level_data[2].rows[2] = {x:3, shapes:"110101"};
_global.level_data[2].rows[3] = {x:3, shapes:"1111011"};
_global.level_data[3] = new Object();
_global.level_data[3].left_bar_x = 4;
_global.level_data[3].right_bar_x = 7;
_global.level_data[3].rows = new Array();
_global.level_data[3].rows[0] = {x:5, shapes:"23"};
_global.level_data[3].rows[1] = {x:3, shapes:"110011"};
_global.level_data[3].rows[2] = {x:2, shapes:"1110111"};
_global.level_data[3].rows[3] = {x:3, shapes:"10101"};
_global.level_data[3].rows[4] = {x:4, shapes:"10111"};
_global.level_data[4] = new Object();
_global.level_data[4].left_bar_x = 3;
_global.level_data[4].right_bar_x = 7;
_global.level_data[4].rows = new Array();
_global.level_data[4].rows[0] = {x:4, shapes:"3022"};
_global.level_data[4].rows[1] = {x:3, shapes:"101001"};
_global.level_data[4].rows[2] = {x:2, shapes:"101011"};
_global.level_data[4].rows[3] = {x:3, shapes:"110001"};
_global.level_data[4].rows[4] = {x:2, shapes:"1101011"};
_global.level_data[5] = new Object();
_global.level_data[5].left_bar_x = 3;
_global.level_data[5].right_bar_x = 8;
_global.level_data[5].rows = new Array();
_global.level_data[5].rows[0] = {x:3, shapes:"2032"};
_global.level_data[5].rows[1] = {x:1, shapes:"11010011"};
_global.level_data[5].rows[2] = {x:3, shapes:"1011001"};
_global.level_data[5].rows[3] = {x:2, shapes:"1010011"};
_global.level_data[5].rows[4] = {x:1, shapes:"11001011"};
_global.X_CENTER = Stage.width / 2;
_global.Y_CENTER = Stage.height / 2;
_global.LAST_LEVEL_ID = _global.level_data.length - 1;
_global.animations_on = 1;
_global.curr_game;
_global.level_buttons = new Array();
_global.init_game = function (start_level) {
_global.curr_game = new Game(start_level);
var k = 0;
while (k < LAST_LEVEL_ID) {
_global.level_buttons[k] = _root.level_buttons_mc.add_mc("level_button", k * 30, 0);
_global.level_buttons[k].set_level_id(k + 1);
_global.level_buttons[k].disable();
k++;
}
_global.init_level();
};
_global.deinit_game = function () {
_global.deinit_level();
_global.curr_game = null;
};
_global.init_level = function () {
_root.gotoAndStop("main");
var level_id = _global.curr_game.get_level_id();
var level_data = _global.level_data[level_id];
var row_data = level_data.rows;
var curr_level = _root.level_mc.add_mc("level", 0, 0);
_global.curr_game.set_level(curr_level);
curr_level.set_animations_on(_global.animations_on);
curr_level.set_right_bar_x(level_data.right_bar_x);
curr_level.set_left_bar_x(level_data.left_bar_x);
curr_level.set_shapes(row_data);
curr_level._x = X_CENTER - curr_level.get_center_x();
curr_level.set_play_on(1);
_root.level_num = "<b>Level:</b> " + level_id;
var num_best_moves = _global.curr_game.get_level_moves(level_id);
if (num_best_moves <= 0) {
num_best_moves = "-";
}
_root.level_best = "<b>Best:</b> " + num_best_moves;
_global.reset_level_buttons();
};
_global.deinit_level = function () {
var curr_level = _global.curr_game.get_level();
_root.level_mc.empty();
_global.curr_game.set_level(null);
_global.disable_level_buttons();
};
_global.go_to_level = function (level_id) {
if ((level_id > 0) && (level_id <= _global.curr_game.get_max_level_id())) {
_global.deinit_level();
_global.curr_game.set_level_id(level_id);
_global.init_level();
}
};
_global.restart_level = function () {
_global.deinit_level();
_global.init_level();
};
_global.win_level = function () {
_global.disable_level_buttons();
var mc = _global.show_working_window("You win!", 20, 30);
var curr_level = _global.curr_game.get_level();
curr_level.set_play_on(0);
mc.onClose = function () {
_global.curr_game.win_level();
_global.deinit_level();
if (_global.curr_game.get_level_id() <= LAST_LEVEL_ID) {
_global.init_level();
} else {
_global.end_game_win();
}
};
};
_global.lose_level = function () {
_global.disable_level_buttons();
var mc = _global.show_working_window("You lose", 20, 30);
var curr_level = _global.curr_game.get_level();
curr_level.set_play_on(0);
mc.onClose = function () {
_global.curr_game.lose_level();
_global.deinit_level();
_global.init_level();
};
};
_global.end_game_win = function () {
_root.gotoAndStop("win");
};
_global.disable_level_buttons = function () {
for (var k in _root.level_buttons_mc) {
var mc = _root.level_buttons_mc[k];
if (mc instanceof LevelButton) {
mc.disable();
}
}
};
_global.reset_level_buttons = function () {
var curr_level_id = _global.curr_game.get_level_id();
var max_level_id = _global.curr_game.get_max_level_id();
var k = 0;
while (k < _global.level_buttons.length) {
var mc = _global.level_buttons[k];
var level_id = (k + 1);
if (level_id <= max_level_id) {
mc.enable();
mc.set_level_moves(_global.curr_game.get_level_moves(k + 1));
} else {
mc.disable();
}
if (level_id == curr_level_id) {
mc.hilite();
}
k++;
}
};
_global.show_message_window = function (label, message) {
var mc = show_window("message_window");
mc.label = label;
mc.message = message;
return(mc);
};
_global.show_working_window = function (message, open_delay, close_delay) {
var mc = show_window("working_window");
mc.set_open_delay(open_delay);
mc.set_close_delay(close_delay);
mc.message = message;
return(mc);
};
_global.show_window = function (symbol) {
var mc = _root.windows_mc.add_mc(symbol, X_CENTER - 50, Y_CENTER - 50);
return(mc);
};
_global.set_animations_on = function (animations_on) {
var curr_level = _global.curr_game.get_level();
_global.animations_on = animations_on;
curr_level.set_animations_on(animations_on);
};
_root.onEnterFrame = function () {
var curr_level;
if ((_global.curr_game && ((curr_level = _global.curr_game.get_level()))) && (curr_level.get_play_on())) {
curr_level.update_move();
_root.level_moves = "<b>Moves:</b> " + curr_level.get_num_moves();
var level_status = curr_level.get_status();
if (level_status == "lose") {
_global.lose_level();
} else if (level_status == "win") {
_global.win_level();
} else if (Key.isDown(76) && (Key.isDown(17))) {
_global.curr_game.set_max_level_id(LAST_LEVEL_ID);
_global.go_to_level(LAST_LEVEL_ID);
}
}
};
_global.AnimationCheckBox = function () {
super();
if (_global.animations_on) {
this.check();
} else {
this.uncheck();
}
};
AnimationCheckBox.prototype = new CheckBox();
Object.registerClass("animation_check_box", AnimationCheckBox);
AnimationCheckBox.prototype.onCheck = function () {
_global.set_animations_on(1);
};
AnimationCheckBox.prototype.onUncheck = function () {
_global.set_animations_on(0);
};
_global.LevelButton = function () {
super();
this.level_id = 0;
this.level_moves = "-";
};
LevelButton.prototype = new BasicButton();
Object.registerClass("level_button", LevelButton);
LevelButton.prototype.get_level_id = function (level_id) {
return(this.level_id);
};
LevelButton.prototype.set_level_id = function (level_id) {
this.level_id = level_id;
this.label = level_id;
};
LevelButton.prototype.get_level_moves = function () {
return(this.level_moves);
};
LevelButton.prototype.set_level_moves = function (level_moves) {
if (level_moves > 0) {
this.level_moves = level_moves;
} else {
this.level_moves = "-";
}
};
LevelButton.prototype.hilite = function () {
this.disable();
this.gotoAndStop("hilite");
};
LevelButton.prototype.onClick = function () {
_global.go_to_level(this.level_id);
};
_global.RestartLevelButton = function () {
super();
};
RestartLevelButton.prototype = new BasicButton();
Object.registerClass("restart_level_button", RestartLevelButton);
RestartLevelButton.prototype.onClick = function () {
_global.restart_level();
};
Frame 26
stop();
Instance of Symbol 64 MovieClip [basic_button] in Frame 26
onClipEvent (load) {
this.label = "Start";
this.onClick = function () {
_root.gotoAndStop("init_game");
};
}
Frame 27
stop();
_global.init_game(1);
Frame 29
_root.level_buttons_mc._visible = false;
_root.level_mc._visible = false;
var k = 1;
while (k < _global.curr_game.get_num_levels()) {
var mc = _root.scores_mc.add_mc("scores_row", 0, (k - 1) * 20);
mc.num_level = k;
mc.num_moves = _global.curr_game.get_level_moves(k);
k++;
}
Instance of Symbol 64 MovieClip [basic_button] in Frame 29
onClipEvent (load) {
this.label = "Back";
this.onClick = function () {
_root.level_buttons_mc._visible = true;
_root.level_mc._visible = true;
_global.go_to_level(1);
};
}
Symbol 18 MovieClip [bar_right] Frame 1
stop();
Symbol 19 MovieClip [bar_left] Frame 1
stop();