refactorign

This commit is contained in:
Gwenhael Le Moine 2011-07-13 20:27:10 +02:00
parent 123d82374b
commit e85db4362f

View file

@ -24,8 +24,7 @@ var css_classes = {
var sprites = {}; var sprites = {};
var board_infos = {}; var board_infos = {};
var options = { var options = {
starting_level : 0, starting_level : 0
dom_place : ""
}; };
var state = { var state = {
moving : cell.BALL, moving : cell.BALL,
@ -194,9 +193,7 @@ function make_a_move( state, where ) {
} }
function start_loop( state, elt, board_infos ) { function start_loop( state, elt, board_infos ) {
options.dom_place = elt; display_level( state, elt );
display_level( state, options.dom_place );
$(document).focus( ); $(document).focus( );
$(document).click( $(document).click(
@ -239,7 +236,7 @@ function start_loop( state, elt, board_infos ) {
} }
} }
display_level( state, options.dom_place ); display_level( state, elt );
} }
}); });
$(document).keydown( $(document).keydown(
@ -286,28 +283,12 @@ function start_loop( state, elt, board_infos ) {
} }
} }
display_level( state, options.dom_place ); display_level( state, elt );
}); });
} }
function initialize_a_star( elt ) { function initialize_a_star( elt ) {
var starhtml = '<div class="gstar">'; // load sprites
starhtml += '<aside id="help">' + format_help( state ) + '</aside>';
starhtml += '<canvas id="starboard" width="320" height="180"></canvas>';
starhtml += '<aside id="infos"></aside>';
starhtml += '</div>';
$( elt ).html( starhtml );
var board_infos = {};
board_infos.offset = $(elt + " #starboard").offset();
board_infos.dimensions = {};
board_infos.dimensions.width = $(elt + " #starboard").width();
board_infos.dimensions.height = $(elt + " #starboard").height();
board_infos.cell_dimensions = {};
board_infos.cell_dimensions.width = board_infos.dimensions.width / LEVEL_WIDTH;
board_infos.cell_dimensions.height = board_infos.dimensions.height / LEVEL_HEIGHT;
sprites.ball = new Image(); sprites.ball = new Image();
sprites.ball.src = "themes/HP48/tex_ball.png"; sprites.ball.src = "themes/HP48/tex_ball.png";
sprites.ball_selected = new Image(); sprites.ball_selected = new Image();
@ -323,9 +304,23 @@ function initialize_a_star( elt ) {
sprites.gift = new Image(); sprites.gift = new Image();
sprites.gift.src = "themes/HP48/tex_gift.png"; sprites.gift.src = "themes/HP48/tex_gift.png";
state = load_level( levels, 0 ); var starhtml = '<div class="gstar">';
// display_level( state, options.dom_place ); starhtml += '<aside id="help">' + format_help( state ) + '</aside>';
display_on_canvas( state, "starboard" ); starhtml += '<canvas id="starboard" width="320" height="180"></canvas>';
starhtml += '<aside id="infos"></aside>';
starhtml += '</div>';
$( elt ).html( starhtml );
board_infos.offset = $(elt + " #starboard").offset();
board_infos.dimensions = {};
board_infos.dimensions.width = $(elt + " #starboard").width();
board_infos.dimensions.height = $(elt + " #starboard").height();
board_infos.cell_dimensions = {};
board_infos.cell_dimensions.width = board_infos.dimensions.width / LEVEL_WIDTH;
board_infos.cell_dimensions.height = board_infos.dimensions.height / LEVEL_HEIGHT;
state = load_level( levels, options.starting_level );
start_loop( state, elt, board_infos ); start_loop( state, elt, board_infos );
} }