diff --git a/src/activities/binary_bulb/BinaryBulb.qml b/src/activities/binary_bulb/BinaryBulb.qml index 190ae7f68..7bbb39d82 100644 --- a/src/activities/binary_bulb/BinaryBulb.qml +++ b/src/activities/binary_bulb/BinaryBulb.qml @@ -1,210 +1,205 @@ /* 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 + // Tutorial section starts + Image { + id: tutorialImage + source: Activity.url + "background.svg" + anchors.fill: parent + z: 5 + visible: true + Tutorial { + id: tutorialSection + tutorialDetails: Activity.tutorialInstructions + onSkipPressed: { + Activity.initLevel() + tutorialImage.visible = false + } } } + // Tutorial section ends + 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/binary_bulb.js b/src/activities/binary_bulb/binary_bulb.js index 9be5d94e7..33b2f9f1b 100644 --- a/src/activities/binary_bulb/binary_bulb.js +++ b/src/activities/binary_bulb/binary_bulb.js @@ -1,114 +1,145 @@ /* 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 url = "qrc:/gcompris/src/activities/binary_bulb/resource/" +var tutorialInstructions = [ + { + "instruction": qsTr("This activity teaches how to convert decimal numbers to binary numbers."), + "instructionImage" : "qrc:/gcompris/src/activities/binary_bulb/resource/tutorial1.svg" + }, + { + "instruction": qsTr("Computers use transistors to count and transistors have only 2 states, 0 and 1. Mathematically they are represented by binary digits, a digit like a transistor has 2 states, 0 and 1."), + "instructionImage" : "qrc:/gcompris/src/activities/binary_bulb/resource/tutorial3.svg" + }, + { + "instruction": qsTr("Binary system uses these digits in a very efficient way, allowing with only 8 bits to count from 0 to 255."), + "instructionImage": "qrc:/gcompris/src/activities/binary_bulb/resource/tutorial3.svg" + }, + { + "instruction": qsTr("Each bit has a weight, from right to left 1, 2, 4, 8, 16, 32 etc.. They correspond to 2e0, 2e1, 2e2, 2e3 etc."), + "instructionImage": "qrc:/gcompris/src/activities/binary_bulb/resource/tutorial4.svg" + }, + { + "instruction": qsTr("To convert a decimal 5 to a binary value, 1 and 4 are added."), + "instructionImage": "qrc:/gcompris/src/activities/binary_bulb/resource/tutorial5.svg" + }, + { + "instruction": qsTr("Their corresponding bits are set to 1, the others set to 0. Decimal 5 is equal to binary 101."), + "instructionImage": "qrc:/gcompris/src/activities/binary_bulb/resource/tutorial6.svg" + }, + { + "instruction": qsTr("In the activity 0 and 1 are simulated by bulbs, switched on or off."), + "instructionImage": "qrc:/gcompris/src/activities/binary_bulb/resource/tutorial7.svg" + } + ] 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.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/resource/tutorial1.svg b/src/activities/binary_bulb/resource/tutorial1.svg new file mode 100644 index 000000000..93bf82587 --- /dev/null +++ b/src/activities/binary_bulb/resource/tutorial1.svg @@ -0,0 +1,8522 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/activities/binary_bulb/resource/tutorial3.svg b/src/activities/binary_bulb/resource/tutorial3.svg new file mode 100644 index 000000000..cb142a598 --- /dev/null +++ b/src/activities/binary_bulb/resource/tutorial3.svg @@ -0,0 +1,118 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + 1 + 0 + + diff --git a/src/activities/binary_bulb/resource/tutorial4.svg b/src/activities/binary_bulb/resource/tutorial4.svg new file mode 100644 index 000000000..64c1fec2c --- /dev/null +++ b/src/activities/binary_bulb/resource/tutorial4.svg @@ -0,0 +1,203 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/activities/binary_bulb/resource/tutorial5.svg b/src/activities/binary_bulb/resource/tutorial5.svg new file mode 100644 index 000000000..33975d28f --- /dev/null +++ b/src/activities/binary_bulb/resource/tutorial5.svg @@ -0,0 +1,113 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/src/activities/binary_bulb/resource/tutorial6.svg b/src/activities/binary_bulb/resource/tutorial6.svg new file mode 100644 index 000000000..c79582b47 --- /dev/null +++ b/src/activities/binary_bulb/resource/tutorial6.svg @@ -0,0 +1,89 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/src/activities/binary_bulb/resource/tutorial7.svg b/src/activities/binary_bulb/resource/tutorial7.svg new file mode 100644 index 000000000..c3cf332e5 --- /dev/null +++ b/src/activities/binary_bulb/resource/tutorial7.svg @@ -0,0 +1,1965 @@ + + + + + + + + + + + + + + image/svg+xml + + + + + + + + +