diff --git a/src/activities/railroad/ActivityInfo.qml b/src/activities/railroad/ActivityInfo.qml index 66c3b4f61..ce4f99cbd 100644 --- a/src/activities/railroad/ActivityInfo.qml +++ b/src/activities/railroad/ActivityInfo.qml @@ -1,35 +1,35 @@ /* GCompris - ActivityInfo.qml * * Copyright (C) 2016 Your Name * * 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: "railroad/Railroad.qml" difficulty: 1 icon: "railroad/railroad.svg" - author: "Your Name <yy@zz.org>" + author: "Utkarsh Tiwari <iamutkarshtiwari@kde.org>" demo: true - title: "Railroad activity" + title: qsTr("Railroad activity") description: "" //intro: "put here in comment the text for the intro voice" - goal: "" - prerequisite: "" - manual: "" + goal: qsTr("Improves your memory") + prerequisite: qsTr("Good memory") + manual: qsTr("A train - a locomotive and carriage(s) - is displayed at the top of the main area for a few seconds. Rebuild it at the top of the screen by selecting the appropriate carriages and locomotive. Deselect an item by clicking on it again.") credit: "" - section: "fun" + section: "memory" createdInVersion: 7000 } diff --git a/src/activities/railroad/Railroad.qml b/src/activities/railroad/Railroad.qml index 3eb4ca6eb..af5c80a41 100644 --- a/src/activities/railroad/Railroad.qml +++ b/src/activities/railroad/Railroad.qml @@ -1,225 +1,248 @@ /* GCompris - railroad.qml * * Copyright (C) 2016 * * Authors: * (GTK+ version) * YOUR NAME (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.1 import GCompris 1.0 import "../../core" import "railroad.js" as Activity ActivityBase { id: activity onStart: focus = true onStop: {} property variant barAtStart pageComponent: Image { id: background source: Activity.resourceURL + "railroad-bg.svg" height: activity.height / 2 width: activity.width anchors.fill: parent 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 score: score property alias sampleList: sampleList property alias listModel: listModel property alias displayList: displayList property alias animateFlow: animateFlow property alias railCollection: railCollection } onStart: { barAtStart = ApplicationSettings.isBarHidden; ApplicationSettings.isBarHidden = true; Activity.start(items) } onStop: { Activity.stop() } // Top Display Area Rectangle { Flow { id: displayFlow x: 2 y: background.height / 12 Repeater { id: displayList model: listModel delegate: Image { id: wagon source: Activity.resourceURL + "loco1.svg" height: background.height / 8.5 width: background.width / (Activity.railWidthArray[0] + 1) visible: true MouseArea { id: displayWagonMouseArea hoverEnabled: true enabled: true anchors.fill: parent onClicked: { if (Activity.memoryMode == true) { listModel.remove(index); Activity.isAnswer(); } else { animateFlow.stop(); displayFlow.x = 2; listModel.clear(); Activity.memoryMode = true; Activity.items.railCollection.visible = true ApplicationSettings.isBarHidden = true; } } } states: State { name: "waganHover" when: displayWagonMouseArea.containsMouse PropertyChanges { target: wagon scale: 1.1 } } } } onXChanged: { if (displayFlow.x >= background.width) { animateFlow.stop(); displayFlow.x = 2; listModel.clear(); Activity.memoryMode = true; Activity.items.railCollection.visible = true; ApplicationSettings.isBarHidden = true; } } PropertyAnimation { id: animateFlow target: displayFlow properties: "x" from: 2 to: background.width duration: 18000 easing.type: Easing.InExpo loops: 1 } } ListModel { id: listModel } } // Lower Sample Wagon Display Area Rectangle { id: railCollection + color: "transparent" visible: false - Flow { - id: railCarriages - x: 2 - y: background.height / 4.7 - height: background.height - (background.height / 5) - width: background.width - anchors.margins: 1 - anchors.bottomMargin: 10 - spacing: 8 - flow: Flow.LeftToRight - Repeater { - id: sampleList - model: 22 - - Image { - id: loco - source: Activity.resourceURL + "loco" + (index + 1) + ".svg" - height: background.height / 7.5 - width: background.width / Activity.railWidthArray[index] - visible: true - MouseArea { - id: mouseArea - hoverEnabled: true - enabled: true - anchors.fill: parent - onClicked: { - Activity.addWagon(index + 1); - Activity.isAnswer(); + Repeater { + id: sampleList + model: 5 + Flow { + id: railCarriages + property real rowNo: index + anchors.margins: 1 + anchors.bottomMargin: 10 + spacing: 8 + x: 2 + y: (background.height / 4.7) + (index * (background.height / 6.5)) + height: background.height / 7.5 + width: background.width + flow: Flow.LeftToRight + + Repeater { + + id: eachRow + model: Activity.noOfCarriages[railCarriages.rowNo] + + Image { + id: loco + readonly property int uniqueID: Activity.sum(railCarriages.rowNo) + index + source: Activity.resourceURL + "loco" + (uniqueID + 1) + ".svg" + height: background.height / 7.5 + width: background.width / (Activity.railWidthArray[uniqueID]); + visible: true + MouseArea { + id: mouseArea + hoverEnabled: true + enabled: true + anchors.fill: parent + onClicked: { + Activity.addWagon(parent.uniqueID + 1); + Activity.isAnswer(); + } } - } - states: State { - name: "carHover" - when: mouseArea.containsMouse - PropertyChanges { - target: loco - scale: 1.1 + states: State { + name: "carHover" + when: mouseArea.containsMouse + PropertyChanges { + target: loco + scale: 1.1 + } } } } } } } + // Lower level wagons shelves + Repeater { + id: railSupporter + model: 5 + Rectangle { + x: 0 + y: (background.height / 2.9) + (index * (background.height / 6.5)) + width: background.width + height: 5 + border.color: "#808180" + color: "transparent" + border.width: 5 + } + } + DialogHelp { id: dialogHelp onClose: home() } Score { id: score anchors.top: parent.top anchors.topMargin: 10 * ApplicationInfo.ratio anchors.right: parent.right anchors.leftMargin: 10 * ApplicationInfo.ratio anchors.bottom: undefined anchors.left: undefined } Bar { id: bar content: BarEnumContent { value: help | home | level | reload} onHelpClicked: { displayDialog(dialogHelp) } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() onReloadClicked: { Activity.reset() } } Bonus { id: bonus Component.onCompleted: win.connect(Activity.advanceSubLevel) } } - } diff --git a/src/activities/railroad/railroad.js b/src/activities/railroad/railroad.js index 6fc3b3613..bc5165686 100644 --- a/src/activities/railroad/railroad.js +++ b/src/activities/railroad/railroad.js @@ -1,143 +1,153 @@ /* GCompris - railroad.js * * Copyright (C) 2016 YOUR NAME * * Authors: * (GTK+ version) * "YOUR NAME" (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 QtQuick 2.0 as Quick .import GCompris 1.0 as GCompris var currentLevel = 0 var numberOfLevel = 4 var noOfCarriages = [4, 5, 4, 4, 5] var railWidthArray = [5, 4, 3.8, 3.8, 5, 6.5, 6.5, 3.8, 6.5, 4, 4, 4, 4.5, 4, 4, 4.5, 4, 5, 5.5, 6.5, 6.5, 3.8] var memoryMode = false var backupArray = [] var isReset = false var resourceURL = "qrc:/gcompris/src/activities/railroad/resource/" var maxSubLevel = 3 var sampleIsVisible = false var items function start(items_) { items = items_ currentLevel = 0 items.score.numberOfSubLevels = maxSubLevel; items.score.currentSubLevel = 1; initLevel() } function stop() { } function initLevel() { var index = 0; memoryMode = false; items.railCollection.visible = false; items.animateFlow.stop(); // Stops any previous animations items.listModel.clear(); items.displayList.model = items.listModel; if (isReset == false) { // Initiates a new level backupArray = []; for (var i = 0; i < currentLevel + 2; i++) { if (i == (currentLevel + 1)) { // Selects the last carriage do { index = Math.floor(Math.random() * 9) + 1; } while (backupArray.indexOf(index) != -1) // Ensures non-repeative wagons setup } else { // Selects the follow up wagons do { index = Math.floor(Math.random() * 12) + 10; } while (backupArray.indexOf(index) != -1) } backupArray.push(index); items.listModel.append({"name" : index}); (items.displayList.itemAt(items.listModel.count - 1)).source = resourceURL + "loco" + (index) + ".svg"; (items.displayList.itemAt(items.listModel.count - 1)).width = items.background.width / (railWidthArray[index - 1] + 1); } } else { // Re-setup the same level for ( var i = 0; i < backupArray.length; i++) { items.listModel.append({"name" : backupArray[i]}); (items.displayList.itemAt(items.listModel.count - 1)).source = resourceURL + "loco" + (backupArray[i]) + ".svg"; (items.displayList.itemAt(items.listModel.count - 1)).width = items.background.width / (railWidthArray[backupArray[i] - 1] + 1); } isReset = false; } items.animateFlow.start() items.bar.level = currentLevel + 1; } function nextLevel() { if(numberOfLevel <= ++currentLevel ) { currentLevel = 0 } items.score.currentSubLevel = 1; initLevel(); } function previousLevel() { if(--currentLevel < 0) { currentLevel = numberOfLevel - 1 } items.score.currentSubLevel = 1; initLevel(); } function reset() { isReset = true; initLevel(); } function advanceSubLevel() { + /* Sets up the next sublevel */ items.score.currentSubLevel++; if (items.score.currentSubLevel > maxSubLevel) { nextLevel(); items.score.currentSubLevel = 1; } else { initLevel(); } } function isAnswer() { + /* Checks if the top level setup equals the solutions */ if (items.listModel.count === backupArray.length) { var flag = true; for (var index = 0; index < items.listModel.count; index++) { if (items.listModel.get(index).name != backupArray[index]) { flag = false; break; } } if (flag == true) { items.bonus.good("flower"); } } } +function sum(index) { + /* Returns the sum up till the specified index */ + var total = 0 + for (var i = 0; i