nettoyage code et commentaire
This commit is contained in:
parent
c4777017dc
commit
10425889a3
@ -1,6 +1,6 @@
|
|||||||
var bits=60; // how many bits
|
var bits=50; // how many bits
|
||||||
var speed=33; // how fast - smaller is faster
|
var speed=20; // how fast - smaller is faster
|
||||||
var bangs=5; // how many can be launched simultaneously (note that using too many can slow the script down)
|
var bangs=4; // how many can be launched simultaneously (note that using too many can slow the script down)
|
||||||
var colours=new Array("#03f", "#f03", "#0e0", "#93f", "#0cf", "#f93", "#f0c");
|
var colours=new Array("#03f", "#f03", "#0e0", "#93f", "#0cf", "#f93", "#f0c");
|
||||||
// blue red green purple cyan orange pink
|
// blue red green purple cyan orange pink
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
;(function( window ) {
|
;(function( window ) {
|
||||||
|
|
||||||
//'use strict';
|
// code inspiré de https://github.com/callmenick/Memory
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extend object function
|
* Extend object function
|
||||||
*
|
*
|
||||||
@ -18,8 +17,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shuffle array function
|
* fonction qui va permettre de mélanger les cartes dans une array
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function shuffle(o) {
|
function shuffle(o) {
|
||||||
@ -28,8 +26,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Memory constructor
|
* Constructeur du Memory
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function Memory( options, level, nbcase, nbPartie ) {
|
function Memory( options, level, nbcase, nbPartie ) {
|
||||||
@ -41,8 +38,7 @@
|
|||||||
/**
|
/**
|
||||||
* Memory _init - initialise Memory
|
* Memory _init - initialise Memory
|
||||||
*
|
*
|
||||||
* Creates all the game content areas, adds the id's and classes, and gets
|
*Crée toutes les zones de contenu de jeu, ajoute les id et les classes, et se prépare pour la configuration de jeu.
|
||||||
* ready for game setup.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Memory.prototype._init = function(level,nbcase, nbPartie) {
|
Memory.prototype._init = function(level,nbcase, nbPartie) {
|
||||||
@ -71,20 +67,13 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Memory _setupGame - Sets up the game
|
* Memory _setupGame - on définit les paramètres du jeu
|
||||||
*
|
*
|
||||||
* We're caching all game related variables, and by default, displaying the
|
* Etats de la variable gameStates:
|
||||||
* meta info bar and start screen HTML.
|
|
||||||
*
|
*
|
||||||
* A NOTE ABOUT GAME STATES:
|
* 1 : par défaut,ça permet à l'utilisateur de choisir un niveau
|
||||||
*
|
* 2 : changer le niveau pendant que le joueur joue
|
||||||
* There are 4 game states in total, governed by the variable this.gameState.
|
* 3 : le jeu est fini
|
||||||
* Each game state allows for a certain series of functions to be performed.
|
|
||||||
* The gameStates are as follows:
|
|
||||||
*
|
|
||||||
* 1 : default, allows user to choose level
|
|
||||||
* 2 : set when user chooses level, and game is in play
|
|
||||||
* 3 : game is finished
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Memory.prototype._setupGame = function(level, nbcase, nbPartie) {
|
Memory.prototype._setupGame = function(level, nbcase, nbPartie) {
|
||||||
@ -106,8 +95,7 @@
|
|||||||
/**
|
/**
|
||||||
* Memory _setupGameWrapper
|
* Memory _setupGameWrapper
|
||||||
*
|
*
|
||||||
* This function sets up the game wrapper, which is where the actual memory
|
*Cette fonction définit l'espace du jeu.
|
||||||
* tiles will reside and where all the game play happens.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Memory.prototype._setupGameWrapper = function(levelNode,nbcase,nbPartie) {
|
Memory.prototype._setupGameWrapper = function(levelNode,nbcase,nbPartie) {
|
||||||
@ -125,28 +113,21 @@
|
|||||||
/**
|
/**
|
||||||
* Memory _renderTiles
|
* Memory _renderTiles
|
||||||
*
|
*
|
||||||
* This renders the actual tiles with content. A few thing happen here:
|
* Dans cette fonction nous définissons le niveau et le nombre de carte enregistré dans la base.
|
||||||
*
|
* On y créer une array ou on y met les carte. Puis on utilise la fonction shuffle pour mélaner et donc ne pas avoir toutes les cartes à la suite.
|
||||||
* 1. Calculate grid X and Y based on user level selection
|
* Ensuite on affiche les cartes
|
||||||
* 2. Calculate num tiles
|
* Puis on déclenche le jeu.
|
||||||
* 3. Create new cards array based on level, and draw cards from original array
|
|
||||||
* 4. Shuffle the new cards array
|
|
||||||
* 5. Cards get distributed into tiles
|
|
||||||
* 6. gamePlay function gets triggered, taking care of all the game play action.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Memory.prototype._renderTiles = function(nbPartie,nbcase) {
|
Memory.prototype._renderTiles = function(nbPartie,nbcase) {
|
||||||
if(this.level == 1) {this.gridX = 2; this.gridY= 2; }
|
if(this.level == 1) {this.gridX = 2; this.gridY= 2; }
|
||||||
else if(this.level == 2) {this.gridX = 3; this.gridY= 2; }
|
else if(this.level == 2) {this.gridX = 3; this.gridY= 2; }
|
||||||
else { this.gridX = 2; this.gridY=4 ; }
|
else { this.gridX = 2; this.gridY=4 ; }
|
||||||
// this.gridY = this.gridX ;
|
|
||||||
this.numTiles = this.nbcase*2;
|
this.numTiles = this.nbcase*2;
|
||||||
this.halfNumTiles = this.numTiles/2;
|
this.halfNumTiles = this.numTiles/2;
|
||||||
if (this.cards.length < this.halfNumTiles) { console.log("pas assez de carte"); document.getElementById("mg__contents").innerHTML="<img height='80px' src='/imgs/sad.png'><h1>Pas assez de cartes enregistrées par le référent </h1>";}
|
if (this.cards.length < this.halfNumTiles) { console.log("pas assez de carte"); document.getElementById("mg__contents").innerHTML="<img height='80px' src='/imgs/sad.png'><h1>Pas assez de cartes enregistrées par le référent </h1>";}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
//this.halfNumTiles = this.gridX;
|
|
||||||
|
|
||||||
this.newCards = [];
|
this.newCards = [];
|
||||||
for ( var i = 0; i < this.halfNumTiles; i++ ) {
|
for ( var i = 0; i < this.halfNumTiles; i++ ) {
|
||||||
this.newCards.push(this.cards[i], this.cards[i]);
|
this.newCards.push(this.cards[i], this.cards[i]);
|
||||||
@ -163,13 +144,7 @@
|
|||||||
<div class="mg__tile--inner" data-id="' + this.newCards[i]["id"] + '">\
|
<div class="mg__tile--inner" data-id="' + this.newCards[i]["id"] + '">\
|
||||||
<span class="mg__tile--outside"></span>\
|
<span class="mg__tile--outside"></span>\
|
||||||
<span class="mg__tile--inside" style="background-image:url(' + this.newCards[i]["img"] + ');"></span>';
|
<span class="mg__tile--inside" style="background-image:url(' + this.newCards[i]["img"] + ');"></span>';
|
||||||
this.tilesHTML +='</div>';
|
this.tilesHTML +='</div></div>';
|
||||||
|
|
||||||
|
|
||||||
/* if(this.level == 1 && n == 2){
|
|
||||||
this.tilesHTML +="</tr><tr>";
|
|
||||||
}*/
|
|
||||||
this.tilesHTML +="</div>";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.gameContents.innerHTML = this.tilesHTML;
|
this.gameContents.innerHTML = this.tilesHTML;
|
||||||
@ -181,10 +156,8 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Memory _gamePlay
|
* Memory _gamePlay
|
||||||
*
|
*Maintenant que tout le HTML est mis en place, le jeu est prêt à être joué.
|
||||||
* Now that all the HTML is set up, the game is ready to be played. In this
|
*Dans cette fonction, avec une boucle on ajoute les "tiles" avec la fonction gamePlayEvents.
|
||||||
* function, we loop through all the tiles (goverend by the .mg__tile--inner)
|
|
||||||
* class, and for each tile, we run the _gamePlayEvents function.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Memory.prototype._gamePlay = function(levelNode,nbPartie,nbcase) {
|
Memory.prototype._gamePlay = function(levelNode,nbPartie,nbcase) {
|
||||||
@ -197,13 +170,8 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Memory _gamePlayEvents
|
* Memory _gamePlayEvents
|
||||||
*
|
*Cette fonction prend en charge les «événements», qui est essentiellement le clic sur les "tiles".
|
||||||
* This function takes care of the "events", which is basically the clicking
|
*Les "titles" sont verifié, savoir si ils sont retourné ou non et vérifier si les deux cartes retourné sont identiques.
|
||||||
* of tiles. Tiles need to be checked if flipped or not, flipped if possible,
|
|
||||||
* and if zero, one, or two cards are flipped. When two cards are flipped, we
|
|
||||||
* have to check for matches and mismatches. The _gameCardsMatch and
|
|
||||||
* _gameCardsMismatch functions perform two separate sets of functions, and are
|
|
||||||
* thus separated below.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Memory.prototype._gamePlayEvents = function(tile,levelNode,nbPartie,nbcase) {
|
Memory.prototype._gamePlayEvents = function(tile,levelNode,nbPartie,nbcase) {
|
||||||
@ -248,13 +216,13 @@
|
|||||||
// cache this
|
// cache this
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// add correct class
|
// on ajoute la classe correct
|
||||||
window.setTimeout( function(){
|
window.setTimeout( function(){
|
||||||
self.card1.classList.add("correct");
|
self.card1.classList.add("correct");
|
||||||
self.card2.classList.add("correct");
|
self.card2.classList.add("correct");
|
||||||
}, 300 );
|
}, 300 );
|
||||||
|
|
||||||
// remove correct class and reset vars
|
// On supprime la classe correct et on réinitialiser les vars
|
||||||
window.setTimeout( function(){
|
window.setTimeout( function(){
|
||||||
self.card1.classList.remove("correct");
|
self.card1.classList.remove("correct");
|
||||||
self.card2.classList.remove("correct");
|
self.card2.classList.remove("correct");
|
||||||
@ -265,7 +233,7 @@
|
|||||||
}
|
}
|
||||||
}, 500 );
|
}, 500 );
|
||||||
|
|
||||||
// plus one on the move counter
|
// on incrémente les compteurs
|
||||||
this._gameCounterPlusOne();
|
this._gameCounterPlusOne();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -339,42 +307,26 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Memoray _winGame
|
* Memoray _winGame
|
||||||
*
|
* fonction lorsque l'utilisateur à gagné.
|
||||||
* You won the game! This function runs the "onGameEnd" callback, which by
|
|
||||||
* default clears the game div entirely and shows a "play again" button.
|
|
||||||
*/
|
*/
|
||||||
/*
|
|
||||||
Memory.prototype._winGame = function() {
|
|
||||||
var self = this;
|
|
||||||
if (this.options.onGameEnd() === false) {
|
|
||||||
this._clearGame();
|
|
||||||
|
|
||||||
alert("zoro 2");
|
|
||||||
document.location.href="/memo";
|
|
||||||
self.resetGame();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// run callback
|
|
||||||
this.options.onGameEnd();
|
|
||||||
//alert("coucou");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
Memory.prototype._winGame = function(levelNode, nbPartie, nbcase) {
|
Memory.prototype._winGame = function(levelNode, nbPartie, nbcase) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.level = levelNode;
|
this.level = levelNode;
|
||||||
partieRealise = partieRealise + 1 ;
|
partieRealise = partieRealise + 1 ;
|
||||||
|
|
||||||
if (partieRealise != nbPartie){
|
if (partieRealise != nbPartie){
|
||||||
|
// Pour gagner une coupe il y a un certain nombre de partie à faire
|
||||||
this._clearGame();
|
this._clearGame();
|
||||||
this._init(this.level, nbcase, nbPartie);
|
this._init(this.level, nbcase, nbPartie);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (this.options.onGameEnd() === false) {
|
else if (this.options.onGameEnd() === false) {
|
||||||
|
// si il a fini le jeu on le félicite et on lui rajoute aussi des feu d'artifice.
|
||||||
this._clearGame();
|
this._clearGame();
|
||||||
firework();
|
firework();
|
||||||
//firework2();
|
//firework2();
|
||||||
|
// on affiche la bonne coupe en fonction du niveau choisi
|
||||||
if(levelNode == 1){this.gameMessages.innerHTML = '<img style="height: 270px;" src="/imgs/trophees/bronze.png"><br>\
|
if(levelNode == 1){this.gameMessages.innerHTML = '<img style="height: 270px;" src="/imgs/trophees/bronze.png"><br>\
|
||||||
<button id="mg__onend--restart" class="mg__button"><span class="icon-spinner11"></span></button>';}
|
<button id="mg__onend--restart" class="mg__button"><span class="icon-spinner11"></span></button>';}
|
||||||
|
|
||||||
@ -387,14 +339,14 @@ Memory.prototype._winGame = function(levelNode, nbPartie, nbcase) {
|
|||||||
else
|
else
|
||||||
{ this.gameMessages.innerHTML = '<h2 class="mg__onend--heading"><span class="icon-trophy"></span></h2>\
|
{ this.gameMessages.innerHTML = '<h2 class="mg__onend--heading"><span class="icon-trophy"></span></h2>\
|
||||||
<button id="mg__onend--restart" class="mg__button"><span class="icon-spinner11"></span></button>';}
|
<button id="mg__onend--restart" class="mg__button"><span class="icon-spinner11"></span></button>';}
|
||||||
|
// en ajax on incrémente les coupes de l'utilisateur
|
||||||
var r = new XMLHttpRequest();
|
var r = new XMLHttpRequest();
|
||||||
r.open("GET", "/setRecords" + "/" + levelNode, true);
|
r.open("GET", "/setRecords" + "/" + levelNode, true);
|
||||||
r.send();
|
r.send();
|
||||||
|
|
||||||
//http://translate.google.com/translate_tts?ie=UTF-8&q=bravo%2C%20tu%20as%20gagn%C3%A9&tl=fr
|
//http://translate.google.com/translate_tts?ie=UTF-8&q=bravo%2C%20tu%20as%20gagn%C3%A9&tl=fr
|
||||||
//http://translate.google.com/translate_tts?ie=UTF-8&q=bravo%2C%20tu%20as%20gagn%C3%A9&tl=fr&total=1&idx=0&textlen=18&client=t&prev=input
|
//http://translate.google.com/translate_tts?ie=UTF-8&q=bravo%2C%20tu%20as%20gagn%C3%A9&tl=fr&total=1&idx=0&textlen=18&client=t&prev=input
|
||||||
|
//une petite voix dit à l'utilisateur qu'il a gagné
|
||||||
var audio = new Audio();
|
var audio = new Audio();
|
||||||
var texte = 'http://translate.google.com/translate_tts?ie=UTF-8&q=bravo%2C%20tu%20as%20gagn%C3%A9&tl=fr';
|
var texte = 'http://translate.google.com/translate_tts?ie=UTF-8&q=bravo%2C%20tu%20as%20gagn%C3%A9&tl=fr';
|
||||||
audio.src =texte;
|
audio.src =texte;
|
||||||
|
Reference in New Issue
Block a user