; to amek js2-mode happy

This commit is contained in:
Gwenhael Le Moine 2011-07-04 21:10:44 +02:00
parent 0eb514274b
commit f14b429b17

View file

@ -6,23 +6,23 @@ cell= {
BALL: '@', BALL: '@',
CUBE: 'H', CUBE: 'H',
VOID: ' ', VOID: ' ',
GIFT: 'x', GIFT: 'x'
} };
direction = { direction = {
UP: 'u', UP: 'u',
DOWN: 'd', DOWN: 'd',
LEFT: 'l', LEFT: 'l',
RIGHT: 'r', RIGHT: 'r'
} };
options = { options = {
starting_level: 0, starting_level: 0
} };
state = { state = {
moving: cell.BALL, moving: cell.BALL,
moves: 0, moves: 0,
level: 0, level: 0,
board: "" board: ""
} };
levels = [ "#################@## x#H## x #### ##x ## ## x #### x x x ## x x## x ## ##x x#################", levels = [ "#################@## x#H## x #### ##x ## ## x #### x x x ## x x## x ## ##x x#################",
" # # # # # ### x @# #x #x x # # x x # # # x # # #H# x # # # # #xx## # # # # ", " # # # # # ### x @# #x #x x # # x x # # # x # # #H# x # # # # #xx## # # # # ",
@ -51,7 +51,7 @@ levels = [ "#################@## x#H## x #### ##x ##
"################# # ## x ##x x ## #x x ## ## x ## #x ## #x x# x ## ##x #@ H ################# " ]; "################# # ## x ##x x ## #x x ## ## x ## #x ## #x x# x ## ##x #@ H ################# " ];
function count_gifts( state ) { function count_gifts( state ) {
n = 0 n = 0;
for ( i = 0 ; i < LEVEL_HEIGHT * LEVEL_WIDTH ; i++ ) { for ( i = 0 ; i < LEVEL_HEIGHT * LEVEL_WIDTH ; i++ ) {
if ( state.board.charAt( i ) == cell.GIFT ) { if ( state.board.charAt( i ) == cell.GIFT ) {
n++; n++;
@ -62,7 +62,7 @@ function count_gifts( state ) {
function get_pos( state, actor ) { function get_pos( state, actor ) {
p = state.board.indexOf( actor, state.board ); p = state.board.indexOf( actor, state.board );
pos = {} pos = {};
pos[ 1 ] = Math.floor( p / LEVEL_WIDTH ); /* y */ pos[ 1 ] = Math.floor( p / LEVEL_WIDTH ); /* y */
pos[ 0 ] = p - ( pos[ 1 ] * LEVEL_WIDTH ); /* x */ pos[ 0 ] = p - ( pos[ 1 ] * LEVEL_WIDTH ); /* x */
@ -116,15 +116,15 @@ function format_level( state ) {
default: default:
break; break;
} }
dl = dl + "<span class=\"" + classes + "\">" + c + "</span>" dl = dl + "<span class=\"" + classes + "\">" + c + "</span>";
} }
dl = dl + "<br />" dl = dl + "<br />";
} }
return dl; return dl;
} }
function load_level( levelset, nb ) { function load_level( levelset, nb ) {
state.level = nb state.level = nb;
state.board = levelset[ state.level ]; state.board = levelset[ state.level ];
state.moves = 0; state.moves = 0;
state.moving = cell.BALL; state.moving = cell.BALL;
@ -202,12 +202,12 @@ function start_loop( state, elt ) {
break; break;
case 78: // n case 78: // n
if ( state.level < levels.length - 1 ) { if ( state.level < levels.length - 1 ) {
state = load_level( levels, state.level + 1 ) state = load_level( levels, state.level + 1 );
} }
break; break;
case 80: // p case 80: // p
if ( state.level > 0 ) { if ( state.level > 0 ) {
state = load_level( levels, state.level - 1 ) state = load_level( levels, state.level - 1 );
} }
break; break;
default: default:
@ -216,7 +216,7 @@ function start_loop( state, elt ) {
if ( won_or_not( state ) ) { if ( won_or_not( state ) ) {
if ( state.level < levels.length - 1 ) { 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!" );