diff --git a/src/activities/money/money.js b/src/activities/money/money.js index 6fa595941..2904ec096 100644 --- a/src/activities/money/money.js +++ b/src/activities/money/money.js @@ -1,262 +1,271 @@ /* GCompris - money.js * * Copyright (C) 2014 Bruno Coudoin * * Authors: * Bruno Coudoin (GTK+ version) * Bruno Coudoin (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 "qrc:/gcompris/src/core/core.js" as Core .import GCompris 1.0 as GCompris .import "moneyConstants.js" as Constants var url = "qrc:/gcompris/src/activities/money/resource/" // We create 3 prices categories to make the game more realistic. // List of images to use in the game (cheap objects) var currentLevel var numberOfLevel var dataset var items var centsMode var backMode var priceTotal function start(items_, datasetName) { items = items_ dataset = items.levels switch(datasetName) { case "WITHOUT_CENTS": centsMode = false backMode = false break case "WITH_CENTS": centsMode = true backMode = false break case "BACK_WITHOUT_CENTS": centsMode = false backMode = true break case "BACK_WITH_CENTS": centsMode = true backMode = true break } currentLevel = 0 numberOfLevel = dataset.length initLevel() } function stop() { } +function getCoinCount (pocket) { + var count = 0 + for(var i = 0; i < pocket.length; i++) { + if(pocket[i].val <= 2) + count++ + } + return count; +} + function initLevel() { items.bar.level = currentLevel + 1 items.answerModel.clear() items.pocketModel.clear() var data = dataset[currentLevel] - - items.pocketRows = (data.pocket.length > 12) ? 3 : 2 var pocket = Core.shuffle(data.pocket) + var coinCount = getCoinCount(pocket) + items.pocketRows = ((data.pocket.length - coinCount / 2) > 9) ? 3 : 2 for (var i in pocket) items.pocketModel.append(pocket[i]) // fill up the store in a random way var storeModel = new Array() priceTotal = Math.floor(data.minPrice + Math.random() * (data.maxPrice - data.minPrice)) var priceCounter = 0 for(var i = 0; i < data.numberOfItem; i++) { var price if(i < data.numberOfItem - 1) // Calc a random price for each item based on the previous prices price = Math.floor((centsMode ? 0 : 1) + Math.random() * (2 * (priceTotal - priceCounter) / data.numberOfItem)) else // Put the remaining missing price on the last item price = priceTotal - priceCounter var cents = 0 if(centsMode) { if(currentLevel === 0) cents += 0.10 + Math.floor(Math.random() * 9) / 10 else cents += 0.01 + Math.floor(Math.random() * 9) / 100 priceTotal += cents price += cents } var locale = GCompris.ApplicationSettings.locale if(locale == "system") { locale = Qt.locale().name == "C" ? "en_US" : Qt.locale().name } var priceText = Number(price).toLocaleCurrencyString(Qt.locale(locale)) if(!centsMode) { // Strip floating part priceText = priceText.replace((/.00/), "") } storeModel.push({img: getRandomObject(price), price: priceText}) priceCounter += price } items.store.model = storeModel if(!backMode) { items.instructions.text = qsTr("Click on the coins or paper money at the bottom of the screen to pay." + " If you want to remove a coin or note, click on it on the upper screen area.") } else { var tuxMoney switch(data.paid) { case 5: tuxMoney = [Constants.moneyItems.MONEY_PAPER_5E] break case 10: tuxMoney = [Constants.moneyItems.MONEY_PAPER_10E] break case 15: tuxMoney = [Constants.moneyItems.MONEY_PAPER_10E, Constants.moneyItems.MONEY_PAPER_5E] break case 20: tuxMoney = [Constants.moneyItems.MONEY_PAPER_20E] break case 25: tuxMoney = [Constants.moneyItems.MONEY_PAPER_20E, Constants.moneyItems.MONEY_PAPER_5E] break case 30: tuxMoney = [Constants.moneyItems.MONEY_PAPER_20E, Constants.moneyItems.MONEY_PAPER_10E] break case 40: tuxMoney = [Constants.moneyItems.MONEY_PAPER_20E, Constants.moneyItems.MONEY_PAPER_20E] break case 50: tuxMoney = [Constants.moneyItems.MONEY_PAPER_50E] break case 100: tuxMoney = [Constants.moneyItems.MONEY_PAPER_100E] break case 200: tuxMoney = [Constants.moneyItems.MONEY_PAPER_200E] break case 300: tuxMoney = [Constants.moneyItems.MONEY_PAPER_200E, Constants.moneyItems.MONEY_PAPER_100E] break case 400: tuxMoney = [Constants.moneyItems.MONEY_PAPER_200E, Constants.moneyItems.MONEY_PAPER_200E] break } items.tuxMoney.model = tuxMoney var tuxTotal = 0 for(var i=0; i < tuxMoney.length; i++) tuxTotal += tuxMoney[i].val var locale = GCompris.ApplicationSettings.locale if(locale == "system") { locale = Qt.locale().name == "C" ? "en_US" : Qt.locale().name } var priceText = Number(tuxTotal).toLocaleCurrencyString(Qt.locale(locale)) if(!centsMode) { // Strip floating part priceText = priceText.replace((/.00/), "") } /* The money sign is inserted based on the current locale */ items.instructions.text = qsTr("Tux just bought some items in your shop.\n" + "He gives you %1, please give back his change.") .arg(priceText) } //Keyboard reset items.itemIndex = -1 items.selectedArea = items.pocket } // Given a price return a random object function getRandomObject(price) { var list if(price < 5) list = Constants.cheapObjects else if(price < 10) list = Constants.normalObjects else list = Constants.expensiveObjects return list[Math.floor(Math.random() * list.length)] } function checkAnswer() { var paid = 0 for (var i = 0; i < items.answerModel.count; ++i) paid += items.answerModel.get(i).val paid = paid.toFixed(2) if(!backMode) { if(paid === priceTotal.toFixed(2)) items.bonus.good("flower") } else { if(paid === (dataset[currentLevel].paid - priceTotal).toFixed(2)) items.bonus.good("flower") } } function pay(index) { items.audioEffects.play(url + "money1.wav") // Add it to the anwser items.answerModel.append(items.pocketModel.get(index)) // Remove it from the pocket items.pocketModel.remove(index, 1) checkAnswer() } function unpay(index) { items.audioEffects.play(url + "money2.wav") // Add it to the pocket items.pocketModel.append(items.answerModel.get(index)) // Remove it from the Answer items.answerModel.remove(index, 1) checkAnswer() } function nextLevel() { if(numberOfLevel <= ++currentLevel ) { currentLevel = 0 } initLevel(); } function previousLevel() { if(--currentLevel < 0) { currentLevel = numberOfLevel - 1 } initLevel(); } diff --git a/src/activities/money_back_cents/ActivityInfo.qml b/src/activities/money_back_cents/ActivityInfo.qml index be3496b56..4564553de 100644 --- a/src/activities/money_back_cents/ActivityInfo.qml +++ b/src/activities/money_back_cents/ActivityInfo.qml @@ -1,41 +1,41 @@ /* GCompris - ActivityInfo.qml * * Copyright (C) 2015 Bruno Coudoin * * 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 ActivityInfo { name: "money_back_cents/MoneyBackCents.qml" difficulty: 5 icon: "money_back_cents/money_back_cents.svg" author: "Bruno Coudoin <bruno.coudoin@gcompris.net>" demo: false //: Activity title title: qsTr("Give Tux his change, including cents") //: Help title description: qsTr("Practice money usage by giving Tux his change") // intro: "Click on the money at the bottom of the screen to give Tux his change." //: Help goal goal: qsTr("Tux bought different items from you and shows you his money. You must give him back his change. At higher levels, several items are displayed, and you must first calculate the total price.") //: Help prerequisite prerequisite: qsTr("Can count") //: Help manual manual: qsTr("Click on the coins or paper money at the bottom of the screen to pay. If you want to remove a coin or note, click on it on the upper screen area.") credit: "" section: "math money measures" createdInVersion: 0 - levels: "1" + levels: "1,2,3" } diff --git a/src/activities/money_back_cents/resource/1/Data.qml b/src/activities/money_back_cents/resource/1/Data.qml index ae204b97a..f74ef8f02 100644 --- a/src/activities/money_back_cents/resource/1/Data.qml +++ b/src/activities/money_back_cents/resource/1/Data.qml @@ -1,121 +1,121 @@ /* GCompris - Data.qml * * Copyright (C) 2019 Akshay Kumar * * Authors: * Akshay 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 QtQuick 2.6 import GCompris 1.0 import "../../../../core" import "../../../money/moneyConstants.js" as Constants Dataset { - objective: qsTr("Learn how to pay up to 10 euros giving back the change") + objective: qsTr("Learn how to calculate change including cents when amount paid is upto 5 units") property var moneyItems: Constants.moneyItems data: [ { "numberOfItem": 1, "minPrice": 1, "maxPrice": 3, "paid": 5, "pocket": [ moneyItems.MONEY_COIN_2E, moneyItems.MONEY_COIN_1E, moneyItems.MONEY_COIN_5C, moneyItems.MONEY_COIN_2C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_50C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_10C, moneyItems.MONEY_COIN_1C, moneyItems.MONEY_COIN_1C ] }, { "numberOfItem": 1, "minPrice": 1, "maxPrice": 3, "paid": 5, "pocket": [ moneyItems.MONEY_COIN_2E, moneyItems.MONEY_COIN_1E, moneyItems.MONEY_COIN_5C, moneyItems.MONEY_COIN_2C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_50C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_10C, moneyItems.MONEY_COIN_1C, moneyItems.MONEY_COIN_1C ] }, { "numberOfItem": 2, "minPrice": 1, "maxPrice": 3, "paid": 5, "pocket": [ moneyItems.MONEY_COIN_2E, moneyItems.MONEY_COIN_1E, moneyItems.MONEY_COIN_5C, moneyItems.MONEY_COIN_2C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_50C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_10C, moneyItems.MONEY_COIN_1C, moneyItems.MONEY_COIN_1C ] }, { "numberOfItem": 3, "minPrice": 1, "maxPrice": 3, "paid": 5, "pocket": [ moneyItems.MONEY_COIN_2E, moneyItems.MONEY_COIN_1E, moneyItems.MONEY_COIN_5C, moneyItems.MONEY_COIN_2C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_50C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_10C, moneyItems.MONEY_COIN_1C, moneyItems.MONEY_COIN_1C ] }, { "numberOfItem": 4, "minPrice": 0, "maxPrice": 4, "paid": 5, "pocket": [ moneyItems.MONEY_COIN_2E, moneyItems.MONEY_COIN_1E, moneyItems.MONEY_COIN_5C, moneyItems.MONEY_COIN_2C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_50C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_10C, moneyItems.MONEY_COIN_1C, moneyItems.MONEY_COIN_1C ] } ] } diff --git a/src/activities/money_back_cents/resource/2/Data.qml b/src/activities/money_back_cents/resource/2/Data.qml index ae204b97a..5a9d97c47 100644 --- a/src/activities/money_back_cents/resource/2/Data.qml +++ b/src/activities/money_back_cents/resource/2/Data.qml @@ -1,121 +1,131 @@ /* GCompris - Data.qml * * Copyright (C) 2019 Akshay Kumar * * Authors: * Akshay 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 QtQuick 2.6 import GCompris 1.0 import "../../../../core" import "../../../money/moneyConstants.js" as Constants Dataset { - objective: qsTr("Learn how to pay up to 10 euros giving back the change") + objective: qsTr("Learn how to calculate change including cents when amount paid is upto 30 units") property var moneyItems: Constants.moneyItems data: [ { "numberOfItem": 1, "minPrice": 1, - "maxPrice": 3, - "paid": 5, + "maxPrice": 9, + "paid": 10, "pocket": [ + moneyItems.MONEY_PAPER_5E, moneyItems.MONEY_COIN_2E, moneyItems.MONEY_COIN_1E, moneyItems.MONEY_COIN_5C, moneyItems.MONEY_COIN_2C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_50C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_10C, moneyItems.MONEY_COIN_1C, moneyItems.MONEY_COIN_1C ] }, { "numberOfItem": 1, - "minPrice": 1, - "maxPrice": 3, - "paid": 5, + "minPrice": 5, + "maxPrice": 14, + "paid": 15, "pocket": [ + moneyItems.MONEY_PAPER_5E, + moneyItems.MONEY_PAPER_5E, moneyItems.MONEY_COIN_2E, moneyItems.MONEY_COIN_1E, moneyItems.MONEY_COIN_5C, moneyItems.MONEY_COIN_2C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_50C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_10C, moneyItems.MONEY_COIN_1C, moneyItems.MONEY_COIN_1C ] }, { "numberOfItem": 2, - "minPrice": 1, - "maxPrice": 3, - "paid": 5, + "minPrice": 10, + "maxPrice": 19, + "paid": 20, "pocket": [ + moneyItems.MONEY_PAPER_10E, + moneyItems.MONEY_PAPER_5E, moneyItems.MONEY_COIN_2E, moneyItems.MONEY_COIN_1E, moneyItems.MONEY_COIN_5C, moneyItems.MONEY_COIN_2C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_50C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_10C, moneyItems.MONEY_COIN_1C, moneyItems.MONEY_COIN_1C ] }, { "numberOfItem": 3, - "minPrice": 1, - "maxPrice": 3, - "paid": 5, + "minPrice": 15, + "maxPrice": 24, + "paid": 25, "pocket": [ + moneyItems.MONEY_PAPER_10E, + moneyItems.MONEY_PAPER_10E, + moneyItems.MONEY_PAPER_5E, moneyItems.MONEY_COIN_2E, moneyItems.MONEY_COIN_1E, moneyItems.MONEY_COIN_5C, moneyItems.MONEY_COIN_2C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_50C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_10C, moneyItems.MONEY_COIN_1C, moneyItems.MONEY_COIN_1C ] }, { "numberOfItem": 4, - "minPrice": 0, - "maxPrice": 4, - "paid": 5, + "minPrice": 20, + "maxPrice": 29, + "paid": 30, "pocket": [ + moneyItems.MONEY_PAPER_20E, + moneyItems.MONEY_PAPER_5E, moneyItems.MONEY_COIN_2E, moneyItems.MONEY_COIN_1E, moneyItems.MONEY_COIN_5C, moneyItems.MONEY_COIN_2C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_50C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_10C, moneyItems.MONEY_COIN_1C, moneyItems.MONEY_COIN_1C ] } ] } diff --git a/src/activities/money_back_cents/resource/1/Data.qml b/src/activities/money_back_cents/resource/3/Data.qml similarity index 69% copy from src/activities/money_back_cents/resource/1/Data.qml copy to src/activities/money_back_cents/resource/3/Data.qml index ae204b97a..51f839a02 100644 --- a/src/activities/money_back_cents/resource/1/Data.qml +++ b/src/activities/money_back_cents/resource/3/Data.qml @@ -1,121 +1,146 @@ /* GCompris - Data.qml * * Copyright (C) 2019 Akshay Kumar * * Authors: * Akshay 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 QtQuick 2.6 import GCompris 1.0 import "../../../../core" import "../../../money/moneyConstants.js" as Constants Dataset { - objective: qsTr("Learn how to pay up to 10 euros giving back the change") + objective: qsTr("Learn how to calculate change including cents when amount paid is upto 300 units") property var moneyItems: Constants.moneyItems data: [ { "numberOfItem": 1, - "minPrice": 1, - "maxPrice": 3, - "paid": 5, + "minPrice": 30, + "maxPrice": 39, + "paid": 40, "pocket": [ + moneyItems.MONEY_PAPER_20E, + moneyItems.MONEY_PAPER_10E, + moneyItems.MONEY_PAPER_5E, moneyItems.MONEY_COIN_2E, moneyItems.MONEY_COIN_1E, moneyItems.MONEY_COIN_5C, moneyItems.MONEY_COIN_2C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_50C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_10C, moneyItems.MONEY_COIN_1C, moneyItems.MONEY_COIN_1C ] }, { "numberOfItem": 1, - "minPrice": 1, - "maxPrice": 3, - "paid": 5, + "minPrice": 40, + "maxPrice": 49, + "paid": 50, "pocket": [ + moneyItems.MONEY_PAPER_20E, + moneyItems.MONEY_PAPER_10E, + moneyItems.MONEY_PAPER_10E, + moneyItems.MONEY_PAPER_5E, + moneyItems.MONEY_PAPER_5E, moneyItems.MONEY_COIN_2E, moneyItems.MONEY_COIN_1E, moneyItems.MONEY_COIN_5C, moneyItems.MONEY_COIN_2C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_50C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_10C, moneyItems.MONEY_COIN_1C, moneyItems.MONEY_COIN_1C ] }, { "numberOfItem": 2, - "minPrice": 1, - "maxPrice": 3, - "paid": 5, + "minPrice": 50, + "maxPrice": 70, + "paid": 100, "pocket": [ + moneyItems.MONEY_PAPER_50E, + moneyItems.MONEY_PAPER_20E, + moneyItems.MONEY_PAPER_10E, + moneyItems.MONEY_PAPER_5E, + moneyItems.MONEY_PAPER_5E, moneyItems.MONEY_COIN_2E, moneyItems.MONEY_COIN_1E, moneyItems.MONEY_COIN_5C, moneyItems.MONEY_COIN_2C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_50C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_10C, moneyItems.MONEY_COIN_1C, moneyItems.MONEY_COIN_1C ] }, { "numberOfItem": 3, - "minPrice": 1, - "maxPrice": 3, - "paid": 5, + "minPrice": 100, + "maxPrice": 199, + "paid": 200, "pocket": [ + moneyItems.MONEY_PAPER_100E, + moneyItems.MONEY_PAPER_50E, + moneyItems.MONEY_PAPER_20E, + moneyItems.MONEY_PAPER_10E, + moneyItems.MONEY_PAPER_10E, + moneyItems.MONEY_PAPER_5E, moneyItems.MONEY_COIN_2E, moneyItems.MONEY_COIN_1E, moneyItems.MONEY_COIN_5C, moneyItems.MONEY_COIN_2C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_50C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_10C, moneyItems.MONEY_COIN_1C, moneyItems.MONEY_COIN_1C ] }, { "numberOfItem": 4, - "minPrice": 0, - "maxPrice": 4, - "paid": 5, + "minPrice": 200, + "maxPrice": 299, + "paid": 300, "pocket": [ + moneyItems.MONEY_PAPER_200E, + moneyItems.MONEY_PAPER_50E, + moneyItems.MONEY_PAPER_20E, + moneyItems.MONEY_PAPER_20E, + moneyItems.MONEY_PAPER_10E, + moneyItems.MONEY_PAPER_5E, moneyItems.MONEY_COIN_2E, moneyItems.MONEY_COIN_1E, moneyItems.MONEY_COIN_5C, moneyItems.MONEY_COIN_2C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_50C, moneyItems.MONEY_COIN_20C, moneyItems.MONEY_COIN_10C, moneyItems.MONEY_COIN_1C, moneyItems.MONEY_COIN_1C ] } ] }