diff --git a/src/activities/guessnumber/ActivityInfo.qml b/src/activities/guessnumber/ActivityInfo.qml --- a/src/activities/guessnumber/ActivityInfo.qml +++ b/src/activities/guessnumber/ActivityInfo.qml @@ -37,4 +37,5 @@ credit: "" section: "math numeration" createdInVersion: 0 + levels: "1,2,3,4,5" } diff --git a/src/activities/guessnumber/AnswerArea.qml b/src/activities/guessnumber/AnswerArea.qml --- a/src/activities/guessnumber/AnswerArea.qml +++ b/src/activities/guessnumber/AnswerArea.qml @@ -36,7 +36,6 @@ } property string userEntry - // A top gradient Rectangle { anchors.fill: parent @@ -54,7 +53,6 @@ anchors.fill: parent horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter - text: answerBackground.userEntry color: "black" fontSize: largeSize style: Text.Outline @@ -69,7 +67,10 @@ } onUserEntryChanged: { + if(userEntry == "") + userEntryText.text = "" if(userEntry != "") + userEntryText.text = Number(answerBackground.userEntry).toLocaleString(Qt.locale(), 'f', 0) Activity.setUserAnswer(parseInt(userEntry)) } } diff --git a/src/activities/guessnumber/Guessnumber.qml b/src/activities/guessnumber/Guessnumber.qml --- a/src/activities/guessnumber/Guessnumber.qml +++ b/src/activities/guessnumber/Guessnumber.qml @@ -44,6 +44,7 @@ onHeightChanged: helico.init() Component.onCompleted: { + dialogActivityConfig.initialize() activity.start.connect(start) activity.stop.connect(stop) } @@ -59,8 +60,11 @@ property alias textArea: textArea property alias infoText: userInfo property alias answerArea: answerArea - property alias numpad: numpad + property alias numericalSuite: numericalSuite + property var levels: activity.datasetLoader.item.data + property var difficulty: activity.datasetLoader.item.difficulty property int currentMax: 0 + property alias numpad: numpad property int maxSize: 120 property int minSize: 80 property int barHeightAddon: ApplicationSettings.isBarHidden ? 1 : 3 @@ -115,6 +119,42 @@ fontSize: regularSize } + Item { + id: numericalSuite + anchors { + horizontalCenter: textArea.horizontalCenter + top: userInfo.top + left: textArea.left + topMargin: 20 + textArea.contentHeight + } + visible: false + Row { + Repeater { + id: repeatNumbers + model: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", + "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"] + Rectangle { + id: suiteNumber + width: 80 + height: 80 + color: activeFocus ? "#ff07fff2" : "#cccccccc" + border.color: "black" + border.width: 1 + radius: 2 + gradient: Gradient { + GradientStop { position: 0.0; color: "#CCFFFFFF" } + GradientStop { position: 0.5; color: "#80FFFFFF" } + GradientStop { position: 1.0; color: "#00000000" } + } + Text { + text: modelData + font.pointSize: 35 + } + } + } + } + } + NumPad { id: numpad onAnswerChanged: { @@ -134,6 +174,25 @@ numpad.updateAnswer(event.key, false); } + DialogChooseLevel { + id: dialogActivityConfig + currentActivity: activity.activityInfo + + onSaveData: { + levelFolder = dialogActivityConfig.chosenLevel + currentActivity.currentLevel = dialogActivityConfig.chosenLevel + ApplicationSettings.setCurrentLevel(currentActivity.name, dialogActivityConfig.chosenLevel) + background.start() + home() + } + onClose: { + home() + } + onStartActivity: { + background.start() + } + } + DialogHelp { id: dialogHelp onClose: home() @@ -141,10 +200,13 @@ Bar { id: bar - content: BarEnumContent { value: help | home | level } + content: BarEnumContent { value: help | home | level | activityConfig } onHelpClicked: { displayDialog(dialogHelp) } + onActivityConfigClicked: { + displayDialog(dialogActivityConfig) + } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() diff --git a/src/activities/guessnumber/guessnumber.js b/src/activities/guessnumber/guessnumber.js --- a/src/activities/guessnumber/guessnumber.js +++ b/src/activities/guessnumber/guessnumber.js @@ -23,7 +23,7 @@ .import QtQuick 2.6 as Quick var currentLevel = 0 -var numberOfLevel = 9 +var numberOfLevel var items var numberToGuess = 0 @@ -37,41 +37,23 @@ } function initLevel() { + numberOfLevel = items.levels.length items.bar.level = currentLevel + 1 + items.currentMax = items.levels[currentLevel].maxNumber items.helico.init() items.helico.state = "horizontal" items.infoText.text = "" items.numpad.resetText() - switch(currentLevel) { - case 0: items.currentMax = 20 - numberToGuess = getRandomInt(1,items.currentMax) - break; - case 1: items.currentMax = 40 - numberToGuess = getRandomInt(1,items.currentMax) - break; - case 2: items.currentMax = 60 - numberToGuess = getRandomInt(1,items.currentMax) - break; - case 3: items.currentMax = 100 - numberToGuess = getRandomInt(1,items.currentMax) - break; - case 4: items.currentMax = 500 - numberToGuess = getRandomInt(1,items.currentMax) - break; - case 5: items.currentMax = 1000 - numberToGuess = getRandomInt(1,items.currentMax) - break; - case 6: items.currentMax = 5000 - numberToGuess = getRandomInt(1,items.currentMax) - break; - case 7: items.currentMax = 10000 - numberToGuess = getRandomInt(1,items.currentMax) - break; - case 8: items.currentMax = 50000 - numberToGuess = getRandomInt(1,items.currentMax) - break; - } - items.textArea.text = qsTr("Guess a number between 1 and %1").arg(items.currentMax); + if(items.levels) + numberToGuess = getRandomInt(1, items.levels[currentLevel].maxNumber) + if(items.difficulty == 1) + if(currentLevel == 0 || currentLevel == 2 || currentLevel == 4) + items.numericalSuite.visible = true + else + items.numericalSuite.visible = false + else + items.numericalSuite.visible = false + items.textArea.text = items.levels[currentLevel].objective } function nextLevel() { @@ -95,7 +77,7 @@ function setUserAnswer(value){ if(value === 0) return; - if(value > items.currentMax){ + if(value > items.levels[currentLevel].maxNumber){ items.infoText.text = qsTr("Number too high") return; } @@ -112,9 +94,9 @@ items.helico.x = items.background.width items.helico.y = items.background.height / 2 - items.helico.height / 2 } else { - var diff = Math.abs(numberToGuess-value)/items.currentMax + var diff = Math.abs(numberToGuess-value) / items.levels[currentLevel].maxNumber items.helico.x = (items.background.width-items.helico.width) - diff * items.background.width items.helico.y = items.background.height / 2 + - ((numberToGuess-value) / items.currentMax) * (items.background.height/2) - items.helico.height / 2 + ((numberToGuess-value) / items.levels[currentLevel].maxNumber) * (items.background.height/2) - items.helico.height / 2 } } diff --git a/src/activities/guessnumber/resource/1/Data.qml b/src/activities/guessnumber/resource/1/Data.qml new file mode 100644 --- /dev/null +++ b/src/activities/guessnumber/resource/1/Data.qml @@ -0,0 +1,57 @@ +/* GCompris - Data.qml + * + * Copyright (C) 2019 Sambhav Kaul + * + * Authors: + * Sambhav Kaul + * + * 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" + +Dataset { + objective: qsTr("Guess a number between 1 and 20.") + difficulty: 1 + data: [ + { + // first number is the minimum number and second is the maximum number + "objective" : qsTr("Guess a number between 1 and %1").arg(10), + "maxNumber" : 10 + }, + { + "objective" : qsTr("Guess a number between 1 and %1").arg(10), + "maxNumber" : 10 + }, + { + "objective" : qsTr("Guess a number between 1 and %1").arg(15), + "maxNumber" : 15 + }, + { + "objective" : qsTr("Guess a number between 1 and %1").arg(15), + "maxNumber" : 15 + }, + { + "objective" : qsTr("Guess a number between 1 and %1").arg(20), + "maxNumber" : 20 + }, + { + "objective" : qsTr("Guess a number between 1 and %1").arg(20), + "maxNumber" : 20 + } + ] +} + diff --git a/src/activities/guessnumber/resource/2/Data.qml b/src/activities/guessnumber/resource/2/Data.qml new file mode 100644 --- /dev/null +++ b/src/activities/guessnumber/resource/2/Data.qml @@ -0,0 +1,40 @@ +/* GCompris - Data.qml + * + * Copyright (C) 2019 Sambhav Kaul + * + * Authors: + * Sambhav Kaul + * + * 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" + +Dataset { + objective: qsTr("Guess a number between 1 and 100.") + difficulty: 2 + data: [ + { + // first number is the minimum number and second is the maximum number + "objective" : qsTr("Guess a number between 1 and %1").arg(10), + "maxNumber" : 10 + }, + { + "objective" : qsTr("Guess a number between 1 and %1").arg(100), + "maxNumber" : 100 + } + ] +} diff --git a/src/activities/guessnumber/resource/3/Data.qml b/src/activities/guessnumber/resource/3/Data.qml new file mode 100644 --- /dev/null +++ b/src/activities/guessnumber/resource/3/Data.qml @@ -0,0 +1,44 @@ +/* GCompris - Data.qml + * + * Copyright (C) 2019 Sambhav Kaul + * + * Authors: + * Sambhav Kaul + * + * 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" + +Dataset { + objective: qsTr("Guess a number between 1 and 1000.") + difficulty: 3 + data: [ + { + // first number is the minimum number and second is the maximum number + "objective" : qsTr("Guess a number between 1 and %1").arg(10), + "maxNumber" : 10 + }, + { + "objective" : qsTr("Guess a number between 1 and %1").arg(100), + "maxNumber" : 100 + }, + { + "objective" : qsTr("Guess a number between 1 and %1").arg(1000), + "maxNumber" : 1000 + } + ] +} diff --git a/src/activities/guessnumber/resource/4/Data.qml b/src/activities/guessnumber/resource/4/Data.qml new file mode 100644 --- /dev/null +++ b/src/activities/guessnumber/resource/4/Data.qml @@ -0,0 +1,49 @@ +/* GCompris - Data.qml + * + * Copyright (C) 2019 Sambhav Kaul + * + * Authors: + * Sambhav Kaul + * + * 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" + +Dataset { + objective: qsTr("Guess a number between 1 and 100 000.") + difficulty: 4 + data: [ + { + // first number is the minimum number and second is the maximum number + "objective" : qsTr("Guess a number between 1 and %1").arg(10), + "maxNumber" : 10 + }, + { + "objective" : qsTr("Guess a number between 1 and %1").arg(100), + "maxNumber" : 100 + }, + { + "objective" : qsTr("Guess a number between 1 and %1").arg(1000), + "maxNumber" : 1000 + }, + { + "objective" : qsTr("Guess a number between 1 and %1").arg(100000), + "maxNumber" : 100000 + } + ] +} + diff --git a/src/activities/guessnumber/resource/5/Data.qml b/src/activities/guessnumber/resource/5/Data.qml new file mode 100644 --- /dev/null +++ b/src/activities/guessnumber/resource/5/Data.qml @@ -0,0 +1,53 @@ +/* GCompris - Data.qml + * + * Copyright (C) 2019 Sambhav Kaul + * + * Authors: + * Sambhav Kaul + * + * 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" + +Dataset { + objective: qsTr("Guess a number between 1 and 1 000 000.") + difficulty: 5 + data: [ + { + // first number is the minimum number and second is the maximum number + "objective" : qsTr("Guess a number between 1 and %1").arg(10), + "maxNumber" : 10 + }, + { + "objective" : qsTr("Guess a number between 1 and %1").arg(100), + "maxNumber" : 100 + }, + { + "objective" : qsTr("Guess a number between 1 and %1").arg(1000), + "maxNumber" : 1000 + }, + { + "objective" : qsTr("Guess a number between 1 and %1").arg(100000), + "maxNumber" : 100000 + }, + { + "objective" : qsTr("Guess a number between 1 and %1").arg(1000000), + "maxNumber" : 1000000 + } + ] +} +