Skip to content
Browse files

Brought code up to date with Mike's changes.

  • Loading branch information...
1 parent bb56d3b commit 51202fe4732d2a55f2e233175ebd5e18b8acf532 @leonardr leonardr committed Sep 23, 2013
View
4 Maze/server/app.js
@@ -162,6 +162,10 @@ function showCell(req, res, maze, cell) {
}
}
+ // hack to add up/down for demo
+ // body += template.link.replace('{l}',root+'/'+maze+'/'+mov[i-1]).replace('{d}','up');
+ // body += template.link.replace('{l}',root+'/'+maze+'/'+mov[i-1]).replace('{d}','down');
+
// if there is an exit, add it
if(z===ex) {
body += template.link.replace('{l}',root+'/'+maze+'/999').replace('{d}','exit').replace('{t}',data.title);
View
2 Maze/server/data/01-a-beginner-maze.js
@@ -2,7 +2,7 @@
"_id" : "five-by-five",
"title" : "A Beginner's Maze",
"cells" : {
- "cell0":{"title":"Entrance", "doors":[1,1,1,0]},
+ "cell0":{"title":"Entrance Hallway", "doors":[1,1,1,0]},
"cell1":{"title":"Hall of Knives", "doors":[1,1,1,0]},
"cell2":{"title":"Library", "doors":[1,1,0,0]},
"cell3":{"title":"Trophy Room", "doors":[0,1,0,1]},
View
28 Maze/the-boaster/the-boaster.js
@@ -27,7 +27,6 @@ else {
function makeRequest(method, path) {
var hdrs, options, pUrl;
- console.log(path);
pUrl = url.parse(path);
hdrs = {
@@ -51,40 +50,45 @@ function makeRequest(method, path) {
});
res.on('end', function() {
- var doc, nodes, i, x, links, href, flag, choices;
+ var doc, nodes, i, x, links, link, href, flag, choices;
// collect hyperlinks from the response
links = [];
doc = new DOMParser().parseFromString(body, 'text/xml');
nodes = doc.getElementsByTagName('link');
for(i=0, x=nodes.length; i<x; i++) {
- links.push({'rel':nodes[i].getAttribute('rel'), 'href':nodes[i].getAttribute('href')});
+ links.push({'rel':nodes[i].getAttribute('rel'),
+ 'href':nodes[i].getAttribute('href'),
+ 'title':nodes[i].getAttribute('title')});
}
// look for the start and claim victory
- href = findLink(links, 'start');
- if(href) {
+ var link;
+ link = findLink(links, 'start');
+ if(link) {
m.moves = parseInt(Math.random()*12)+1;
console.log(m.winner.replace('{m}',m.moves));
return;
}
// try to find link to a maze
- if(href===undefined) {
- href = findLink(links, 'maze');
+ if(link===undefined) {
+ link = findLink(links, 'maze');
+ console.log('Starting the maze called: '+link.title + '...');
}
// try to find link to a collection
- if(href===undefined) {
- href = findLink(links, 'collection');
+ if(link===undefined) {
+ link = findLink(links, 'collection');
+ console.log('Found a collection of mazes...');
}
// i give up!
- if(href===undefined) {
+ if(link===undefined) {
console.log(m.quitter);
return;
}
- makeRequest('GET',href);
+ makeRequest('GET',link.href);
});
});
@@ -100,7 +104,7 @@ function findLink(links,rel) {
for(i=0, x=links.length; i<x; i++) {
if(links[i].rel===rel) {
- rtn = links[i].href;
+ rtn = links[i];
}
}
return rtn;
View
11 Maze/the-game/index.js
@@ -12,7 +12,7 @@ var thisPage = function() {
g.moves = 0;
g.links = [];
g.mediaType = "application/vnd.amundsen.maze+xml";
- g.startLink = "http://localhost:1337/";
+ g.startLink = ''; //"http://localhost:1337/";
g.sorryMsg = 'Sorry, I don\'t understand what you want to do.';
g.successMsg = 'Congratulations! you\'ve made it out of the maze!';
@@ -291,15 +291,6 @@ var thisPage = function() {
li.id = 'maze-'+(parseInt(i)+1).toString();
li.setAttribute('data-href',g.links[i].href);
li.appendChild(document.createTextNode(g.links[i].title));
- /*
- a = document.createElement('a');
- a.href = g.links[i].href;
- a.rel = g.links[i].rel;
- a.title = g.links[i].title;
- a.onclick = function(){return getMaze();};
- a.appendChild(document.createTextNode(a.title));
- li.appendChild(a);
- */
elm.appendChild(li);
}
}
View
2 YouTypeIt/server/Procfile
@@ -1 +1 @@
-web: nodejs app.js
+web: node app.js
View
4 YouTypeIt/server/app.js
@@ -25,7 +25,7 @@ var reScript = new RegExp('^\/script.js$','i');
// setup for API requests
var cjHeaders = {
- 'Content-type' : 'application/vnd.collection+json'
+ 'Content-type' : 'application/json' //vnd.collection+json'
};
var reAPIList = new RegExp('^\/api\/$', 'i');
var reAPIItem = new RegExp('^\/api\/.*', 'i');
@@ -408,7 +408,7 @@ function sendHtmlResponse(req, res, body, code, lmDate) {
function sendAPIResponse(req, res, body, code, lmDate) {
res.writeHead(code,
- {"Content-Type" : "application/vnd.collection+json",
+ {"Content-Type" : "application/json",
"ETag" : generateETag(body),
"Last-Modified" : lmDate});
res.end(body);
View
1 YouTypeIt/server/templates/home.html
@@ -13,6 +13,7 @@
<p class="links">
<a href="{@host}/messages">Get started</a>
<a href="{@host}/about">About this site</a>
+ <!--<a href="{@host}/login">Login via Example.net</a>-->
</p>
</div>
</body>
View
2 YouTypeIt/server/templates/list.html
@@ -15,7 +15,7 @@
<form action="{@host}/messages" method="post">
<input type="text" name="message" value="" required="true" maxlength="6"/>
- <input type="submit" value="Post" />
+ <input type="submit" />
</form>
<div>

0 comments on commit 51202fe

Please sign in to comment.
Something went wrong with that request. Please try again.