Frame 1
function play_game(a) {
game.load_story(a);
game._visible = true;
editor._visible = false;
}
function edit_game() {
game._visible = false;
editor._visible = true;
}
editor._visible = false;
game._visible = false;
Symbol 3 Button
on (release) {
load_path(story);
}
Symbol 8 Button
on (release) {
_parent.load_path(path);
}
Symbol 11 Button
on (release) {
_root.edit_game();
}
Symbol 14 MovieClip Frame 1
function clear_buttons() {
while (buttons.length) {
var x = buttons.pop();
x.removeMovieClip();
}
}
function add_button(a) {
var x = (buttons.length + 3);
button.duplicateMovieClip("button" + x, x);
var y = eval ("button" + x);
y.path = a;
y.text = a.title;
y._x = 200;
y._y = 100 + (x * 24);
buttons.push(y);
}
function load_paths_from(a) {
clear_buttons();
var x = 0;
while (x < a.paths.length) {
add_button(a.paths[x]);
x++;
}
if (x == 0) {
add_button(story);
}
}
function load_path(a) {
text = a.text;
load_paths_from(a);
}
function load_story(a) {
story = a;
load_path(story);
}
button._visible = false;
buttons = new Array();
story = null;
Symbol 17 Button
on (release) {
_root.play_game(load_story(text));
}
Symbol 19 MovieClip Frame 1
function find_newline(a, s) {
var x = 0;
var y = 0;
x = a.indexOf("\r", s);
y = a.indexOf(newline, s);
if (x == -1) {
return(y);
}
if (y == -1) {
return(x);
}
if (x < y) {
return(x + 1);
}
return(y);
}
function path(a) {
var end = 0;
end = find_newline(a, 0);
if (end == -1) {
end = a.length;
}
this.title = a.substring(0, end);
this.text = a.substring(end, a.length);
this.paths = new Array();
}
function load_path(a) {
text = a.text;
load_paths_from(a);
}
function story_loader(a) {
this.story = a;
this.s = 0;
this.e = 0;
this.indent = 0;
}
function load_story(a) {
var x = 0;
var z = new Array();
var loader = new story_loader(a);
loader.get_next();
z.push(loader.get_path());
while (loader.get_next()) {
x = loader.get_indent();
while (x < z.length) {
z.pop();
}
z.push(z[z.length - 1].add_path(loader.get_path()));
}
z[0].title = "Restart";
return(z[0]);
}
text = "start\nwelcome to text adventure\n>begin adventure\nyou are now having an adventure\n>>go to castle\nyou are now at castle\n\nbut drawbridge is up\n>>>look around\nyou are eaten by a manticore\n>>>make loud noises\nyou are eaten by a manticore\n>>go to forest\nyou are eaten by a manticore\n>>go to death mountain\nyou enjoy nice picnic at death mountain\n\nbut you invited a manticore\n>>>isnt that dangerous\nyou are eaten by a manticore\n>credits\nmade by some guy\n>>is there any way to make an option to go back?\nno";
path.prototype.add_path = function (a) {
this.paths.push(a);
return(a);
};
story_loader.prototype.get_next = function () {
var x = 0;
this.e++;
this.s = this.e;
while (this.e < this.story.length) {
this.e = find_newline(this.story, this.e);
if (this.e == -1) {
this.e = this.story.length;
x = 1;
break;
}
if (this.story.charAt(this.e + 1) == ">") {
x = 1;
break;
}
this.e++;
}
if (x) {
x = 0;
while (this.story.charAt(this.s + x) == ">") {
x++;
}
if (!x) {
return(0);
}
this.indent = x;
this.s = this.s + x;
return(1);
}
return(0);
};
story_loader.prototype.get_path = function () {
return(new path(this.story.substring(this.s, this.e)));
};
story_loader.prototype.get_indent = function () {
return(this.indent);
};
_root.play_game(load_story(text));