diff --git a/SRC/app/Http/Controllers/GameController.php b/SRC/app/Http/Controllers/GameController.php index 680166c..ee7242e 100755 --- a/SRC/app/Http/Controllers/GameController.php +++ b/SRC/app/Http/Controllers/GameController.php @@ -37,13 +37,15 @@ class GameController extends Controller { $oes = $configjeu->oeuvres; $params = json_decode($configjeu->parametres); $bloc = $params->{"m".$niveau}; + $nbParie = $params->{"mt"}; } else { + $nbParie = 1; $oes = Oeuvre::orderByRaw("RAND()")->take(8)->get(); if($niveau == 1) {$bloc = 2;} elseif($niveau == 2){$bloc = 3;} else {$bloc = 4;} } - return view('frontend/memo', ['oeuvres' => $oes, 'niveau' => $niveau, 'nbBloc'=>$bloc]); + return view('frontend/memo', ['oeuvres' => $oes, 'niveau' => $niveau, 'nbBloc'=>$bloc, 'nbPartie'=> $nbParie]); } @@ -77,16 +79,16 @@ class GameController extends Controller { $cookie = Cookie::get('trophee'); $values = json_decode($cookie); - + if (!is_array($values)) $values = [0, 0, 0]; switch ($idTrophee) { - + case '1': $values[0] += 1; break; - + case '2': $values[1] += 1; break; @@ -94,7 +96,7 @@ class GameController extends Controller { case '3': $values[2] += 1; break; - + default: break; } diff --git a/SRC/public/js/memory.js b/SRC/public/js/memory.js index 1ba376e..5da7255 100755 --- a/SRC/public/js/memory.js +++ b/SRC/public/js/memory.js @@ -7,7 +7,7 @@ * */ - + var partieRealise = 0; function extend( a, b ) { for( var key in b ) { if( b.hasOwnProperty( key ) ) { @@ -32,12 +32,10 @@ * */ - function Memory( options, level, nbcase ) { - //console.log(nbcase); - //console.log("bob"); + function Memory( options, level, nbcase, nbPartie ) { this.options = extend( {}, this.options ); extend( this.options, options ); - this._init(level, nbcase); + this._init(level, nbcase, nbPartie); } /** @@ -47,7 +45,8 @@ * ready for game setup. */ - Memory.prototype._init = function(level,nbcase) { + Memory.prototype._init = function(level,nbcase, nbPartie) { + this.game = document.createElement("div"); this.game.id = "mg"; this.game.className = "mg"; @@ -68,7 +67,7 @@ this.gameMessages.id = "mg__onend"; this.gameMessages.className = "mg__onend"; - this._setupGame(level,nbcase); + this._setupGame(level,nbcase, nbPartie); }; /** @@ -88,7 +87,7 @@ * 3 : game is finished */ - Memory.prototype._setupGame = function(level, nbcase) { + Memory.prototype._setupGame = function(level, nbcase, nbPartie) { var self = this; this.gameState = 1; this.cards = shuffle(this.options.cards); @@ -101,7 +100,7 @@ this.flippedTiles = 0; this.chosenLevel = ""; this.numMoves = 0; - this._setupGameWrapper(level, nbcase); + this._setupGameWrapper(level, nbcase, nbPartie); } /** @@ -111,7 +110,7 @@ * tiles will reside and where all the game play happens. */ - Memory.prototype._setupGameWrapper = function(levelNode,nbcase) { + Memory.prototype._setupGameWrapper = function(levelNode,nbcase,nbPartie) { this.nbcase = nbcase; this.level = levelNode; this.gameContents.className = "mg__contents mg__level-"+this.level; @@ -119,7 +118,7 @@ this.chosenLevel = this.level; - this._renderTiles(); + this._renderTiles(nbPartie,nbcase); }; @@ -136,7 +135,7 @@ * 6. gamePlay function gets triggered, taking care of all the game play action. */ - Memory.prototype._renderTiles = function() { + Memory.prototype._renderTiles = function(nbPartie,nbcase) { if(this.level == 1) {this.gridX = 2; this.gridY= 2; } else if(this.level == 2) {this.gridX = 3; this.gridY= 2; } else { this.gridX = 2; this.gridY=4 ; } @@ -176,7 +175,7 @@ this.gameContents.innerHTML = this.tilesHTML; this.gameState = 2; this.options.onGameStart(); - this._gamePlay(this.level); + this._gamePlay(this.level, nbPartie, nbcase); } } @@ -188,11 +187,11 @@ * class, and for each tile, we run the _gamePlayEvents function. */ - Memory.prototype._gamePlay = function(levelNode) { + Memory.prototype._gamePlay = function(levelNode,nbPartie,nbcase) { var tiles = document.querySelectorAll(".mg__tile--inner"); for (var i = 0, len = tiles.length; i < len; i++) { var tile = tiles[i]; - this._gamePlayEvents(tile,levelNode); + this._gamePlayEvents(tile,levelNode,nbPartie,nbcase); }; }; @@ -207,7 +206,7 @@ * thus separated below. */ - Memory.prototype._gamePlayEvents = function(tile,levelNode) { + Memory.prototype._gamePlayEvents = function(tile,levelNode,nbPartie,nbcase) { var self = this; tile.addEventListener( "click", function(e) { if (!this.classList.contains("flipped")) { @@ -222,7 +221,7 @@ self.card2id = this.getAttribute("data-id"); self.card2flipped = true; if ( self.card1id == self.card2id ) { - self._gameCardsMatch(levelNode); + self._gameCardsMatch(levelNode,nbPartie,nbcase); } else { self._gameCardsMismatch(); } @@ -245,7 +244,7 @@ "document"in self&&("classList"in document.createElement("_")?!function(){"use strict";var a=document.createElement("_");if(a.classList.add("c1","c2"),!a.classList.contains("c2")){var b=function(a){var b=DOMTokenList.prototype[a];DOMTokenList.prototype[a]=function(a){var c,d=arguments.length;for(c=0;d>c;c++)a=arguments[c],b.call(this,a)}};b("add"),b("remove")}if(a.classList.toggle("c3",!1),a.classList.contains("c3")){var c=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(a,b){return 1 in arguments&&!this.contains(a)==!b?b:c.call(this,a)}}a=null}():!function(a){"use strict";if("Element"in a){var b="classList",c="prototype",d=a.Element[c],e=Object,f=String[c].trim||function(){return this.replace(/^\s+|\s+$/g,"")},g=Array[c].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1},h=function(a,b){this.name=a,this.code=DOMException[a],this.message=b},i=function(a,b){if(""===b)throw new h("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(b))throw new h("INVALID_CHARACTER_ERR","String contains an invalid character");return g.call(a,b)},j=function(a){for(var b=f.call(a.getAttribute("class")||""),c=b?b.split(/\s+/):[],d=0,e=c.length;e>d;d++)this.push(c[d]);this._updateClassName=function(){a.setAttribute("class",this.toString())}},k=j[c]=[],l=function(){return new j(this)};if(h[c]=Error[c],k.item=function(a){return this[a]||null},k.contains=function(a){return a+="",-1!==i(this,a)},k.add=function(){var a,b=arguments,c=0,d=b.length,e=!1;do a=b[c]+"",-1===i(this,a)&&(this.push(a),e=!0);while(++c