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

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

// Whether the user has hit a wall.
var lost = false;

// When the page is ready, attach event handlers.
$(document).ready(function() {
/*[<ins>]*/   // Reset the maze when #start is clicked.
   $('#start').click(reset);/*[</ins>]*/
   
   // Display a success message when #end is moused over.
   $('#end').mouseover(win);
   
   // 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 and status message to the "lost" state.
function lose() {
   lost = true;
   $('div#maze div.boundary').addClass('youlose');
}

/*[<ins>]*/// Reset the boundaries and allow the user to play again.
function reset() {
   lost = false;
   $('div#maze div.boundary').removeClass('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! :]');
   }
}