show final alert only once, stop handling event then

This commit is contained in:
Gwenhael Le Moine 2011-07-14 12:57:51 +02:00
parent b7bb9f32d6
commit 396cefca7d

View file

@ -65,7 +65,8 @@ function initialize_a_star( dom_container ) {
moving: cell.BALL,
distance_travelled: 0,
level: 0,
board: ""
board: "",
it_s_over: false
};
////// FUNCTIONS //////
@ -238,6 +239,7 @@ function initialize_a_star( dom_container ) {
}
function event_handler( e ) {
if ( !state.it_s_over ) {
if ( e.type === "click" ) {
var movingpos = get_pos( state.moving );
var notmovingpos = get_pos( ( state.moving != cell.BALL ) ? cell.BALL : cell.CUBE );
@ -312,10 +314,12 @@ function initialize_a_star( dom_container ) {
display_level( );
}
else {
state.it_s_over = true;
alert( "You won!" );
}
}
}
}
function start_loop( ) {