diff --git a/src/activities/binary_bulb/BinaryBulb.qml b/src/activities/binary_bulb/BinaryBulb.qml index a62baf698..190ae7f68 100644 --- a/src/activities/binary_bulb/BinaryBulb.qml +++ b/src/activities/binary_bulb/BinaryBulb.qml @@ -1,209 +1,210 @@ /* GCompris - BinaryBulb.qml * * Copyright (C) 2018 Rajat Asthana * * Authors: * RAJAT ASTHANA * * 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 "binary_bulb.js" as Activity import "numbers.js" as Dataset ActivityBase { id: activity onStart: focus = true onStop: {} property var dataset: Dataset pageComponent: Image { id: background anchors.fill: parent source: "resource/background.svg" signal start signal stop Component.onCompleted: { activity.start.connect(start) activity.stop.connect(stop) } // Add here the QML items you need to access in javascript QtObject { id: items property Item main: activity.main property alias background: background property alias bar: bar property alias bonus: bonus property alias bulbs: bulbs property int numberSoFar: 0 property int numberToConvert: 0 property int numberOfBulbs: 0 property int currentSelectedBulb: -1 property int currentLevel: 0 property alias score: score } onStart: { Activity.start(items, dataset) } onStop: { Activity.stop() } IntroMessage { id: message onIntroDone: { Activity.initLevel() } intro: [ qsTr("Computers use binary number system, where there are two symbols, 0 and 1."), qsTr("In decimal number system 123 is represented as 1 x 100 + 2 x 10 + 3 x 1."), qsTr("Binary represents numbers in the same pattern, but using powers of 2 instead of powers of 10 that decimal uses."), qsTr("So, 1 in binary is represented by 001, 4 by 100, 7 by 111 and so on..."), qsTr("Our computer has a lot of switches (called transistors) that can be turned on or off given electricity. A switch that is on will represent a 1 and a switch that is off will represent a 0."), qsTr("In this activity, you are given a number, you have to find its binary representation by turning on the bulbs. An on bulb represents 1 and an off bulb represents 0.") ] z: 20 anchors { top: parent.top topMargin: 10 right: parent.right rightMargin: 5 left: parent.left leftMargin: 5 } } Keys.onPressed: { if(event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { Activity.equalityCheck() } else if(event.key == Qt.Key_Space) { if(items.currentSelectedBulb != -1) { Activity.changeState(items.currentSelectedBulb) } } else if(event.key == Qt.Key_Left) { if(--items.currentSelectedBulb < 0) { items.currentSelectedBulb = items.numberOfBulbs-1 } } else if(event.key == Qt.Key_Right) { if(++items.currentSelectedBulb >= items.numberOfBulbs) { items.currentSelectedBulb = 0 } } } Rectangle { id: questionItemBackground opacity: 0 z: 10 anchors { horizontalCenter: parent.horizontalCenter bottomMargin: 10 } height: background.height / 6 width: parent.width - 20 * ApplicationInfo.ratio } GCText { id: questionItem anchors.fill: questionItemBackground anchors.bottom: questionItemBackground.bottom fontSizeMode: Text.Fit wrapMode: Text.Wrap z: 10 color: "white" verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter text: qsTr("What is the binary representation of %1?").arg(items.numberToConvert) } Row { id: row anchors.top: questionItem.bottom anchors.topMargin: 30 * ApplicationInfo.ratio anchors.horizontalCenter: parent.horizontalCenter spacing: 10 * ApplicationInfo.ratio Repeater { id: bulbs model: items.numberOfBulbs LightBulb { height: background.height / 5 width: (background.width > background.height) ? (background.width / 20) : ((background.width - (16 * row.spacing)) / 8) + valueVisible: Dataset.get()[items.currentLevel].bulbValueVisible } } } GCText { id: reachedSoFar anchors.horizontalCenter: row.horizontalCenter anchors.top: row.bottom anchors.topMargin: 30 * ApplicationInfo.ratio color: "white" fontSize: largeSize text: items.numberSoFar visible: Dataset.get()[items.currentLevel].enableHelp } BarButton { id: okButton anchors { bottom: bar.top right: parent.right rightMargin: 10 * ApplicationInfo.ratio bottomMargin: 10 * ApplicationInfo.ratio } source: "qrc:/gcompris/src/core/resource/bar_ok.svg" sourceSize.width: 60 * ApplicationInfo.ratio onClicked: Activity.equalityCheck() enabled: !bonus.isPlaying && !score.isWinAnimationPlaying } DialogHelp { id: dialogHelp onClose: home() } Bar { id: bar content: BarEnumContent { value: help | home | level} onHelpClicked: { displayDialog(dialogHelp) } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() } Score { id: score anchors.bottom: bar.top anchors.right: bar.right anchors.left: parent.left anchors.bottomMargin: 10 * ApplicationInfo.ratio anchors.leftMargin: 10 * ApplicationInfo.ratio anchors.rightMargin: 0 } Bonus { id: bonus Component.onCompleted: win.connect(Activity.nextLevel) } } } diff --git a/src/activities/binary_bulb/LightBulb.qml b/src/activities/binary_bulb/LightBulb.qml index 9a12d02a6..a41ea6ca4 100644 --- a/src/activities/binary_bulb/LightBulb.qml +++ b/src/activities/binary_bulb/LightBulb.qml @@ -1,95 +1,98 @@ /* GCompris - LightBulb.qml * * Copyright (C) 2018 Rajat Asthana * * Authors: * RAJAT ASTHANA * * 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 GCompris 1.0 import "binary_bulb.js" as Activity Item { id: bulb anchors.verticalCenter: parent.verticalCenter state: "off" focus: true + property alias valueVisible: valueText.visible + Rectangle { color: "transparent" width: parent.width + 10 height: parent.height + 10 border.color: "red" border.width: 3 anchors.centerIn: bulbImage radius: 5 visible: index == items.currentSelectedBulb } Image { id: bulbImage height: parent.height width: parent.width sourceSize.height: 60 * ApplicationInfo.ratio source: "resource/bulb_off.svg" } property string bit: "" readonly property int value: Math.pow(2, items.numberOfBulbs - index - 1) GCText { + id: valueText anchors.bottom: parent.top anchors.horizontalCenter: parent.horizontalCenter text: value color: "white" } MouseArea { anchors.fill: parent onClicked: Activity.changeState(index) } GCText { anchors.top: bulb.bottom anchors.horizontalCenter: parent.horizontalCenter text: bit color: "white" } states: [ State { name: "off" PropertyChanges { target: bulb bit: "0" } PropertyChanges { target: bulbImage source: "resource/bulb_off.svg" } }, State { name: "on" PropertyChanges { target: bulb bit: "1" } PropertyChanges { target: bulbImage source: "resource/bulb_on.svg" } } ] } diff --git a/src/activities/binary_bulb/binary_bulb.js b/src/activities/binary_bulb/binary_bulb.js index 889206d42..9be5d94e7 100644 --- a/src/activities/binary_bulb/binary_bulb.js +++ b/src/activities/binary_bulb/binary_bulb.js @@ -1,112 +1,114 @@ /* GCompris - binary_bulb.js * * Copyright (C) 2018 Rajat Asthana * * Authors: * "RAJAT ASTHANA" * * 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 numberOfLevel var items var dataset +var levelDataset function start(items_, dataset_) { items = items_ dataset = dataset_.get() items.currentLevel = 0 numberOfLevel = dataset.length } function stop() { } function resetBulbs() { for(var i = 0; i < items.numberOfBulbs; i++) { items.bulbs.itemAt(i).state = "off" } } function initializeValues() { items.currentSelectedBulb = -1 items.numberSoFar = 0 - items.numberOfBulbs = dataset[items.currentLevel].bulbCount - items.numberToConvert = dataset[items.currentLevel].numbersToBeConverted[items.score.currentSubLevel - 1] + items.numberToConvert = levelDataset[items.score.currentSubLevel - 1] } function equalityCheck() { if(items.numberSoFar == items.numberToConvert) { if(items.score.currentSubLevel < items.score.numberOfSubLevels) { items.score.currentSubLevel++; items.score.playWinAnimation() resetBulbs() initializeValues() } else { items.bonus.good("lion") resetBulbs() } } else { items.bonus.bad("lion") resetBulbs() items.numberSoFar = 0 } } function changeState(index) { var currentBulb = items.bulbs.itemAt(index) if(currentBulb.state == "off") { currentBulb.state = "on" items.numberSoFar += currentBulb.value } else { currentBulb.state = "off" items.numberSoFar -= currentBulb.value } } function initLevel() { items.bar.level = items.currentLevel + 1 items.score.numberOfSubLevels = dataset[items.currentLevel].numbersToBeConverted.length items.score.currentSubLevel = 1 + items.numberOfBulbs = dataset[items.currentLevel].bulbCount + levelDataset = Core.shuffle(dataset[items.currentLevel].numbersToBeConverted) initializeValues() resetBulbs() } function nextLevel() { if(numberOfLevel <= items.currentLevel + 1) { items.currentLevel = 0 } else { ++ items.currentLevel } items.score.currentSubLevel = 1 initLevel(); } function previousLevel() { if(items.currentLevel-1 < 0) { items.currentLevel = numberOfLevel - 1 } else { --items.currentLevel } items.score.currentSubLevel = 1 initLevel(); } diff --git a/src/activities/binary_bulb/numbers.js b/src/activities/binary_bulb/numbers.js index 222091d5a..2bb5116e0 100644 --- a/src/activities/binary_bulb/numbers.js +++ b/src/activities/binary_bulb/numbers.js @@ -1,52 +1,70 @@ /* GCompris - numbers.js * * Copyright (C) 2018 Rajat Asthana * * 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 . */ function get() { return [ { //level1 "bulbCount": 2, "numbersToBeConverted": [1, 2, 3], - "enableHelp": true + "enableHelp": true, + "bulbValueVisible": true }, { //level 2 "bulbCount": 2, "numbersToBeConverted": [1, 2, 3], - "enableHelp": false + "enableHelp": false, + "bulbValueVisible": true }, { //level3 "bulbCount": 4, "numbersToBeConverted": [4, 9, 13, 15], - "enableHelp": true + "enableHelp": true, + "bulbValueVisible": true }, { //level4 "bulbCount": 4, "numbersToBeConverted": [5, 10, 14, 7], - "enableHelp": false + "enableHelp": false, + "bulbValueVisible": true }, { //level5 "bulbCount": 8, "numbersToBeConverted": [57, 152, 248, 239, 89, 101], - "enableHelp": true + "enableHelp": true, + "bulbValueVisible": true }, { //level6 "bulbCount": 8, "numbersToBeConverted": [58, 153, 240, 236, 231, 255], - "enableHelp": false + "enableHelp": false, + "bulbValueVisible": true + }, + { //level7 + "bulbCount": 4, + "numbersToBeConverted": [3, 12, 5, 10, 15, 11], + "enableHelp": false, + "bulbValueVisible": false + }, + { //level8 + "bulbCount": 8, + "numbersToBeConverted": [57, 152, 248, 239, 89, 101], + "enableHelp": false, + "bulbValueVisible": false } ]; }