mirror of
https://github.com/gwenhael-le-moine/c-urs_-toil-s.git
synced 2024-12-26 09:58:48 +01:00
store the dom element where star will be displayed
This commit is contained in:
parent
3565772ffb
commit
9d060fd25f
1 changed files with 11 additions and 10 deletions
|
@ -22,7 +22,8 @@ var css_classes = {
|
|||
"x" : "gift"
|
||||
};
|
||||
var options = {
|
||||
starting_level : 0
|
||||
starting_level : 0,
|
||||
dom_place : ""
|
||||
};
|
||||
var state = {
|
||||
moving : cell.BALL,
|
||||
|
@ -136,6 +137,11 @@ function format_infos( state ) {
|
|||
return infos;
|
||||
}
|
||||
|
||||
function display_level( state, elt ) {
|
||||
var starhtml = '<div class="gstar"><div id="blackboard">' + format_level( state, false ) + '</div><aside id="infos">' + format_infos( state ) + '</aside></div>';
|
||||
$( elt ).html( starhtml );
|
||||
}
|
||||
|
||||
function load_level( levelset, nb ) {
|
||||
state.level = nb;
|
||||
state.board = levelset[ state.level ];
|
||||
|
@ -144,12 +150,6 @@ function load_level( levelset, nb ) {
|
|||
return state;
|
||||
}
|
||||
|
||||
function display_level( state, elt ) {
|
||||
var starhtml = '<div class="gstar"><div id="blackboard">' + format_level( state, false ) + '</div><aside id="infos">' + format_infos( state ) + '</aside></div>';
|
||||
$( elt ).html( starhtml );
|
||||
}
|
||||
|
||||
|
||||
function make_a_move( state, where ) {
|
||||
var motion = [ 0, 0 ];
|
||||
var item_coord = get_pos( state, state.moving );
|
||||
|
@ -195,7 +195,8 @@ function make_a_move( state, where ) {
|
|||
}
|
||||
|
||||
function start_loop( state, elt ) {
|
||||
display_level( state, elt );
|
||||
options.dom_place = elt;
|
||||
display_level( state, options.dom_place );
|
||||
|
||||
$( document ).keydown( function( e ) {
|
||||
switch( e.keyCode ) {
|
||||
|
@ -230,13 +231,13 @@ function start_loop( state, elt ) {
|
|||
|
||||
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 {
|
||||
alert( "You won!" );
|
||||
}
|
||||
}
|
||||
|
||||
display_level( state, elt );
|
||||
display_level( state, options.dom_place );
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue