diff --git a/src/activities/algebra_by/AlgebraBy.qml b/src/activities/algebra_by/AlgebraBy.qml index add88b17a..197d1a848 100644 --- a/src/activities/algebra_by/AlgebraBy.qml +++ b/src/activities/algebra_by/AlgebraBy.qml @@ -1,31 +1,32 @@ /* GCompris - AlgebraBy.qml * * Copyright (C) 2014 Aruna Sankaranarayanan * * Authors: * Bruno Coudoin (GTK+ version) * Aruna Sankaranarayanan (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 . */ import QtQuick 2.6 import "../../core" import "../algebra_by" +import "algebra.js" as Activity Algebra { onStart: { - operand.text = "x" + operand.text = Activity.OperandsEnum.TIMES_SIGN } } diff --git a/src/activities/algebra_by/algebra.js b/src/activities/algebra_by/algebra.js index 3fac1158a..18c6e56d5 100644 --- a/src/activities/algebra_by/algebra.js +++ b/src/activities/algebra_by/algebra.js @@ -1,165 +1,171 @@ /* GCompris - algebra.js * * Copyright (C) 2014 Aruna Sankaranarayanan and 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 . */ .pragma library .import QtQuick 2.6 as Quick .import "qrc:/gcompris/src/core/core.js" as Core var currentLevel var coreItems var otherItems var operand var secondOperandVal var firstOperandVal var operations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +var OperandsEnum = { + TIMES_SIGN : "\u00D7", + PLUS_SIGN : "\u002B", + MINUS_SIGN : "\u2212", + DIVIDE_SIGN : "\u2215" +} var nbLevel = operations.length function start(coreItems_, otherItems_, operand_) { operand = operand_ coreItems = coreItems_ otherItems = otherItems_ currentLevel = 0 coreItems.score.numberOfSubLevels = 10 // for multiplication and addition, the first levels will display // currentLevel * N (N behind random) // where the last levels will do: // N * currentLevel - if(operand.text === "x" || operand.text === "+") + if(operand.text === OperandsEnum.TIMES_SIGN || operand.text === OperandsEnum.PLUS_SIGN) nbLevel = 2 * operations.length else nbLevel = operations.length initLevel() } function stop() { coreItems.balloon.stopMoving() } function initLevel() { coreItems.bar.level = currentLevel + 1 coreItems.score.visible = false coreItems.score.currentSubLevel = 1 operations = Core.shuffle(operations) calculateOperands() otherItems.iAmReady.visible = true otherItems.firstOp.visible = false otherItems.secondOp.visible = false coreItems.balloon.stopMoving() } function nextLevel() { if(++currentLevel >= nbLevel) { currentLevel = 0 } initLevel(); } function previousLevel() { if(--currentLevel < 0) { currentLevel = nbLevel - 1 } initLevel(); } function calculateOperands() { switch(operand.text) { - case "x": + case OperandsEnum.TIMES_SIGN: firstOperandVal = coreItems.bar.level secondOperandVal = operations[coreItems.score.currentSubLevel - 1] break; - case "+": + case OperandsEnum.PLUS_SIGN: firstOperandVal = coreItems.bar.level secondOperandVal = operations[coreItems.score.currentSubLevel - 1] break; - case "-": + case OperandsEnum.MINUS_SIGN: firstOperandVal = coreItems.bar.level + 9 secondOperandVal = operations[coreItems.score.currentSubLevel - 1] break; - case "/": + case OperandsEnum.DIVIDE_SIGN: firstOperandVal = coreItems.bar.level * operations[coreItems.score.currentSubLevel - 1] secondOperandVal = coreItems.bar.level break; } if(currentLevel < operations.length) { otherItems.firstOp.text = firstOperandVal otherItems.secondOp.text = secondOperandVal } else { otherItems.firstOp.text = secondOperandVal // Don't forget to remove the first operations.length levels firstOperandVal -= operations.length otherItems.secondOp.text = firstOperandVal } } // Return the expected answer function getAnswer() { switch(operand.text) { - case "x": + case OperandsEnum.TIMES_SIGN: return (firstOperandVal * secondOperandVal) - case "+": + case OperandsEnum.PLUS_SIGN: return (firstOperandVal + secondOperandVal) - case "-": + case OperandsEnum.MINUS_SIGN: return (firstOperandVal - secondOperandVal) - case "/": + case OperandsEnum.DIVIDE_SIGN: return (firstOperandVal / secondOperandVal) } } function validateAnswer(screenAnswer) { return (getAnswer() === screenAnswer) } function run() { calculateOperands() otherItems.numpad.resetText() coreItems.score.visible = true otherItems.iAmReady.visible = false otherItems.firstOp.visible = true otherItems.secondOp.visible = true otherItems.numpad.answerFlag = false otherItems.result = getAnswer() // TODO adjusting or disabling the difficulty coreItems.balloon.startMoving(20000) } function questionsLeft() { if(validateAnswer(parseInt(otherItems.numpad.answer))) { otherItems.numpad.answerFlag = true if(coreItems.score.currentSubLevel < coreItems.score.numberOfSubLevels) { coreItems.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/win.wav") coreItems.score.currentSubLevel++ coreItems.timer.start() } else { coreItems.score.currentSubLevel = 1 coreItems.balloon.stopMoving() coreItems.bonus.good("smiley"); } } } diff --git a/src/activities/algebra_div/AlgebraDiv.qml b/src/activities/algebra_div/AlgebraDiv.qml index 120d78d54..e195c6755 100644 --- a/src/activities/algebra_div/AlgebraDiv.qml +++ b/src/activities/algebra_div/AlgebraDiv.qml @@ -1,30 +1,31 @@ /* GCompris - AlgebraDiv.qml * * Copyright (C) 2015 Sayan Biswas * * Authors: * Sayan Biswas (Qt version) * * 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 "../../core" import "../algebra_by/" +import "../algebra_by/algebra.js" as Activity Algebra { onStart: { - operand.text = "/" + operand.text = Activity.OperandsEnum.DIVIDE_SIGN } } diff --git a/src/activities/algebra_minus/AlgebraMinus.qml b/src/activities/algebra_minus/AlgebraMinus.qml index 091301fdb..c717414e0 100644 --- a/src/activities/algebra_minus/AlgebraMinus.qml +++ b/src/activities/algebra_minus/AlgebraMinus.qml @@ -1,32 +1,32 @@ /* GCompris - AlgebraMinus.qml * * Copyright (C) 2014 Aruna Sankaranarayanan * * Authors: * Bruno Coudoin (GTK+ version) * Aruna Sankaranarayanan (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 . */ import QtQuick 2.6 import "../../core" import "../algebra_by/" - +import "../algebra_by/algebra.js" as Activity Algebra { onStart: { - operand.text = "-" + operand.text = Activity.OperandsEnum.MINUS_SIGN } } diff --git a/src/activities/algebra_plus/AlgebraPlus.qml b/src/activities/algebra_plus/AlgebraPlus.qml index 134d006ee..ef02af5b6 100644 --- a/src/activities/algebra_plus/AlgebraPlus.qml +++ b/src/activities/algebra_plus/AlgebraPlus.qml @@ -1,30 +1,31 @@ /* GCompris - AlgebraPlus.qml * * Copyright (C) 2015 Bruno Coudoin * * Authors: * 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 QtQuick 2.6 import "../../core" import "../algebra_by/" +import "../algebra_by/algebra.js" as Activity Algebra { onStart: { - operand.text = "+" + operand.text = Activity.OperandsEnum.PLUS_SIGN } }