The LBi Labyrinth Challenge

by laustdeleuran

HTML

<div class="wrapper">
  <h1><a href="http://labyrinth.lbi.co.uk/" target="_blank">The LBi Labyrinth Challenge</a></h1>
  
  <div class="results">
    
  </div>
  
</div>

CSS

@import "http://fonts.googleapis.com/css?family=Droid+Sans:400,700";
/* House cleaning */
html {
  font-family:Droid Sans, Arial, Helvetica, Helvetica Neue, sans-serif;
  color:#333;
  
  background:#ddd;
}
a {
  color:#f1001c;
  text-decoration:none;
}
h1 {
  font-weight:normal;
}
.wrapper {
  padding:2em;
  margin:0 auto;
  max-width:30em;
  
  background:#eee;
}
.maze.is-repeat h2 {
    color:green;
}
.maze.is-new h2 {
  color:red;
}

JavaScript

// Log
// usage: log('inside coolFunc',this,arguments);
// http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  if(this.console){
    console.log( Array.prototype.slice.call(arguments) );
  }
};

// Set up our adventurer
var Adventurer = function () {
  this.construct.apply(this, arguments);
};
Adventurer.prototype = (function () {
  var construct, openRoom, mapRoom, mapDoors, mapNewRoom, chooseDoor, recognizeDoor, exit, shortestRoute;
  
  construct = function (name, email, maze) {
    var scope = this;
    
    scope.name = name;
    scope.email = email;
    scope.rooms = {};
    scope.maze = maze.split('/');
    scope.maze = scope.maze[scope.maze.length - 2];
    scope.path = [];
    scope.pills = [];
    
    openRoom.apply(scope, [maze]);
    
    return scope;
  };
  openRoom = function (room) {
    var scope = this;
    
    scope.path.push(recognizeDoor.apply(scope, [room]));
                    
    $.ajax({
      cache: false,
      complete: function (xhr, status) {
        var response = $.parseJSON(xhr.responseText);
        
        //log('Entering room: ' + response.LocationId);
    
        switch (response.LocationType.toLowerCase()) {
          case 'powerpill':
            log('Yay, found a PowerPill!');
            scope.pills.push(response.LocationId);
          case 'start':
          case 'normal':
            mapRoom.apply(scope, [response]);
            mapDoors.apply(scope, [response.Exits]);
            chooseDoor.apply(scope, [response.Exits]);
            break;
          case 'exit':
            //log('Hey, this is the exit!');
            exit.apply(scope, [response]);
            break;
          default:
            log('Wow, this is a weird room. It feels like a death trap. Wait. It is. Ugh.', response, scope);
            break;
        }
      },
      dataType: 'json',
     ...