diff --git a/src/activities/memory-enumerate/resource/1/Data.qml b/src/activities/memory-enumerate/resource/1/Data.qml index 457ebc6fa..e93a1f90f 100644 --- a/src/activities/memory-enumerate/resource/1/Data.qml +++ b/src/activities/memory-enumerate/resource/1/Data.qml @@ -1,65 +1,57 @@ /* GCompris - Data.qml * * Copyright (C) 2020 Deepak Kumar * * Authors: * Deepak Kumar * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ import GCompris 1.0 import GCompris 1.0 as GCompris Data { objective: qsTr("Match the numbers up to 2.") difficulty: 1 property string url: "qrc:/gcompris/src/activities/memory-enumerate/resource/" property var texts: [ - ["", 1], - ["", 2], ["", 1], ["", 2] ] property var images: [ [url + 'math_1.svg', ''], [url + 'math_2.svg', ''], - [url + 'math_1.svg', ''], - [url + 'math_2.svg', ''] ] property var sounds: [ - ["", - GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0031.$CA")], - ["", - GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0032.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0031.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0032.$CA")] ] data: [ { // Level 1 "columns": 2, "rows": 2, - "texts": texts.slice(0, 4), - "images": images.slice(0, 4), - "sounds": sounds.slice(0, 4) + "texts": texts.slice(0, 2), + "images": images.slice(0, 2), + "sounds": sounds.slice(0, 2) } ] } diff --git a/src/activities/memory-enumerate/resource/2/Data.qml b/src/activities/memory-enumerate/resource/2/Data.qml index db3dbd979..2d83e081b 100644 --- a/src/activities/memory-enumerate/resource/2/Data.qml +++ b/src/activities/memory-enumerate/resource/2/Data.qml @@ -1,66 +1,62 @@ /* GCompris - Data.qml * * Copyright (C) 2020 Deepak Kumar * * Authors: * Deepak Kumar * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ import GCompris 1.0 import GCompris 1.0 as GCompris Data { objective: qsTr("Match the numbers up to 3.") difficulty: 1 property string url: "qrc:/gcompris/src/activities/memory-enumerate/resource/" property var texts: [ ["", 1], ["", 2], - ["", 2], ["", 3] ] property var images: [ [url + 'math_1.svg', ''], [url + 'math_2.svg', ''], - [url + 'math_2.svg', ''], [url + 'math_3.svg', ''] ] property var sounds: [ ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0031.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0032.$CA")], - ["", - GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0032.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0033.$CA")] ] data: [ { // Level 1 - "columns": 2, + "columns": 3, "rows": 2, "texts": texts.slice(0, 4), "images": images.slice(0, 4), "sounds": sounds.slice(0, 4) } ] } diff --git a/src/activities/memory-enumerate/resource/3/Data.qml b/src/activities/memory-enumerate/resource/3/Data.qml index 36e03d6b9..adadd696f 100644 --- a/src/activities/memory-enumerate/resource/3/Data.qml +++ b/src/activities/memory-enumerate/resource/3/Data.qml @@ -1,65 +1,65 @@ /* GCompris - Data.qml * * Copyright (C) 2020 Deepak Kumar * * Authors: * Deepak Kumar * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ import GCompris 1.0 import GCompris 1.0 as GCompris Data { objective: qsTr("Match the numbers up to 4.") difficulty: 1 property string url: "qrc:/gcompris/src/activities/memory-enumerate/resource/" property var texts: [ ["", 1], ["", 2], ["", 3], ["", 4] ] property var images: [ [url + 'math_1.svg', ''], [url + 'math_2.svg', ''], [url + 'math_3.svg', ''], [url + 'math_4.svg', ''] ] property var sounds: [ ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0031.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0032.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0033.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0034.$CA")], ] data: [ { // Level 1 - "columns": 2, + "columns": 4, "rows": 2, "texts": texts.slice(0, 4), "images": images.slice(0, 4), "sounds": sounds.slice(0, 4) } ] } diff --git a/src/activities/memory-enumerate/resource/4/Data.qml b/src/activities/memory-enumerate/resource/4/Data.qml index 40010fc94..29a104532 100644 --- a/src/activities/memory-enumerate/resource/4/Data.qml +++ b/src/activities/memory-enumerate/resource/4/Data.qml @@ -1,73 +1,73 @@ /* GCompris - Data.qml * * Copyright (C) 2020 Deepak Kumar * * Authors: * Deepak Kumar * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ import GCompris 1.0 import GCompris 1.0 as GCompris Data { objective: qsTr("Match the numbers up to 5.") difficulty: 2 property string url: "qrc:/gcompris/src/activities/memory-enumerate/resource/" property var texts: [ ["", 0], ["", 1], ["", 2], ["", 3], ["", 4], ["", 5] ] property var images: [ [url + 'math_0.svg', ''], [url + 'math_1.svg', ''], [url + 'math_2.svg', ''], [url + 'math_3.svg', ''], [url + 'math_4.svg', ''], [url + 'math_5.svg', ''], ] property var sounds: [ ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0030.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0031.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0032.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0033.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0034.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0035.$CA")] ] data: [ { // Level 1 - "columns": 3, - "rows": 2, + "columns": 4, + "rows": 3, "texts": texts.slice(0, 6), "images": images.slice(0, 6), "sounds": sounds.slice(0, 6) } ] } diff --git a/src/activities/memory-enumerate/resource/5/Data.qml b/src/activities/memory-enumerate/resource/5/Data.qml index 15599c328..c71bc1e9c 100644 --- a/src/activities/memory-enumerate/resource/5/Data.qml +++ b/src/activities/memory-enumerate/resource/5/Data.qml @@ -1,79 +1,79 @@ /* GCompris - Data.qml * * Copyright (C) 2020 Deepak Kumar * * Authors: * Deepak Kumar * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ import GCompris 1.0 import GCompris 1.0 as GCompris Data { objective: qsTr("Match the numbers up to 6.") difficulty: 3 property string url: "qrc:/gcompris/src/activities/memory-enumerate/resource/" property var texts: [ ["", 0], ["", 1], ["", 2], ["", 3], ["", 4], ["", 5], ["", 6], ] property var images: [ [url + 'math_0.svg', ''], [url + 'math_1.svg', ''], [url + 'math_2.svg', ''], [url + 'math_3.svg', ''], [url + 'math_4.svg', ''], [url + 'math_5.svg', ''], [url + 'math_6.svg', ''], ] property var sounds: [ ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0030.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0031.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0032.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0033.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0034.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0035.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0036.$CA")] ] data: [ { // Level 1 - "columns": 3, - "rows": 2, + "columns": 4, + "rows": 3, "texts": texts.slice(0, 7), "images": images.slice(0, 7), "sounds": sounds.slice(0, 7) } ] } diff --git a/src/activities/memory-enumerate/resource/6/Data.qml b/src/activities/memory-enumerate/resource/6/Data.qml index 81f89f115..f233a3f88 100644 --- a/src/activities/memory-enumerate/resource/6/Data.qml +++ b/src/activities/memory-enumerate/resource/6/Data.qml @@ -1,81 +1,81 @@ /* GCompris - Data.qml * * Copyright (C) 2020 Deepak Kumar * * Authors: * Deepak Kumar * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ import GCompris 1.0 import GCompris 1.0 as GCompris Data { objective: qsTr("Match the numbers up to 7.") difficulty: 3 property string url: "qrc:/gcompris/src/activities/memory-enumerate/resource/" property var texts: [ ["", 0], ["", 1], ["", 2], ["", 3], ["", 4], ["", 5], ["", 6], ["", 7], ] property var images: [ [url + 'math_0.svg', ''], [url + 'math_1.svg', ''], [url + 'math_2.svg', ''], [url + 'math_3.svg', ''], [url + 'math_4.svg', ''], [url + 'math_5.svg', ''], [url + 'math_6.svg', ''], [url + 'math_7.svg', ''] ] property var sounds: [ ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0030.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0031.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0032.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0033.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0034.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0035.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0036.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0037.$CA")] ] data: [ { // Level 1 "columns": 4, - "rows": 2, + "rows": 4, "texts": texts.slice(0, 8), "images": images.slice(0, 8), "sounds": sounds.slice(0, 8) } ] } diff --git a/src/activities/memory-enumerate/resource/7/Data.qml b/src/activities/memory-enumerate/resource/7/Data.qml index b952bcd57..34528bfd4 100644 --- a/src/activities/memory-enumerate/resource/7/Data.qml +++ b/src/activities/memory-enumerate/resource/7/Data.qml @@ -1,85 +1,85 @@ /* GCompris - Data.qml * * Copyright (C) 2020 Deepak Kumar * * Authors: * Deepak Kumar * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ import GCompris 1.0 import GCompris 1.0 as GCompris Data { objective: qsTr("Match the numbers up to 8.") difficulty: 3 property string url: "qrc:/gcompris/src/activities/memory-enumerate/resource/" property var texts: [ ["", 0], ["", 1], ["", 2], ["", 3], ["", 4], ["", 5], ["", 6], ["", 7], ["", 8] ] property var images: [ [url + 'math_0.svg', ''], [url + 'math_1.svg', ''], [url + 'math_2.svg', ''], [url + 'math_3.svg', ''], [url + 'math_4.svg', ''], [url + 'math_5.svg', ''], [url + 'math_6.svg', ''], [url + 'math_7.svg', ''], [url + 'math_8.svg', ''], ] property var sounds: [ ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0030.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0031.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0032.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0033.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0034.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0035.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0036.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0037.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0038.$CA")] ] data: [ { // Level 1 "columns": 4, - "rows": 2, + "rows": 4, "texts": texts.slice(0, 9), "images": images.slice(0, 9), "sounds": sounds.slice(0, 9) } ] } diff --git a/src/activities/memory-enumerate/resource/8/Data.qml b/src/activities/memory-enumerate/resource/8/Data.qml index 2868bc28c..28d354125 100644 --- a/src/activities/memory-enumerate/resource/8/Data.qml +++ b/src/activities/memory-enumerate/resource/8/Data.qml @@ -1,89 +1,89 @@ /* GCompris - Data.qml * * Copyright (C) 2020 Deepak Kumar * * Authors: * Deepak Kumar * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ import GCompris 1.0 import GCompris 1.0 as GCompris Data { objective: qsTr("Match the numbers up to 9.") difficulty: 3 property string url: "qrc:/gcompris/src/activities/memory-enumerate/resource/" property var texts: [ ["", 0], ["", 1], ["", 2], ["", 3], ["", 4], ["", 5], ["", 6], ["", 7], ["", 8], ["", 9] ] property var images: [ [url + 'math_0.svg', ''], [url + 'math_1.svg', ''], [url + 'math_2.svg', ''], [url + 'math_3.svg', ''], [url + 'math_4.svg', ''], [url + 'math_5.svg', ''], [url + 'math_6.svg', ''], [url + 'math_7.svg', ''], [url + 'math_8.svg', ''], [url + 'math_9.svg', ''] ] property var sounds: [ ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0030.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0031.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0032.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0033.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0034.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0035.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0036.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0037.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0038.$CA")], ["", GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/U0039.$CA")], ] data: [ { // Level 1 "columns": 5, - "rows": 2, + "rows": 4, "texts": texts.slice(0, 10), "images": images.slice(0, 10), "sounds": sounds.slice(0, 10) } ] } diff --git a/src/activities/memory/memory.js b/src/activities/memory/memory.js index 6da138d77..270adedfe 100644 --- a/src/activities/memory/memory.js +++ b/src/activities/memory/memory.js @@ -1,264 +1,264 @@ /* gcompris - memory.js * * Copyright (C) 2014 JB BUTET * * Authors: * Bruno Coudoin (GTK+ version) * JB BUTET (Qt Quick port) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ .pragma library .import QtQuick 2.6 as Quick .import "qrc:/gcompris/src/core/core.js" as Core var url = "qrc:/gcompris/src/activities/memory/resource/" var items var currentLevel var numberOfLevel var nbOfPair var cardLeft var cardList function start(items_) { items = items_ currentLevel = 0 numberOfLevel = items.levels.length initLevel() } function stop() { } function initLevel() { items.bar.level = currentLevel + 1 items.containerModel.clear() items.playQueue = [] items.tuxTurn = false items.selectionCount = 0 items.blockClicks = false // compute the number of cards var columns = items.levels[currentLevel].columns var rows = items.levels[currentLevel].rows var images = items.levels[currentLevel].images var sounds = items.levels[currentLevel].sounds var texts = items.levels[currentLevel].texts items.columns = columns items.rows = rows nbOfPair = rows * columns / 2 cardLeft = nbOfPair * 2 // Check the provided dataset has enough data var maxData = Math.max( images ? images.length : 0, sounds ? sounds.length : 0, texts ? texts.length : 0) - if(rows * columns > maxData) { + if(rows * columns > maxData * 2) { console.log("ERROR: Memory dataset does not have enough data pairs at level ", currentLevel + 1) return } // Create a list of indexes for the shuffling // This way we can keep the 3 lists in sync var shuffleIds = [] for(var i = 0; i < maxData; ++i) { shuffleIds.push(i) } Core.shuffle(shuffleIds) // place randomly a level-defined number of pairs cardList = [] for(var ix = 0; ix < nbOfPair; ++ix) { // select a random item for(var j = 0; j < 2; ++j) { cardList.push( { image: images ? images[shuffleIds[ix]][j] : "", sound: sounds ? sounds[shuffleIds[ix]][j] : "", text: texts ? texts[shuffleIds[ix]][j] : "", matchCode: ix, back: url + "backcard.svg", emptyCard: url + "emptycard.svg" } ) } } cardList = Core.shuffle(cardList) // fill the model for(i = 0; i < cardList.length; ++i) { items.containerModel.append( { pairData_: cardList[i] } ) } items.tuxScore = 0 items.playerScore = 0 } // Return a pair of cards that have already been shown function getShownPair() { for(var i = 0; i < nbOfPair * 2; ++i) { var cardItem1 = items.grid.getItemAtIndex(i) for(var j = 0; j < nbOfPair * 2; ++j) { var cardItem2 = items.grid.getItemAtIndex(j) if(i != j && !cardItem1.isFound && cardItem1.isShown && !cardItem2.isFound && cardItem2.isShown && (cardItem1.pairData.matchCode === cardItem2.pairData.matchCode) ) { return [cardItem1, cardItem2] } } } return } // Calc randomly is Tux is a good player // Return true if Tux should play correctly function getRandomTuxIsGood() { return Math.random() * numberOfLevel < currentLevel } function chooseCard() { // Tux looks in the shown card to make his choice if(getRandomTuxIsGood()) { var shownPair = getShownPair() if(shownPair) { if(shownPair[0].isBack) { return shownPair[0] } else { return shownPair[1] } } } // If no pairs shown select a random card var listCardNonReturned = [] for(var i = 0; i < cardList.length; ++i) { if (items.grid.getItemAtIndex(i).isFound == false && items.grid.getItemAtIndex(i).isBack) listCardNonReturned.push(items.grid.getItemAtIndex(i)) } //select randomly a card in it return listCardNonReturned[Math.floor(Math.random() * listCardNonReturned.length)] } function reverseCardsIfNeeded() { if(items.playQueue.length >= 2) { items.selectionCount = 0 var item1 = items.playQueue.shift() var item2 = items.playQueue.shift() var tuxTurn = item1.tuxTurn if (item1.card.pairData.matchCode === item2.card.pairData.matchCode) { // the 2 cards are the same item1.card.isBack = false // stay faced item1.card.isFound = true // signal for hidden state item2.card.isBack = false item2.card.isFound = true cardLeft = cardLeft - 2 if (tuxTurn) items.tuxScore++ else items.playerScore++ if(cardLeft === 0) { // no more cards in the level if(items.withTux) { if (items.tuxScore < items.playerScore) { youWon() } else { youLoose() } } else { youWon() } } else { if(items.withTux && items.tuxTurn) { tuxPlay() } else { items.audioEffects.play('qrc:/gcompris/src/core/resource/sounds/win.wav') } } } else { // pictures clicked are not the same item1.card.isBack = true item2.card.isBack = true if(items.withTux) items.tuxTurn = !items.tuxTurn // The user lost, it's Tux turn if (items.withTux && items.tuxTurn) { tuxPlay() } } } } function tuxPlay() { // choose a card chooseCard().selected() } function youWon() { items.blockClicks = true items.bonus.good("flower") } function youLoose(){ items.blockClicks = true items.bonus.bad("flower") if (items.withTux) { initLevel() } } function nextLevel() { if(numberOfLevel <= ++currentLevel) { currentLevel = 0 } initLevel(); } function previousLevel() { if(--currentLevel < 0) { currentLevel = numberOfLevel - 1 } initLevel(); } function dumpPlayQueue() { for(var i in items.playQueue) console.log(items.playQueue[i].card, items.playQueue[i].tuxTurn) } // Return true is we have enough to make a pair function addPlayQueue(card) { items.playQueue.push({'card': card, 'tuxTurn': items.tuxTurn}) return items.playQueue.length >= 2 }