File indexing completed on 2024-05-12 03:42:49
0001 /* GCompris - left_right_click.js 0002 * 0003 * SPDX-FileCopyrightText: 2022 Samarth Raj <mailforsamarth@gmail.com> 0004 * SPDX-FileCopyrightText: 2022 Timothée Giet <animtim@gmail.com> 0005 * SPDX-License-Identifier: GPL-3.0-or-later 0006 * 0007 */ 0008 .pragma library 0009 .import QtQuick 2.12 as Quick 0010 .import "../../core/core.js" as Core 0011 0012 var items; 0013 var numberOfLevel = 3; 0014 var animalCountForBonus = 0; 0015 var cardsToDisplay; 0016 // different number of cards to display per level 0017 var levelDifficulty = [5, 7, 10] 0018 var imgSrc = [ 0019 "qrc:/gcompris/src/activities/left_right_click/resource/fish.svg", 0020 "qrc:/gcompris/src/activities/left_right_click/resource/monkey.svg" 0021 ] 0022 var Position = { 0023 left: 0, 0024 right: 1 0025 } 0026 0027 function start(items_) { 0028 items = items_ 0029 items.currentLevel = Core.getInitialLevel(numberOfLevel); 0030 initLevel() 0031 } 0032 0033 function stop() { 0034 } 0035 0036 function initLevel() { 0037 items.animalListModel.clear(); 0038 var animalArray = new Array(); 0039 cardsToDisplay = levelDifficulty[items.currentLevel]; 0040 items.animalCount = (cardsToDisplay / 2) * 3; 0041 var animalCardLeft = { 0042 "animalIdentifier": Position.left, 0043 "leftArea": items.leftArea, 0044 "rightArea": items.rightArea, 0045 "animalInvisible": false, 0046 "imageSource": imgSrc[0] 0047 } 0048 var animalCardRight = { 0049 "animalIdentifier": Position.right, 0050 "leftArea": items.leftArea, 0051 "rightArea": items.rightArea, 0052 "animalInvisible": false, 0053 "imageSource": imgSrc[1] 0054 } 0055 // this is invisible card so giving any value won't be of any use. 0056 var animalCardInvisible = { 0057 "animalIdentifier": Position.right, 0058 "leftArea": items.leftArea, 0059 "rightArea": items.rightArea, 0060 "animalInvisible": true, 0061 "imageSource": imgSrc[1] 0062 } 0063 for(var i = 0; i < Math.floor(cardsToDisplay/2); i++) { 0064 // with every iteration we insert 3 types of cards, invisible card to create a random spacing between the other two cards. 0065 animalArray.push(animalCardRight); 0066 animalArray.push(animalCardLeft); 0067 animalArray.push(animalCardInvisible); 0068 } 0069 // more right cards on level 1 than left cards. 0070 if(items.currentLevel === 0) { 0071 animalArray.push(animalCardLeft); 0072 } 0073 // more left cards on level 2 than right cards. 0074 else if(items.currentLevel === 1) { 0075 animalArray.push(animalCardRight); 0076 } 0077 Core.shuffle(animalArray); 0078 for(var i = 0; i < animalArray.length; i++) { 0079 items.animalListModel.append(animalArray[i]); 0080 } 0081 animalCountForBonus = 0; 0082 } 0083 0084 function nextLevel() { 0085 items.currentLevel = Core.getNextLevel(items.currentLevel, numberOfLevel); 0086 initLevel(); 0087 } 0088 0089 function previousLevel() { 0090 items.currentLevel = Core.getPreviousLevel(items.currentLevel, numberOfLevel); 0091 initLevel(); 0092 } 0093 0094 function incrementCounter() { 0095 animalCountForBonus++; 0096 if(animalCountForBonus % cardsToDisplay === 0) { 0097 items.bonus.good("lion"); 0098 } 0099 } 0100 0101 function playWrongClickSound() { 0102 items.audioEffects.play('qrc:/gcompris/src/core/resource/sounds/crash.wav') 0103 }