Skip to content

Instantly share code, notes, and snippets.

@videlais

videlais/Maze.js Secret

Created January 8, 2014 00:27
Embed
What would you like to do?
CreateMaze.twee
:: Start
<<display "CreateMaze">>
The entrance of the cave stands before you.
[[Enter Cave]]
:: CreateMaze
<<silently>>
<<set $CreateMaze =
function()
{
var maze =
[[0,0,0,0,0,0,0,0,0,0,0],
[0,1,1,1,0,1,1,1,1,1,0],
[0,0,0,1,0,0,0,0,0,1,0],
[0,1,0,1,1,1,1,1,0,1,0],
[0,1,0,0,0,0,0,1,0,1,0],
[0,1,1,1,1,1,1,1,0,1,0],
[0,0,0,0,0,0,0,1,0,1,0],
[0,1,0,1,1,1,1,1,1,1,0],
[0,1,0,1,0,0,0,1,0,0,0],
[0,1,1,1,0,1,1,1,1,2,0],
[0,0,0,0,0,0,0,0,0,0,0]];
var x = 1;
var y = 1;
$posx = 1;
$posy = 1;
macros['navigate'] =
{
handler: function(obj, fnc, val)
{
x = $posx; y = $posy;
if(maze[y-1][x] eq 1) {
$North = 1;
} else if(maze[x][y+1] eq 2) {
$Exit = 1;
} else {
$North = 0;
}
if(maze[y+1][x] eq 1) {
$South = 1;
} else if(maze[x][y-1] eq 2) {
$Exit = 1;
} else {
$South = 0;
}
if(maze[y][x-1] eq 1) {
$West = 1;
} else if(maze[x-1][y] eq 2) {
$Exit = 1;
} else {
$West = 0;
}
if(maze[y][x+1] eq 1) {
$East = 1;
} else if(maze[x+1][y] eq 2) {
$Exit = 1;
} else {
$East = 0;
}
}
}
}
>>
<<print $CreateMaze()>>
<<endsilently>>
:: template [script]
History.prototype.originalDisplay = History.prototype.display;
History.prototype.display = function (title, link, render)
{
if ((render != 'quietly') && (render != 'offscreen'))
removeChildren($('passages'));
this.originalDisplay.apply(this, arguments);
};
:: North
<<set $posy = $posy - 1>>
<<print "(X: " + $posx + "; Y: " + $posy + ")">>
<<navigate>>
<<if $North eq 1>>
[[North]]
<<endif>>
<<if $South eq 1>>
[[South]]
<<endif>>
<<if $West eq 1>>
[[West]]
<<endif>>
<<if $East eq 1>>
[[East]]
<<endif>>
<<if $Exit eq 1>>
[[Exit]]
<<endif>>
:: StoryTitle
Basic Maze in Twine
:: West
<<set $posx = $posx - 1>>
<<print "(X: " + $posx + "; Y: " + $posy + ")">>
<<navigate>>
<<if $North eq 1>>
[[North]]
<<endif>>
<<if $South eq 1>>
[[South]]
<<endif>>
<<if $West eq 1>>
[[West]]
<<endif>>
<<if $East eq 1>>
[[East]]
<<endif>>
<<if $Exit eq 1>>
[[Exit]]
<<endif>>
:: Enter Cave
<<navigate>>
<<if $North eq 1>>
[[North]]
<<endif>>
<<if $South eq 1>>
[[South]]
<<endif>>
<<if $West eq 1>>
[[West]]
<<endif>>
<<if $East eq 1>>
[[East]]
<<endif>>
:: East
<<set $posx = $posx + 1>>
<<print "(X: " + $posx + "; Y: " + $posy + ")">>
<<navigate>>
<<if $North eq 1>>
[[North]]
<<endif>>
<<if $South eq 1>>
[[South]]
<<endif>>
<<if $West eq 1>>
[[West]]
<<endif>>
<<if $East eq 1>>
[[East]]
<<endif>>
<<if $Exit eq 1>>
[[Exit]]
<<endif>>
:: Exit
This is the exit.
:: StoryAuthor
Dan Cox
:: South
<<set $posy = $posy + 1>>
<<print "(X: " + $posx + "; Y: " + $posy + ")">>
<<navigate>>
<<if $North eq 1>>
[[North]]
<<endif>>
<<if $South eq 1>>
[[South]]
<<endif>>
<<if $West eq 1>>
[[West]]
<<endif>>
<<if $East eq 1>>
[[East]]
<<endif>>
<<if $Exit eq 1>>
[[Exit]]
<<endif>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment