refoctoring to have state always as first argument ; fix end of game test

This commit is contained in:
Gwenhael Le Moine 2011-07-04 17:23:22 +02:00
parent 92bfa8e599
commit 1c7ce20bcb
2 changed files with 12 additions and 10 deletions

View file

@ -49,8 +49,8 @@
<script src="js/star.js"></script> <script src="js/star.js"></script>
<script> <script>
state = load_level( levels, 0 ); state = load_level( levels, 0 );
start_loop( "#blackboard", state ); start_loop( state, "#blackboard" );
$("#blackboard").focus(); $( document ).focus();
</script> </script>
</body> </body>
</html> </html>

View file

@ -104,7 +104,7 @@ function load_level( levelset, nb ) {
return state; return state;
} }
function display_level( elt, state ) { function display_level( state, elt ) {
$( elt ).html( format_level( state ) ); $( elt ).html( format_level( state ) );
} }
@ -153,8 +153,8 @@ function make_a_move( state, where ) {
return state; return state;
} }
function start_loop( elt, state ) { function start_loop( state, elt ) {
display_level( elt, state ); display_level( state, elt );
$( document ).keydown( function( e ) { $( document ).keydown( function( e ) {
switch( e.keyCode ) { switch( e.keyCode ) {
@ -187,13 +187,15 @@ function start_loop( elt, state ) {
break; break;
} }
if ( won_or_not( state ) && state.level < levels.length - 1 ) { if ( won_or_not( state ) ) {
if ( state.level < levels.length - 1 ) {
state = load_level( levels, state.level + 1 ) state = load_level( levels, state.level + 1 )
} }
else { else {
alert( "You won!" ); alert( "You won!" );
}
} }
display_level( elt, state ); display_level( state, elt );
}); });
} }