Initialization

This commit is contained in:
2017-09-28 09:27:36 +00:00
commit cfa29297a4
32 changed files with 13733 additions and 0 deletions

84
js/countdown.js Normal file
View File

@@ -0,0 +1,84 @@
var COUNTDOWN = {
mustStop: false,
init: function( minutes, seconds ) {
COUNTDOWN.minutes = minutes;
COUNTDOWN.seconds = seconds;
COUNTDOWN.mustStop = false;
// $( "#countdown" ).width( ( minutes > 0 ? 90 : 0 ) + 90);
// $( "#countdown" ).css( "background-color", "black" );
},
start: function() {
if( COUNTDOWN.mustStop )
return;
COUNTDOWN.running = true;
var currentMinutes = "";
var currentSeconds = "";
var imageMinutes = "";
var imageSeconds = "";
currentMinutes = COUNTDOWN.minutes;
currentSeconds = COUNTDOWN.seconds;
var nextMinutes = COUNTDOWN.minutes;
var nextSeconds = COUNTDOWN.seconds - 1;
if( nextSeconds < 0 && nextMinutes > 0 ) {
nextSeconds = 59;
nextMinutes = Math.min(0, nextMinutes -1);
}
COUNTDOWN.minutes = nextMinutes;
COUNTDOWN.seconds = nextSeconds;
if( currentMinutes <= 0 && currentSeconds < 10 )
$( "#countdown" ).css( "background-color", "red" );
if(parseInt(currentMinutes) < 10 ) currentMinutes = "0" + currentMinutes;
if(parseInt(currentSeconds) < 10 ) currentSeconds = "0" + currentSeconds;
for(i = 0; i < String(currentMinutes).length; i++) {
imageMinutes += "<div class='clock n"+ String(currentMinutes)[i]+"'></div>";
}
for(i = 0; i < String(currentSeconds).length; i++) {
imageSeconds += "<div class='clock n"+ String(currentSeconds)[i]+"'></div>";
}
if( COUNTDOWN.minutes > 0) {
$("#subMinutes").empty().removeClass( "hide" ).append( imageMinutes );;
$(".clock.clock.separator").removeClass( "hide" );
} else {
$("#subMinutes").empty().addClass( "hide" );
$(".clock.clock.separator").addClass( "hide" );
}
$("#subSeconds").empty().append( imageSeconds );
if( nextMinutes >= 0 && nextSeconds >= 0 )
setTimeout( "COUNTDOWN.start()", 1000 );
else
COUNTDOWN.callback();
},
add: function(seconds) {
console.log( "Adding " + seconds + " seconds to countdown" );
COUNTDOWN.seconds = COUNTDOWN.seconds + seconds;
},
setTime: function( seconds ) {
console.log( "Setting " + seconds + " seconds to countdown" );
COUNTDOWN.seconds = seconds;
},
stop: function() {
COUNTDOWN.mustStop = true;
},
callback: function() {
console.log( "COUNTDOWN.callback" );
}
};

52
js/dictionary.js Normal file
View File

@@ -0,0 +1,52 @@
var dictionary = {
'en' : {
'wordfighter.howto.1' : 'When you click on the "Start" button, a combinaison of letters is generated.',
'wordfighter.howto.2' : 'The goal is to retrieve a maximum of words with these letters using your keyboard.',
'wordfighter.howto.3' : 'To validate a word, simply press the "Enter" key.',
'wordfighter.howto.4' : 'To get new letters, press the "Space" bar.',
'wordfighter.howto.E' : 'Search words between 3 and 7 letters',
'wordfighter.howto.M' : 'Search words between 3 and 6 letters',
'wordfighter.howto.H' : 'Search words between 4 and 7 letters',
'wordfighter.howto.X' : 'No escape ! You can\'t have new letters before reach all words !',
'wordfighter.title' : 'Word Fighters',
'wordfighter.letters' : '%s letters',
'game.no.score' : 'No highscore',
'game.waiting.opponent' : 'Waiting for your opponent',
'game.waiting.ready' : 'Get ready !!',
'game.start' : 'Start !!',
'game.win' : 'You win !!',
'game.loose' : 'You loose !!',
'game.draw' : 'Draw !!',
'game.replay' : 'Play again',
'game.level.E' : 'Easy',
'game.level.M' : 'Medium',
'game.level.H' : 'Hard',
'game.level.X' : 'Extrem',
'game.choose.level' : 'Choose your level'
},
'fr' : {
'wordfighter.howto.1' : 'Dès que vous cliquez sur le bouton "Jouer", une combinaison de lettres est générée.',
'wordfighter.howto.2' : 'Le but est de retrouver le maximum de mots avec ces lettres en utilisant le clavier.',
'wordfighter.howto.3' : 'Pour valider un mot, utilisez simplement la touche "Entrer".',
'wordfighter.howto.4' : 'Pour avoir un nouveau tirage, pressez la touche "Espace".',
'wordfighter.howto.E' : 'Trouver des mots de 3 à 7 lettres',
'wordfighter.howto.M' : 'Trouver des mots de 3 à 6 lettres',
'wordfighter.howto.H' : 'Trouver des mots de 4 à 7 lettres',
'wordfighter.howto.X' : 'Il n\'y a pas déchappatoire! Vous ne pouvez pas changer vos lettres tant que tous les mots n\'ont pas été trouvés!',
'wordfighter.title' : 'Word Fighters',
'wordfighter.letters' : '%s lettres',
'game.no.score' : 'Aucun score',
'game.waiting.opponent' : 'En attente de votre adversaire',
'game.waiting.ready' : 'Pret !!',
'game.start' : 'Partez !!',
'game.win' : 'Victoire !!',
'game.loose' : 'Vous avez perdu !!',
'game.draw' : 'Match nul !!',
'game.replay' : 'Rejouer',
'game.level.E' : 'Facile',
'game.level.M' : 'Intermediaire',
'game.level.H' : 'Diffile',
'game.level.X' : 'Extreme',
'game.choose.level' : 'Choisissez votre niveau'
}
}

563
js/fighters.js Normal file
View File

@@ -0,0 +1,563 @@
var PLAYGROUND_WIDTH = 384;
var PLAYGROUND_HEIGHT = 96;
var FIGHTER_STD_WIDTH = 82;
var FIGHTER_EXT_WIDTH = 126;
var FIGHTER_EXT_WIDTH_2 = 136;
var FIGHTER_EXT_WIDTH_3 = 95;
var FIGHTER_EXT_WIDTH_4 = 105;
var FIGHTER_EXT_WIDTH_5 = 86;
var FIGHTER1_POSX = PLAYGROUND_WIDTH / 2 - (FIGHTER_EXT_WIDTH - FIGHTER_STD_WIDTH) / 2 - FIGHTER_STD_WIDTH;
var FIGHTER2_POSX = PLAYGROUND_WIDTH / 2 + (FIGHTER_EXT_WIDTH - FIGHTER_STD_WIDTH) / 2;
var COUNTDOWN_WIDTH = 48;
var COUNTDOWN_POSX = (PLAYGROUND_WIDTH - COUNTDOWN_WIDTH) / 2;
var HEALTH_REFRESH_RATE = 15;
var FIGHTER_HEALTH = 60;
var LOOP_COUNT_REFRESH = 66;
var fighter1 = null;
var fighter2 = null;
var loopCount = 0;
var fighters = new Array();
$(function(){
//Playground Sprites
var background = new $.gameQuery.Animation({imageURL: "images/background.png", offsety: PLAYGROUND_HEIGHT * Math.floor(Math.random()*11)});
$("#playground").playground({height: PLAYGROUND_HEIGHT, width: PLAYGROUND_WIDTH, keyTracker: true});
$.playground().addGroup("background", {width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT})
.addSprite( "background1",
{posx: 0, posy: 0,
height: PLAYGROUND_HEIGHT, width: PLAYGROUND_WIDTH,
animation: background})
.end()
.addGroup("fighters", {width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT})
.end()
.addGroup( "hud", {width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT})
.end();
$("#hud").append("<div id='countdown'><div id='subSeconds'></div></div>");
$("#hud").append("<div id='step_title'></div>");
$.playground().registerCallback(function(){
if( fighter1 )
updateHealth( $("#player1_health_level"), fighter1.health / fighter1.maxHealth );
if( fighter2 ) {
updateHealth( $("#player2_health_level"), fighter2.health / fighter2.maxHealth );
//$("#player2_health_level").css( "margin-left", ( 100 - (fighter2.health / fighter2.maxHealth) * 100) );
}
loopCount++;
if( loopCount == LOOP_COUNT_REFRESH ) {
loopCount = 0;
var fighter = fighters[ "fighter1" ];
if( fighter && fighter.isIdle() ) {
fighter.node.width( FIGHTER_STD_WIDTH );
fighter.node.x( FIGHTER1_POSX );
}
fighter = fighters[ "fighter2" ];
if( fighter && fighter.isIdle() ) {
fighter.node.width( FIGHTER_STD_WIDTH );
fighter.node.x( FIGHTER2_POSX );
}
}
}, HEALTH_REFRESH_RATE);
$.playground().startGame( function() {});
addFighter = function( fighter) {
$("#fighters").addSprite("fighter1", {animation: fighter.animations["idle"], posx:FIGHTER1_POSX, posy: 15, width: FIGHTER_STD_WIDTH, height: FIGHTER_STD_WIDTH});
fighter.node = $("#fighter1");
fighter1 = fighter;
fighters[ "fighter1" ] = fighter;
};
addFighter2 = function( fighter ) {
$("#fighters").addSprite("fighter2", {animation: fighter.animations["idle"], posx:FIGHTER2_POSX, posy: 15, width: FIGHTER_STD_WIDTH, height: FIGHTER_STD_WIDTH});
fighter.node = $("#fighter2");
$("#fighter2").fliph(true);
fighter2 = fighter;
fighters[ "fighter2" ] = fighter;
};
addScoreBoard = function() {
$("#hud").append("<div id='scoreboard' class='scoreboard'><div class='subScoreboard'></div></div>");
};
addHealthBars = function() {
$("#hud").append("<div id='player1_health' style='left: 10px;' class='health_bar'><div id='player1_health_level' class='health_level good'></div></div>");
$("#hud").append("<div id='player2_health' style='left: " + (PLAYGROUND_WIDTH - 100 - 10) + "px;'class='health_bar'><div id='player2_health_level' class='health_level good reverse'></div></div>");
};
updateHealth = function( HTMLDiv, health ) {
HTMLDiv.removeClass();
HTMLDiv.addClass("health_level");
if( health > 2/3)
HTMLDiv.addClass("good");
else if( health > 1/3)
HTMLDiv.addClass("middle");
else
HTMLDiv.addClass("bad");
HTMLDiv.width( (health * 100) + "%" );
};
display_text = function( text, divId = "#step_title", offset = 1, changePosition = true ) {
var message = text.toLowerCase();
var divHTML = $(divId);
var html = "";
var yPos = offset * 16;
for( var i = 0; i < message.length; i++ ) {
var letter = message[i];
var x = ((97 - message.charCodeAt(i)) * 16);
if( letter == " " )
html += "<div class='blank'></div>";
else if( letter == "!" )
html += "<div class='clock' style='background-position: -416px -" + yPos + "px'></div>";
else
html += "<div class='clock' style='background-position: " + x + "px -" + yPos + "px'></div>";
}
divHTML.empty();
divHTML.width( (text.length * 16) + "px");
if( changePosition ) {
divHTML.css( "margin-left", "-" + (text.length * 8) + "px");
}
divHTML.append( html );
};
hide_text = function() {
$("#step_title").empty();
};
});
//Game objects:
function Fighter(){
this.node = null;
this.animations = new Array();
this.maxHealth = FIGHTER_HEALTH;
this.health = FIGHTER_HEALTH;
this.idle_state = false;
this.isIdle = function() {
return this.idle_state;
};
this.setIdle = function( state ) {
this.idle_state = state;
};
this.start = function() {
this.node.setAnimation(this.animations["start"],
function(node) {
fighters[ node.id ].idle();
});
};
this.idle = function() {
this.node.setAnimation(this.animations["idle"]);
this.setIdle( true );
};
this.punch = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.setAnimation(this.animations["punch"],
function(node) {
fighters[ node.id ].idle();
});
};
this.kick = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.setAnimation(this.animations["kick"],
function(node) {
fighters[ node.id ].idle();
});
};
this.special = function() {};
this.victory = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.setAnimation(this.animations["victory"]);
};
this.loose = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.setAnimation(this.animations["loose"]);
};
this.ouch = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.setAnimation(this.animations["ouch"],
function(node) {
fighters[ node.id ].idle();
});
};
this.laught = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.setAnimation(this.animations["laught"],
function(node) {
fighters[ node.id ].idle();
});
};
};
function Ryu(){
this.animations["start"] = new $.gameQuery.Animation({imageURL: "images/ryu.png", numberOfFrame: 8, offsety: 0, delta: FIGHTER_STD_WIDTH, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["victory"] = new $.gameQuery.Animation({imageURL: "images/ryu.png", numberOfFrame: 7, offsety: 82, delta: FIGHTER_STD_WIDTH, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["victory2"] = new $.gameQuery.Animation({imageURL: "images/ryu.png", numberOfFrame: 4, offsety: 82, offsetx: 246, delta: FIGHTER_STD_WIDTH, rate: 200, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["idle"] = new $.gameQuery.Animation({imageURL: "images/ryu.png", numberOfFrame: 6, offsety: 164, delta: FIGHTER_STD_WIDTH, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL});
this.animations["punch"] = new $.gameQuery.Animation({imageURL: "images/ryu.png", numberOfFrame: 6, offsety: 246, delta: FIGHTER_EXT_WIDTH, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["kick"] = new $.gameQuery.Animation({imageURL: "images/ryu.png", numberOfFrame: 7, offsety: 328, delta: FIGHTER_EXT_WIDTH_2, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["ouch"] = new $.gameQuery.Animation({imageURL: "images/ryu.png", numberOfFrame: 4, offsety: 410, delta: FIGHTER_STD_WIDTH, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["laught"] = new $.gameQuery.Animation({imageURL: "images/ryu.png", numberOfFrame: 7, offsety: 492, delta: FIGHTER_EXT_WIDTH_3, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["loose"] = new $.gameQuery.Animation({imageURL: "images/ryu.png", numberOfFrame: 9, offsety: 574, delta: FIGHTER_EXT_WIDTH_4, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["loose2"] = new $.gameQuery.Animation({imageURL: "images/ryu.png", numberOfFrame: 6, offsety: 656, delta: FIGHTER_EXT_WIDTH_4, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE});
};
Ryu.prototype = new Fighter();
Ryu.prototype.punch = function() {
this.node.width( FIGHTER_EXT_WIDTH );
if( this.node.fliph() ) {
this.node.x( -(FIGHTER_EXT_WIDTH - FIGHTER_STD_WIDTH), true);
}
this.node.setAnimation(this.animations["punch"],
function(node) {
var HTMLnode = fighters[ node.id ].node;
HTMLnode.width( FIGHTER_STD_WIDTH );
if( HTMLnode.fliph() ) {
HTMLnode.x(FIGHTER_EXT_WIDTH - FIGHTER_STD_WIDTH, true);
}
fighters[ node.id ].idle();
});
}
Ryu.prototype.kick = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.width( FIGHTER_EXT_WIDTH_2 );
if( this.node.fliph() ) {
this.node.x( -(FIGHTER_EXT_WIDTH_2 - FIGHTER_STD_WIDTH), true);
}
this.node.setAnimation(this.animations["kick"],
function(node) {
var HTMLnode = fighters[ node.id ].node;
HTMLnode.width( FIGHTER_STD_WIDTH );
if( HTMLnode.fliph() ) {
HTMLnode.x( FIGHTER_EXT_WIDTH_2 - FIGHTER_STD_WIDTH, true);
}
fighters[ node.id ].idle();
});
}
Ryu.prototype.laught = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.width( FIGHTER_EXT_WIDTH_3 );
if( this.node.fliph() ) {
this.node.x( -(FIGHTER_EXT_WIDTH_3 - FIGHTER_STD_WIDTH),true);
}
this.node.setAnimation(this.animations["laught"],
function(node) {
var HTMLnode = fighters[ node.id ].node;
HTMLnode.width( FIGHTER_STD_WIDTH );
if( HTMLnode.fliph() ) {
HTMLnode.x(FIGHTER_EXT_WIDTH_3 - FIGHTER_STD_WIDTH, true);
}
fighters[ node.id ].idle();
});
}
Ryu.prototype.loose = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.width( FIGHTER_EXT_WIDTH_4 );
if( this.node.fliph() ) {
this.node.x( -(FIGHTER_EXT_WIDTH_4 - FIGHTER_STD_WIDTH), true);
}
this.node.setAnimation(this.animations["loose"],
function(node) {
fighters[ node.id ].node.setAnimation(fighters[ node.id ].animations["loose2"]);
});
}
Ryu.prototype.victory = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.setAnimation(this.animations["victory"],
function(node) {
fighters[ node.id ].node.setAnimation(fighters[ node.id ].animations["victory2"]);
});
}
function Sakura(){
this.animations["start"] = new $.gameQuery.Animation({imageURL: "images/sakura.png", numberOfFrame: 9, offsety: 334, delta: FIGHTER_EXT_WIDTH_3, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["victory"] = new $.gameQuery.Animation({imageURL: "images/sakura.png", numberOfFrame: 7, offsety: 82, delta: FIGHTER_EXT_WIDTH_5, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["victory2"] = new $.gameQuery.Animation({imageURL: "images/sakura.png", numberOfFrame: 4, offsety: 82, offsetx: 258, delta: FIGHTER_EXT_WIDTH_5, rate: 200, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["idle"] = new $.gameQuery.Animation({imageURL: "images/sakura.png", numberOfFrame: 5, offsety: 0, delta: FIGHTER_STD_WIDTH, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL});
this.animations["punch"] = new $.gameQuery.Animation({imageURL: "images/sakura.png", numberOfFrame: 5, offsety: 166, delta: FIGHTER_EXT_WIDTH, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["kick"] = new $.gameQuery.Animation({imageURL: "images/sakura.png", numberOfFrame: 6, offsety: 252, delta: FIGHTER_EXT_WIDTH, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["ouch"] = new $.gameQuery.Animation({imageURL: "images/sakura.png", numberOfFrame: 4, offsetx: 492, delta: FIGHTER_STD_WIDTH, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
// this.animations["laught"] = new $.gameQuery.Animation({imageURL: "images/sakura.png", numberOfFrame: 7, offsety: 492, delta: FIGHTER_EXT_WIDTH_3, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["loose"] = new $.gameQuery.Animation({imageURL: "images/sakura.png", numberOfFrame: 10, offsety: 412, delta: FIGHTER_EXT_WIDTH_4, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE });
// this.animations["loose2"] = new $.gameQuery.Animation({imageURL: "images/sakura.png", numberOfFrame: 6, offsety: 656, delta: FIGHTER_EXT_WIDTH_4, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE});
};
Sakura.prototype = new Fighter();
Sakura.prototype.victory = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.setAnimation(this.animations["victory"],
function(node) {
fighters[ node.id ].node.setAnimation(fighters[ node.id ].animations["victory2"]);
});
}
Sakura.prototype.punch = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.width( FIGHTER_EXT_WIDTH );
if( this.node.fliph() ) {
this.node.x( -(FIGHTER_EXT_WIDTH - FIGHTER_STD_WIDTH), true);
}
this.node.setAnimation(this.animations["punch"],
function(node) {
var HTMLnode = fighters[ node.id ].node;
HTMLnode.width( FIGHTER_STD_WIDTH );
if( HTMLnode.fliph() ) {
HTMLnode.x(FIGHTER_EXT_WIDTH - FIGHTER_STD_WIDTH, true);
}
fighters[ node.id ].idle();
});
}
Sakura.prototype.kick = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.width( FIGHTER_EXT_WIDTH );
if( this.node.fliph() ) {
this.node.x( -(FIGHTER_EXT_WIDTH - FIGHTER_STD_WIDTH), true);
}
this.node.setAnimation(this.animations["kick"],
function(node) {
var HTMLnode = fighters[ node.id ].node;
HTMLnode.width( FIGHTER_STD_WIDTH );
if( HTMLnode.fliph() ) {
HTMLnode.x(FIGHTER_EXT_WIDTH - FIGHTER_STD_WIDTH, true);
}
fighters[ node.id ].idle();
});
}
Sakura.prototype.laught = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.width( FIGHTER_EXT_WIDTH_3 );
if( this.node.fliph() ) {
this.node.x(-(FIGHTER_EXT_WIDTH_3 - FIGHTER_STD_WIDTH), true);
}
this.node.setAnimation(this.animations["start"],
function(node) {
var HTMLnode = fighters[ node.id ].node;
HTMLnode.width( FIGHTER_STD_WIDTH );
if( HTMLnode.fliph() ) {
HTMLnodex(FIGHTER_EXT_WIDTH_3 - FIGHTER_STD_WIDTH, true);
}
fighters[ node.id ].idle();
});
}
Sakura.prototype.loose = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.width( FIGHTER_EXT_WIDTH_4 );
if( this.node.fliph() ) {
this.node.x( -(FIGHTER_EXT_WIDTH_4 - FIGHTER_STD_WIDTH), true);
}
this.node.setAnimation(this.animations["loose"]);
}
function Akuma(){
this.animations["start"] = new $.gameQuery.Animation({imageURL: "images/akuma.png", numberOfFrame: 11, offsety: 82, delta: FIGHTER_STD_WIDTH, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["victory"] = new $.gameQuery.Animation({imageURL: "images/akuma.png", numberOfFrame: 10, offsety: 328, delta: FIGHTER_STD_WIDTH, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["victory2"] = new $.gameQuery.Animation({imageURL: "images/akuma.png", numberOfFrame: 8, offsety: 328, offsetx: 162, delta: FIGHTER_STD_WIDTH, rate: 200, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["idle"] = new $.gameQuery.Animation({imageURL: "images/akuma.png", numberOfFrame: 11, offsety: 0, delta: FIGHTER_STD_WIDTH, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL});
this.animations["punch"] = new $.gameQuery.Animation({imageURL: "images/akuma.png", numberOfFrame: 5, offsety: 164, delta: FIGHTER_EXT_WIDTH_4, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["kick"] = new $.gameQuery.Animation({imageURL: "images/akuma.png", numberOfFrame: 7, offsety: 246, delta: FIGHTER_EXT_WIDTH_2, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["ouch"] = new $.gameQuery.Animation({imageURL: "images/akuma.png", numberOfFrame: 7, offsety: 576, delta: FIGHTER_EXT_WIDTH_4, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
// this.animations["laught"] = new $.gameQuery.Animation({imageURL: "images/akuma.png", numberOfFrame: 7, offsety: 492, delta: FIGHTER_EXT_WIDTH_3, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["loose"] = new $.gameQuery.Animation({imageURL: "images/akuma.png", numberOfFrame: 9, offsety: 412, delta: FIGHTER_EXT_WIDTH_4, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["loose2"] = new $.gameQuery.Animation({imageURL: "images/akuma.png", numberOfFrame: 3, offsety: 494, delta: FIGHTER_EXT_WIDTH_4, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE});
};
Akuma.prototype = new Fighter();
Akuma.prototype.punch = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.width( FIGHTER_EXT_WIDTH_4 );
if( this.node.fliph() ) {
this.node.x( -(FIGHTER_EXT_WIDTH_4 - FIGHTER_STD_WIDTH), true);
}
this.node.setAnimation(this.animations["punch"],
function(node) {
var HTMLnode = fighters[ node.id ].node;
HTMLnode.width( FIGHTER_STD_WIDTH );
if( HTMLnode.fliph() ) {
HTMLnode.x(FIGHTER_EXT_WIDTH_4 - FIGHTER_STD_WIDTH, true);
}
fighters[ node.id ].idle();
});
}
Akuma.prototype.kick = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.width( FIGHTER_EXT_WIDTH_2 );
if( this.node.fliph() ) {
this.node.x( -(FIGHTER_EXT_WIDTH_2 - FIGHTER_STD_WIDTH), true);
}
this.node.setAnimation(this.animations["kick"],
function(node) {
var HTMLnode = fighters[ node.id ].node;
HTMLnode.width( FIGHTER_STD_WIDTH );
if( HTMLnode.fliph() ) {
HTMLnode.x(FIGHTER_EXT_WIDTH_2 - FIGHTER_STD_WIDTH, true);
}
fighters[ node.id ].idle();
});
}
Akuma.prototype.victory = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.setAnimation(this.animations["victory"],
function(node) {
fighters[ node.id ].node.setAnimation(fighters[ node.id ].animations["victory2"]);
});
}
Akuma.prototype.loose = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.width( FIGHTER_EXT_WIDTH_4 );
if( this.node.fliph() ) {
this.node.x( -(FIGHTER_EXT_WIDTH_4 - FIGHTER_STD_WIDTH), true);
}
this.node.setAnimation(this.animations["loose"],
function(node) {
fighters[ node.id ].node.setAnimation(fighters[ node.id ].animations["loose2"]);
});
}
Akuma.prototype.ouch = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.width( FIGHTER_EXT_WIDTH_4 );
if( this.node.fliph() ) {
this.node.x(-(FIGHTER_EXT_WIDTH_4 - FIGHTER_STD_WIDTH), true);
}
this.node.setAnimation(this.animations["ouch"],
function(node) {
var HTMLnode = fighters[ node.id ].node;
HTMLnode.width( FIGHTER_STD_WIDTH );
if( HTMLnode.fliph() ) {
HTMLnode.x(FIGHTER_EXT_WIDTH_4 - FIGHTER_STD_WIDTH, true);
}
fighters[ node.id ].idle();
});
}
function Felicia(){
this.animations["start"] = new $.gameQuery.Animation({imageURL: "images/felicia.png", numberOfFrame: 10, offsety: 82, delta: FIGHTER_STD_WIDTH, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["victory"] = new $.gameQuery.Animation({imageURL: "images/felicia.png", numberOfFrame: 10, offsety: 328, delta: FIGHTER_STD_WIDTH, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["victory2"] = new $.gameQuery.Animation({imageURL: "images/felicia.png", numberOfFrame: 5, offsety: 328, offsetx: 410, delta: FIGHTER_STD_WIDTH, rate: 200, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["idle"] = new $.gameQuery.Animation({imageURL: "images/felicia.png", numberOfFrame: 8, offsety: 0, delta: FIGHTER_STD_WIDTH, rate: 200, type: $.gameQuery.ANIMATION_HORIZONTAL});
this.animations["punch"] = new $.gameQuery.Animation({imageURL: "images/felicia.png", numberOfFrame: 6, offsety: 164, delta: FIGHTER_EXT_WIDTH, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["kick"] = new $.gameQuery.Animation({imageURL: "images/felicia.png", numberOfFrame: 7, offsety: 246, delta: FIGHTER_EXT_WIDTH, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["ouch"] = new $.gameQuery.Animation({imageURL: "images/felicia.png", numberOfFrame: 5, offsety: 492, delta: FIGHTER_EXT_WIDTH_4, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
// this.animations["laught"] = new $.gameQuery.Animation({imageURL: "images/felicia.png", numberOfFrame: 7, offsety: 492, delta: FIGHTER_EXT_WIDTH_3, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE | $.gameQuery.ANIMATION_CALLBACK});
this.animations["loose"] = new $.gameQuery.Animation({imageURL: "images/felicia.png", numberOfFrame: 6, offsety: 410, delta: FIGHTER_STD_WIDTH, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_ONCE });
};
Felicia.prototype = new Fighter();
Felicia.prototype.punch = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.width( FIGHTER_EXT_WIDTH );
if( this.node.fliph() ) {
this.node.x( -(FIGHTER_EXT_WIDTH - FIGHTER_STD_WIDTH), true);
}
this.node.setAnimation(this.animations["punch"],
function(node) {
var HTMLnode = fighters[ node.id ].node;
HTMLnode.width( FIGHTER_STD_WIDTH );
if( HTMLnode.fliph() ) {
HTMLnode.x(FIGHTER_EXT_WIDTH - FIGHTER_STD_WIDTH, true);
}
fighters[ node.id ].idle();
});
}
Felicia.prototype.kick = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.width( FIGHTER_EXT_WIDTH );
if( this.node.fliph() ) {
this.node.x(-(FIGHTER_EXT_WIDTH - FIGHTER_STD_WIDTH), true);
}
this.node.setAnimation(this.animations["kick"],
function(node) {
var HTMLnode = fighters[ node.id ].node;
HTMLnode.width( FIGHTER_STD_WIDTH );
if( HTMLnode.fliph() ) {
HTMLnode.x(FIGHTER_EXT_WIDTH - FIGHTER_STD_WIDTH, true);
}
fighters[ node.id ].idle();
});
}
Felicia.prototype.victory = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.setAnimation(this.animations["victory"],
function(node) {
fighters[ node.id ].node.setAnimation(fighters[ node.id ].animations["victory2"]);
});
}
Felicia.prototype.ouch = function() {
if( !this.isIdle() )
return;
this.setIdle( false );
this.node.width( FIGHTER_EXT_WIDTH_4 );
if( this.node.fliph() ) {
this.node.x( -(FIGHTER_EXT_WIDTH_4 - FIGHTER_STD_WIDTH), true);
}
this.node.setAnimation(this.animations["ouch"],
function(node) {
var HTMLnode = fighters[ node.id ].node;
HTMLnode.width( FIGHTER_STD_WIDTH );
if( HTMLnode.fliph() ) {
HTMLnode.x(FIGHTER_EXT_WIDTH_4 - FIGHTER_STD_WIDTH, true);
}
fighters[ node.id ].idle();
});
}

0
js/lexik.js Normal file
View File

207
js/mock.js Normal file
View File

@@ -0,0 +1,207 @@
var lexik = null;
var enigma = null;
var score = 0;
var time = 0;
$(document).ready(function() {
var oReq = new XMLHttpRequest();
oReq.open("GET", "resources/french", true);
oReq.responseType = "arraybuffer";
oReq.onload = function(oEvent) {
var arrayBuffer = oReq.response;
// if you want to access the bytes:
var byteArray = new Uint8Array(arrayBuffer);
var gunzip = new Zlib.Gunzip(new Uint8Array(byteArray));
var plain = gunzip.decompress();
lexik = JSON.parse(Utf8ArrayToStr(plain));
};
oReq.send();
});
function generateEnigma(level) {
var min = 3, max = 7;
switch( level ) {
case 'E' :
min = 3;
max = 7;
break;
case 'M' :
min = 3;
max = 6;
break;
case 'H' :
min = 4;
max = 7;
break;
default :
min = 3;
max = 6;
}
var mustRun = false;
var letters;
var allWords = {};
do {
letters = getRandomSet(max);
allWords = getWords2param(letters, min);
var wordsCount = 0;
for (var i = min; i < max + 1; i++) {
var words = allWords[i];
if (words != null) {
wordsCount += words.length;
}
}
mustRun = wordsCount < (max + min) * 0.7;
} while (mustRun);
return {letters: letters, words: allWords, minLength: min, maxLength: max};
}
function getRandomSet( maxLetter) {
var statistics = lexik.statistics;
var max = 0.0;
for (var i = 0; i < 26; i++) {
max += statistics[i];
}
var letters = [];
for (var i = 0; i < maxLetter; i++) {
letters[i] = getRandomLetter(max, statistics);
}
return letters.sort();
}
function getRandomLetter(max, statistics) {
var r = Math.random() * max;
max = 0.0;
for (var i = 0; i < 26; i++) {
max += statistics[i];
if (r < max) {
return String.fromCharCode(i + 97);
}
}
return 'z';
}
function getWords2param(letters, minimum) {
var words = [];
for (var i = letters.length; i > 2; i--) {
var newWords = getWords(letters, minimum, i);
if (newWords != null && newWords.length > 0 ) {
for( var j = 0; j < newWords.length; j++) {
if( words.indexOf(newWords[j]) == -1 ) {
words.push(newWords[j]);
}
}
}
}
var lists = {};
for (var i = 0; i < words.length; i++) {
var word = words[i];
var list = lists[word.length];
if (list === undefined) {
list = [];
lists[word.length] = list;
}
list.push(word);
}
for (var i = letters.length; i > 2; i--) {
var list = lists[i];
if (list !== undefined) {
list = list.sort();
}
}
return lists;
}
function getWords(letters, minimum, size) {
if (size < minimum) {
return null;
}
var setSize = letters.length;
if (size == setSize) {
var currentNode = lexik.nodes.nodes[letters[0]];
if (currentNode == null) {
return null;
}
for (var i = 1; i < setSize; i++) {
currentNode = currentNode.nodes[letters[i]];
if (currentNode == null) {
return null;
}
if (i == setSize - 1) {
return currentNode.words;
}
}
return null;
}
var results = [];
for (var i = 0; i < setSize - size; i++) {
for (var j = 0; j < setSize; j++) {
var words = getWords(letters.slice(0,j).concat(letters.slice(j+1)), minimum, size - i);
if (words != null && words.length > 0) {
results = results.concat(words);
}
}
}
return results.sort();
}
$.mockjax({
url: "/wordFighter/levelChoice",
status: 200
});
$.mockjax({
url: "/wordFighter/ready",
status: 200
});
$.mockjax({
url: "/wordFighter/newEnigma",
contentType: "application/json",
response: function(data) {
enigma = generateEnigma(data.data.level);
if( time != 0 ) {
enigma.remaining_time = 60 - (new Date().getTime() - time) / 1000;
score = 0;
} else {
enigma.remaining_time = 60;
}
time = new Date().getTime();
this.responseText = JSON.stringify(enigma)
}
});
$.mockjax( {
url: '/wordFighter/get_ready',
contentType: 'text/html',
responseText: '<div>\
<div style="height: 261px;">\
<div id="fighter1portrait" class="portrait"></div>\
</div>\
</div>\
<div style="height: 261px;width: 96px;">\
<div id="versus" style="width: 96px;height: 16px;margin-left: -48px;margin-top: -8px;position: relative;left: 50%;top: 50%;">\
<div id="howToPlay"></div>\
</div>\
</div>\
<div>\
<div style="height: 261px;">\
<div id="fighter2portrait" class="portrait"></div>\
</div>\
</div>'
})
$.mockjax( {
url: '/wordFighter/gameOver',
contentType: 'text/html',
responseText: ''
});

44
js/scoreboard.js Normal file
View File

@@ -0,0 +1,44 @@
var SCOREBOARD = {
score: 0,
scoreLength: 6,
init: function(size) {
if( typeof size !== "undefined" )
SCOREBOARD.scoreLength = size;
SCOREBOARD.score = 0;
SCOREBOARD.set_score( 0 );
},
add: function(addToScore, div) {
SCOREBOARD.set_score( SCOREBOARD.score + addToScore, div);
},
set_score: function( score, div ) {
var currentScore = "";
var imageScore = "";
SCOREBOARD.score = score;
currentScore = SCOREBOARD.pad();
for(i = 0; i < String(currentScore).length; i++) {
imageScore += "<div class='clock n"+ String(currentScore)[i]+"'></div>";
}
if( typeof div === "undefined" )
div = $(".subScoreboard");
div.empty();
div.append( imageScore );
},
pad: function() {
var str = '' + SCOREBOARD.score;
while (str.length < SCOREBOARD.scoreLength) {
str = '0' + str;
}
return str;
},
callback: function() {
console.log( "SCOREBOARD.callback" );
}
};

440
js/wordfighters.js Normal file
View File

@@ -0,0 +1,440 @@
var DURATION = 60;
var WordFighter = {
id: null,
word: "",
started: false,
activeKeypress: false,
level: 'E',
answers: null,
letters: null,
score: 0,
combo: 0,
opponentCombo: 0,
first: true,
opponentLevel: null,
startDate: null,
toggle_howto: function() {
$('#howto').slideToggle();
},
change_level: function( chosenLevel ) {
WordFighter.level = chosenLevel;
switch( chosenLevel ) {
case 'E' :
$("#valid3header").show();
$("#valid3column").show();
$("#valid7header").show();
$("#valid7column").show();
break;
case 'M' :
$("#valid3header").show();
$("#valid3column").show();
$("#valid7header").hide();
$("#valid7column").hide();
break;
case 'H' :
$("#valid3header").hide();
$("#valid3column").hide();
$("#valid7header").show();
$("#valid7column").show();
break;
case 'X' :
$("#valid3header").show();
$("#valid3column").show();
$("#valid7header").hide();
$("#valid7column").hide();
break;
}
},
notify_dual: function() {
$.ajax({
url: '/wordFighter/levelChoice',
data: { level: WordFighter.level },
success: function(data){
$("#waitingGame").load('/wordFighter/get_ready', function() {
console.log( "Current opponent : " + WordFighter.opponentLevel );
console.log( data );
display_text('versus', '#howToPlay', 1, false);
$("#fighter1portrait").addClass( WordFighter.level );
$("#fighter1portrait").css( "visibility", "visible");
addFighter( WordFighter.get_fighter( WordFighter.level) );
addScoreBoard();
WordFighter.opponentLevel = WordFighter.get_random_fighter();
setTimeout( function() {
WordFighter.start_game();
}, 3000 );
WordFighter.set_opponent();
});
}
});
},
get_fighter : function(level) {
switch( level ) {
case 'E' :
return new Sakura();
case 'M' :
return new Ryu();
case 'H' :
return new Felicia();
case 'X' :
return new Akuma();
}
},
get_random_fighter : function() {
var levels = new Array();
levels[ 0 ] = 'E';
levels[ 1 ] = 'M';
levels[ 2 ] = 'H';
levels[ 3 ] = 'X';
return levels[ Math.floor(Math.random() * 4) ];
},
set_opponent: function() {
var fighter2Div = $("#fighter2portrait");
if( fighter2Div != "undefined" && WordFighter.opponentLevel != null ){
fighter2Div.addClass(WordFighter.opponentLevel);
fighter2Div.css( "visibility", "visible");
addFighter2( WordFighter.get_fighter( WordFighter.opponentLevel ) );
}
},
hit_opponent: function( hit ) {
fighter2.ouch();
fighter2.health = fighter2.health - hit;
},
start_game: function() {
$("#waitingGame").hide();
$("#gamePanel").show();
$("#start").attr("disabled","disabled");
$("#level").attr("disabled","disabled");
fighter1.start();
fighter2.start();
display_text(game_waiting_ready);
WordFighter.activeKeypress = false;
WordFighter.clean();
WordFighter.first = true;
WordFighter.init_score();
COUNTDOWN.init(0, DURATION);
SCOREBOARD.init();
setTimeout( function() {
WordFighter.new_word();
COUNTDOWN.callback = function() {
$('#start').removeAttr('disabled');
$('#level').removeAttr('disabled');
WordFighter.game_over();
};
}, 3000)
},
setLetter: function( index, character ) {
$( "#letter" + index ).removeClass();
$( "#letter" + index ).addClass( "letter" );
$( "#letter" + index ).addClass( character );
},
keypressedHandler: function( event ) {
if( WordFighter.activeKeypress )
return false;
WordFighter.activeKeypress = true;
if( event.which == 32 && WordFighter.level != 'X' ) { // space
while( WordFighter.erase() );
WordFighter.started = false;
WordFighter.new_word();
WordFighter.activeKeypress = false;
return true;
}
if( event.which == 13 ) { // enter
WordFighter.check_word();
WordFighter.activeKeypress = false;
return true;
}
if( event.which == 8 && !$.browser.safari) { // backspace
if( WordFighter.word.length > 0 ) {
WordFighter.erase();
WordFighter.activeKeypress = false;
}
return false;
}
var character = String.fromCharCode(event.which);
for( var index = 1; index < 8; index++ )
{
if( WordFighter.process( index, character, "hide" ) ) {
$( "#typed" + (WordFighter.word.length + 1) ).show();
$( "#typed" + (WordFighter.word.length + 1) ).addClass( character );
WordFighter.word += character;
WordFighter.activeKeypress = false;
return true;
}
}
WordFighter.activeKeypress = false;
return true;
},
// Hack for Chrome
prevent_backspace: function( event ) {
if( event.which == 8 ) { // backspace
if( WordFighter.word.length > 0 ) {
WordFighter.erase();
WordFighter.activeKeypress = false;
}
return false;
}
},
clean: function() {
for( var index = 1; index < 8; index++ ) {
var character = WordFighter.word.charAt( index );
$( "#typed" + WordFighter.word.length ).removeClass( character );
$( "#letter" + index ).removeClass();
$( "#letter" + index ).addClass( "letter" );
}
},
erase: function() {
var character = WordFighter.word.charAt( WordFighter.word.length - 1);
for( var index = 1; index < 8; index++ )
{
if( WordFighter.process( index, character, "show" ) ) {
$( "#typed" + WordFighter.word.length ).hide();
$( "#typed" + WordFighter.word.length ).removeClass( character );
WordFighter.word = WordFighter.word.substring(0, WordFighter.word.length - 1);
return true;
}
}
return false;
},
process: function( index, character, visibility ) {
if( $( "#letter" + index ).hasClass( character ) )
{
if( ( visibility === "hide" && $( "#letter" + index ).hasClass( "hideLetter" ) )
|| ( visibility === "show" && $( "#letter" + index ).hasClass( "showLetter" ) ) ) {
return false;
}
$( "#letter" + index ).addClass( visibility + "Letter");
$( "#letter" + index ).removeClass( visibility === "show" ? "hideLetter" : "showLetter" );
return true;
}
return false;
},
new_word: function() {
if( WordFighter.started ) {
return false;
}
WordFighter.combo = 0;
$.ajax({
url: '/wordFighter/newEnigma',
data: {level: WordFighter.level},
success: function(data){
console.log("Ajax : ");
console.log(data);
WordFighter.letters = data.letters;
for( i = 1; i < WordFighter.letters.length + 1; i++ )
{
WordFighter.setLetter( i, data.letters[ i - 1 ] )
}
WordFighter.answers = data.words;
var rest = 0;
var total = 0;
for( var i = 3; i < 8; i++ ) {
total += $( "#valid" + i).length;
rest += $( "#valid" + i).find( ":empty" ).length;
}
if( !WordFighter.first ) {
if( rest == 0) {
COUNTDOWN.add( total * 5 );
WordFighter.change_score( WordFighter.score + total * 5 );
} else {
if( rest / total < 0.5 )
fighter2.kick();
else
fighter2.punch();
fighter1.ouch();
WordFighter.change_score( Math.max( 0, WordFighter.score -5 * rest ) );
}
}
for( i = data.minLength; i < data.maxLength +1; i++ )
{
$( "#valid" + i ).empty();
var obj = data.words[i];
var count = 0;
if( obj != undefined )
count = obj.length;
for( j = 0; j < count; j++ )
{
$( "#valid" + i ).append( "<li id=\"valid" + i + "-" + j + "\" style=\"background-color:yellow\"></li>");
}
}
WordFighter.started = true;
if( WordFighter.first ) {
WordFighter.startDate = new Date();
COUNTDOWN.start();
display_text( game_start );
setTimeout( function() {
hide_text();
}, 1500);
WordFighter.first = false;
}
}
});
},
check_word: function() {
var lAnswers = WordFighter.answers[ WordFighter.word.length ];
var position = -1;
if( lAnswers )
position = lAnswers.indexOf( WordFighter.word );
if( position == -1 ) {
WordFighter.combo = 0;
WordFighter.activeKeypress = true;
while(WordFighter.erase());
WordFighter.activeKeypress = false;
return false;
}
else {
WordFighter.activeKeypress = true;
if( $("#valid" + WordFighter.word.length + "-" + position).text().length == 0 ) {
WordFighter.combo++;
if( ( WordFighter.combo % 3 ) == 0 )
fighter1.kick();
else
fighter1.punch();
WordFighter.hit_opponent( WordFighter.word.length );
$("#valid" + WordFighter.word.length + "-" + position).append( WordFighter.word );
WordFighter.change_score( WordFighter.score + 10 * WordFighter.word.length );
WordFighter.check_validated();
}
}
while(WordFighter.erase());
WordFighter.activeKeypress = false;
},
check_validated: function() {
var rest = 0;
for( var i = 3; i < 8; i++ ) {
rest += $( "#valid" + i).find( ":empty" ).length;
}
if( rest == 0 ) {
while( WordFighter.erase() );
WordFighter.started = false;
WordFighter.new_word();
WordFighter.activeKeypress = false;
}
},
game_over: function() {
COUNTDOWN.stop();
WordFighter.show_game_over();
WordFighter.activeKeypress = true;
var highscore = true;
var win = WordFighter.score > 0;
for( i = 3; i < 8; i++ )
{
var words = WordFighter.answers[i];
if( words != undefined )
{
for( j = 0; j < words.length; j++ )
{
var id = "#valid" + ( words[ j ].length ) + "-" + j;
$( id ).empty();
$( id ).append( words[ j ] );
}
}
}
WordFighter.started = false;
},
show_game_over: function() {
$('.button').show();
/*
$.ajax({
url: "/wordFighter/gameOver",
data: {level: WordFighter.level},
success: function(data){
$("#modalDialog").prepend(data).modal({backdrop: false, show: true});
$(".replayButton").bind( "click", function() {
if( WordFighter.mode!="dual")
window.location.href = "/wordFighter/game";
else
window.location.href = "/wordFighter/invite/" + opponent;
} );
}
});
*/
},
init_score: function() {
WordFighter.score = 0;
SCOREBOARD.init();
},
change_score: function(score) {
WordFighter.score = score;
SCOREBOARD.set_score( WordFighter.score );
}
};
function drawText( divHTML, message ) {
var html = "";
for( var i = 0; i < message.length; i++ ) {
var letter = message[i];
var x = ((97 - message.charCodeAt(i)) * 16);
if( letter == " " )
html += "<div class='blank'></div>";
else if( letter == "!" )
html += "<div class='clock' style='background-position: -416px -16px'></div>";
else
html += "<div class='clock' style='background-position: " + x + "px -16px'></div>";
}
divHTML.css( "width", (message.length * 16) + "px");
divHTML.css( "margin-left", "-" + (message.length * 8) + "px");
divHTML.css( "margin-top", "20px");
divHTML.css( "position", "relative");
divHTML.css( "left", "50%");
divHTML.css( "top", "50%");
divHTML.append( html );
};

View File

@@ -0,0 +1,235 @@
WordFighter.notify_dual = function() {
$.ajax({
url: '/wordFighter/levelChoice',
data: { level: WordFighter.level },
success: function(data){
$("#waitingGame").load('/wordFighter/ready', function() {
console.log( "Current opponent : " + WordFighter.opponentLevel );
console.log( data );
$("#fighter1portrait").addClass( WordFighter.level );
$("#fighter1portrait").css( "visibility", "visible");
addFighter( WordFighter.get_fighter( WordFighter.level) );
if( data.opponentLevel != "undefined" ) {
WordFighter.opponentLevel = data.opponentLevel;
}
WordFighter.set_opponent();
});
}
});
}
WordFighter.new_word = function() {
if( WordFighter.started ) {
return false;
}
WordFighter.combo = 0;
$.ajax({
url: '/wordFighter/newEnigma',
data: {level: WordFighter.level, mode: WordFighter.mode },
success: function(data){
WordFighter.letters = data.letters;
for( i = 1; i < WordFighter.letters.length + 1; i++ )
{
WordFighter.setLetter( i, data.letters[ i - 1 ] )
}
WordFighter.answers = data.words;
var rest = 0;
var total = 0;
for( var i = 3; i < 8; i++ ) {
total += $( "#valid" + i).length;
rest += $( "#valid" + i).find( ":empty" ).length;
}
console.log( data.remaining_time + " seconds" );
COUNTDOWN.setTime( data.remaining_time);
for( i = data.minLength; i < data.maxLength +1; i++ )
{
$( "#valid" + i ).empty();
var obj = data.words[i];
var count = 0;
if( obj != undefined ) {
if( WordFighter.mode == "offline" )
count = obj.length;
else
count = obj;
}
for( j = 0; j < count; j++ )
{
$( "#valid" + i ).append( "<li id=\"valid" + i + "-" + j + "\" style=\"background-color:yellow\"></li>");
}
}
WordFighter.started = true;
if( WordFighter.first ) {
WordFighter.startDate = new Date();
COUNTDOWN.start();
display_text( game_start );
setTimeout( function() {
hide_text();
}, 1500);
WordFighter.first = false;
}
}
});
}
WordFighter.check_word = function() {
$.ajax({
type: "POST",
url: '/wordFighter/check',
data: {suggested: WordFighter.word },
success: function(data){
if( data.valid )
{
WordFighter.combo++;
if( ( WordFighter.combo % 3 ) == 0 )
fighter1.kick();
else
fighter1.punch();
WordFighter.activeKeypress = true;
$("#valid" + WordFighter.word.length + "-" + data.position).append( WordFighter.word );
WordFighter.change_score( data.score );
fighter1.punch();
WordFighter.hit_opponent(WordFighter.word.length );
while(WordFighter.erase());
WordFighter.activeKeypress = false;
WordFighter.check_validated();
} else {
WordFighter.combo = 0;
WordFighter.activeKeypress = true;
while(WordFighter.erase());
WordFighter.activeKeypress = false;
}
fighter1.health = data.fighter1;
fighter2.health = data.fighter2;
if( fighter1.health == 0 || fighter2.health == 0 )
WordFighter.game_over();
if( data.remaining_time )
COUNTDOWN.setTime( data.remaining_time );
}
});
}
WordFighter.game_over = function() {
COUNTDOWN.stop();
WordFighter.activeKeypress = true;
var highscore = true;
var win = WordFighter.score > 0;
$.ajax({
url: '/wordFighter/answers',
data: {action: "answers"},
success: function(data){
$("#modalDialog").prepend(data.modal).modal({backdrop: false, show: true});
$(".replayButton").bind( "click", function() {
if( WordFighter.mode!="dual")
window.location.href = "/wordFighter/game";
else
window.location.href = "/wordFighter/invite/" + opponent;
} );
for( i = data.minLength; i < data.maxLength +1; i++ )
{
var words = data.answers[i];
if( words != undefined )
{
for( j = 0; j < words.length; j++ )
{
var id = "#valid" + ( words[ j ].length ) + "-" + j;
$( id ).empty();
$( id ).append( words[ j ] );
}
}
}
WordFighter.answers = null;
fighter1.health = data.fighter1;
fighter2.health = data.fighter2;
console.log( fighter1.health + " vs " + fighter2.health );
switch( data.state ) {
case "win" :
fighter1.victory();
fighter2.loose();
display_text( game_win );
break;
case "loose" :
fighter1.loose();
fighter2.victory();
display_text( game_loose );
break;
default :
display_text( game_draw );
}
}
});
WordFighter.started = false;
}
WordFighter.callback = function(data) {
if( data.id != WordFighter.id && data.action != "replay" )
return;
if( data.action != undefined ) {
if( data.fighter1 != undefined )
fighter1.health = data.fighter1;
if( data.fighter2 != undefined )
fighter2.health = data.fighter2;
switch( data.action ) {
case "start" :
addHealthBars();
$("#waitingGame").show();
WordFighter.start_game();
break;
case "join" :
break;
case "opponentLevel" :
WordFighter.opponentLevel = data.level;
WordFighter.set_opponent();
break;
case "hit" :
case "beat" :
WordFighter.opponentCombo++;
if( (WordFighter.opponentCombo % 3 ) == 0 )
fighter2.kick();
else
fighter2.punch();
fighter1.ouch();
if( data.action == "beat" )
WordFighter.game_over();
break;
case "timeout" :
if( WordFighter.started ) {
var endDate = new Date();
console.log( WordFighter.startDate.toTimeString() + " - " + endDate.toTimeString() + " = Timeout in " + ( (endDate.getSeconds() - WordFighter.startDate.getSeconds())) + " / " + (endDate.getTime() - WordFighter.startDate.getTime()));
WordFighter.game_over();
}
break;
case "replay" :
$(".replayButton").bind( "click", function() {
window.location.href = '/wordFighter/game/' + data.id;
})
break;
}
}
}

172
js/wordfighters_single.js Normal file
View File

@@ -0,0 +1,172 @@
WordFighter.notify_dual = function() {
$.ajax({
url: '/wordFighter/levelChoice',
data: { level: WordFighter.level },
success: function(data){
$("#waitingGame").load('/wordFighter/ready', function() {
console.log( "Current opponent : " + WordFighter.opponentLevel );
console.log( data );
$("#fighter1portrait").addClass( WordFighter.level );
$("#fighter1portrait").css( "visibility", "visible");
addFighter( WordFighter.get_fighter( WordFighter.level) );
addScoreBoard();
WordFighter.opponentLevel = WordFighter.get_random_fighter();
setTimeout( function() {
WordFighter.start_game();
}, 3000 );
WordFighter.set_opponent();
});
}
});
}
WordFighter.new_word = function() {
if( WordFighter.started ) {
return false;
}
WordFighter.combo = 0;
$.ajax({
url: '/wordFighter/newEnigma',
data: {level: WordFighter.level},
success: function(data){
console.log(data);
WordFighter.letters = data.letters;
for( i = 1; i < WordFighter.letters.length + 1; i++ )
{
WordFighter.setLetter( i, data.letters[ i - 1 ] )
}
WordFighter.answers = data.words;
var rest = 0;
var total = 0;
for( var i = 3; i < 8; i++ ) {
total += $( "#valid" + i).length;
rest += $( "#valid" + i).find( ":empty" ).length;
}
console.log( data.remaining_time + " seconds" );
COUNTDOWN.setTime( data.remaining_time);
if( rest / total < 0.5 )
fighter2.kick();
else
fighter2.punch();
fighter1.ouch();
WordFighter.change_score( data.score );
for( i = data.minLength; i < data.maxLength +1; i++ )
{
$( "#valid" + i ).empty();
var obj = data.words[i];
var count = 0;
if( obj != undefined )
count = obj;
for( j = 0; j < count; j++ )
{
$( "#valid" + i ).append( "<li id=\"valid" + i + "-" + j + "\" style=\"background-color:yellow\"></li>");
}
}
WordFighter.started = true;
if( WordFighter.first ) {
WordFighter.startDate = new Date();
COUNTDOWN.start();
display_text( game_start );
setTimeout( function() {
hide_text();
}, 1500);
WordFighter.first = false;
}
}
});
}
WordFighter.check_word = function() {
$.ajax({
type: "POST",
url: '/wordFighter/check',
data: {suggested: WordFighter.word },
success: function(data){
if( data.valid )
{
WordFighter.combo++;
if( ( WordFighter.combo % 3 ) == 0 )
fighter1.kick();
else
fighter1.punch();
WordFighter.activeKeypress = true;
$("#valid" + WordFighter.word.length + "-" + data.position).append( WordFighter.word );
WordFighter.change_score( data.score );
fighter1.punch();
WordFighter.hit_opponent(WordFighter.word.length );
while(WordFighter.erase());
WordFighter.activeKeypress = false;
WordFighter.check_validated();
} else {
WordFighter.combo = 0;
WordFighter.activeKeypress = true;
while(WordFighter.erase());
WordFighter.activeKeypress = false;
}
if( data.remaining_time )
COUNTDOWN.setTime( data.remaining_time );
}
});
}
WordFighter.game_over = function() {
COUNTDOWN.stop();
WordFighter.activeKeypress = true;
var highscore = true;
var win = WordFighter.score > 0;
$.ajax({
url: '/wordFighter/answers',
data: {action: "answers"},
success: function(data){
console.log(data);
$("#modalDialog").prepend(data.modal).modal({backdrop: false, show: true});
$(".replayButton").bind( "click", function() {
if( WordFighter.mode!=="dual")
window.location.href = "/wordFighter/game";
else
window.location.href = "/wordFighter/invite/" + opponent;
} );
for( i = data.minLength; i < data.maxLength +1; i++ )
{
var words = data.answers[i];
if( words != undefined )
{
for( j = 0; j < words.length; j++ )
{
var id = "#valid" + ( words[ j ].length ) + "-" + j;
$( id ).empty();
$( id ).append( words[ j ] );
}
}
}
WordFighter.answers = null;
SCOREBOARD.set_score( data.score );
}
});
WordFighter.started = false;
}