// maze-ex5.js
// Sample JavaScript solution for Lab 4: Mouse Maze
// 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() {
// Reset the maze when #start is clicked.
$('#start').click(reset);
// 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;
/*[<ins>]*/$('#status').text('You lose!');/*[</ins>]*/
$('div#maze div.boundary').addClass('youlose');
}
// Reset the boundaries and allow the user to play again.
function reset() {
lost = false;
/*[<ins>]*/$("#status").text("Find the end!");/*[</ins>]*/
$('div#maze div.boundary').removeClass('youlose');
}
// Display a success message if the user hasn't lost the game.
function win() {
/*[<ins>]*/ if (!lost) {
$('#status').text('You win! :]');
}/*[</ins>]*/
}