info343/labs/4/solution/maze-ex3.js

// maze-ex3.js
// Sample JavaScript solution for Lab 4: Mouse Maze
// (Partial solution through Exercise 3)
// INFO 343, Autumn 2012
// Morgan Doocy

/*[<ins>]*/// Whether the user has hit a wall.
var lost = false;/*[</ins>]*/

// When the page is ready, attach event handlers.
$(document).ready(function() {
/*[<ins>]*/   // Display a success/failure message when #end is moused over.
   $('#end').mouseover(win);/*[</ins>]*/
   
   // Lose the game when any boundary *inside the maze* is moused over (not
   // including the example boundary).
   $('div#maze div.boundary').mouseover(lose);
});

// Set the maze boundaries to the "lost" state.
function lose() {
/*[<ins>]*/   lost = true;/*[</ins>]*/
   $('div#maze div.boundary').addClass('youlose');
}

/*[<ins>]*/// Display a success message if the user hasn't lost the game.
function win() {
   if (lost) {
      alert('You lose!');
   } else {
      alert('You win! :]');
   }
}/*[</ins>]*/