From 922b65b3eaeb975224adcdfda8a2595cd76309d5 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 3 Apr 2020 18:34:39 +0200 Subject: Well, I'm back at SFOS development! This unfinished idea shows a dynamic approach to the binary fun game including dynamic bit lengths - that's awesome, isn't it? Aside from this AWESOME new feature, I removed the logic and the ugly code from before and need to rewrite it ASAP :) --- BinaryFun.pro | 1 + BinaryFun.pro.user | 462 +++++-------------------------------------- qml/Bit.qml | 31 +++ qml/pages/FirstPage.qml | 258 ++++++------------------ translations/BinaryFun-de.ts | 14 +- translations/BinaryFun.ts | 12 -- 6 files changed, 137 insertions(+), 641 deletions(-) create mode 100644 qml/Bit.qml diff --git a/BinaryFun.pro b/BinaryFun.pro index bfffd72..d75cf78 100644 --- a/BinaryFun.pro +++ b/BinaryFun.pro @@ -17,6 +17,7 @@ CONFIG += sailfishapp SOURCES += src/BinaryFun.cpp DISTFILES += qml/BinaryFun.qml \ + qml/Bit.qml \ qml/cover/CoverPage.qml \ qml/pages/FirstPage.qml \ rpm/BinaryFun.changes.in \ diff --git a/BinaryFun.pro.user b/BinaryFun.pro.user index aced038..6d77191 100644 --- a/BinaryFun.pro.user +++ b/BinaryFun.pro.user @@ -1,14 +1,14 @@ - + EnvironmentId - {1cd99421-ba56-4c51-bdec-e904699ea9c3} + {bdaad72d-59f2-4f26-a23b-24e539401131} ProjectExplorer.Project.ActiveTarget - 1 + 0 ProjectExplorer.Project.EditorSettings @@ -45,7 +45,7 @@ 0 8 true - 1 + 0 true true true @@ -59,380 +59,14 @@ ProjectExplorer.Project.Target.0 - SailfishOS-3.0.0.8-i486 (in Sailfish OS Build Engine) - SailfishOS-3.0.0.8-i486 (in Sailfish OS Build Engine) - {5937b1e5-114b-46e7-88bb-b7cc7e8424e5} - 0 - 0 - 0 - - /home/melvin/Coding/build-BinaryFun-SailfishOS_3_0_0_8_i486_in_Sailfish_OS_Build_Engine-Debug - - - true - Start Build Engine - - Mer.MerSdkStartStep - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - false - - - - 3 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Start Build Engine - - Mer.MerSdkStartStep - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - true - clean - - - 2 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - /home/melvin/Coding/build-BinaryFun-SailfishOS_3_0_0_8_i486_in_Sailfish_OS_Build_Engine-Release - - - true - Start Build Engine - - Mer.MerSdkStartStep - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - false - - - - 3 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Start Build Engine - - Mer.MerSdkStartStep - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - true - clean - - - 2 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - /home/melvin/Coding/build-BinaryFun-SailfishOS_3_0_0_8_i486_in_Sailfish_OS_Build_Engine-Profile - - - true - Start Build Engine - - Mer.MerSdkStartStep - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - false - - - - 3 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Start Build Engine - - Mer.MerSdkStartStep - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - true - clean - - - 2 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - - true - RPM - - QmakeProjectManager.MerRpmBuildStep - - - true - RPM Validation - - QmakeProjectManager.MerRpmValidationStep - - 2 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy By Building An RPM Package - Deploy By Building An RPM Package - QmakeProjectManager.MerMb2RpmBuildConfiguration - - - - - true - Prepare Target - - QmakeProjectManager.MerPrepareTargetStep - - - true - Rsync - - QmakeProjectManager.MerRsyncDeployStep - - 2 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy By Copying Binaries - Deploy By Copying Binaries - QmakeProjectManager.MerRSyncDeployConfiguration - - - - - true - Prepare Target - - QmakeProjectManager.MerPrepareTargetStep - - - true - RPM - - QmakeProjectManager.MerRpmDeployStep - - 2 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy As RPM Package - Deploy As RPM Package - QmakeProjectManager.MerRpmDeployConfiguration - - 3 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - /home/melvin/Coding/BinaryFun - false - 10234 - 3 - - -1 - - BinaryFun (on Sailfish OS Device) - - QmakeProjectManager.MerRunConfiguration:BinaryFun - - BinaryFun - 1 - - false - - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.1 - - SailfishOS-3.0.0.8-armv7hl (in Sailfish OS Build Engine) - SailfishOS-3.0.0.8-armv7hl (in Sailfish OS Build Engine) - {c2c68a7d-4585-4a8f-9e36-a9b373f9d34e} + SailfishOS-3.2.1.20-i486 (in Sailfish OS Build Engine) + SailfishOS-3.2.1.20-i486 (in Sailfish OS Build Engine) + SailfishOS-3.2.1.20-i486 0 2 0 - /home/melvin/Coding/build-BinaryFun-SailfishOS_3_0_0_8_armv7hl_in_Sailfish_OS_Build_Engine-Debug + /home/melvin/code/build-BinaryFun-SailfishOS_3_2_1_20_i486_in_Sailfish_OS_Build_Engine-Debug true @@ -456,13 +90,11 @@ Make Qt4ProjectManager.MakeStep - - -w - -r - + false + false 3 Build @@ -481,13 +113,11 @@ Make Qt4ProjectManager.MakeStep - - -w - -r - + true clean + false 2 Clean @@ -504,7 +134,7 @@ true - /home/melvin/Coding/build-BinaryFun-SailfishOS_3_0_0_8_armv7hl_in_Sailfish_OS_Build_Engine-Release + /home/melvin/code/build-BinaryFun-SailfishOS_3_2_1_20_i486_in_Sailfish_OS_Build_Engine-Release true @@ -528,13 +158,11 @@ Make Qt4ProjectManager.MakeStep - - -w - -r - + false + false 3 Build @@ -553,13 +181,11 @@ Make Qt4ProjectManager.MakeStep - - -w - -r - + true clean + false 2 Clean @@ -576,7 +202,7 @@ true - /home/melvin/Coding/build-BinaryFun-SailfishOS_3_0_0_8_armv7hl_in_Sailfish_OS_Build_Engine-Profile + /home/melvin/code/build-BinaryFun-SailfishOS_3_2_1_20_i486_in_Sailfish_OS_Build_Engine-Profile true @@ -600,13 +226,11 @@ Make Qt4ProjectManager.MakeStep - - -w - -r - + false + false 3 Build @@ -625,13 +249,11 @@ Make Qt4ProjectManager.MakeStep - - -w - -r - + true clean + false 2 Clean @@ -668,8 +290,8 @@ ProjectExplorer.BuildSteps.Deploy 1 - Deploy By Building An RPM Package - Deploy By Building An RPM Package + Build RPM Package For Manual Deployment + QmakeProjectManager.MerMb2RpmBuildConfiguration @@ -693,7 +315,7 @@ 1 Deploy By Copying Binaries - Deploy By Copying Binaries + QmakeProjectManager.MerRSyncDeployConfiguration @@ -717,12 +339,21 @@ 1 Deploy As RPM Package - Deploy As RPM Package + QmakeProjectManager.MerRpmDeployConfiguration 3 + dwarf + + cpu-cycles + + + 250 + -F + true + 4096 false false 1000 @@ -737,6 +368,7 @@ 0.01 10 true + kcachegrind 1 25 @@ -762,42 +394,42 @@ 13 14 - /home/melvin/Coding/BinaryFun + /home/melvin/code/BinaryFunSFOS false - 10234 + -1 3 1 - BinaryFun (on Sailfish OS Device) - - QmakeProjectManager.MerRunConfiguration:BinaryFun - - BinaryFun + + BinaryFun (on Sailfish OS Emulator 3.2.1.20) + QmakeProjectManager.MerRunConfiguration:/home/melvin/code/BinaryFunSFOS/BinaryFun.pro 1 false - + 3768 false true false false true + + 1 ProjectExplorer.Project.TargetCount - 2 + 1 ProjectExplorer.Project.Updater.FileVersion - 18 + 21 Version - 18 + 21 diff --git a/qml/Bit.qml b/qml/Bit.qml new file mode 100644 index 0000000..3e7dd7b --- /dev/null +++ b/qml/Bit.qml @@ -0,0 +1,31 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 + +Loader { + property int index: 0 + property int bits: 0 + + Component { + id: bit + Switch { + width: Theme.paddingLarge * 2 + height: width + onClicked: root.check(index) + } + } + + Component { + id: bit_index + Label { + text: parent.index.toString() + width: Theme.paddingLarge * 2 + height: width + horizontalAlignment: TextInput.AlignHCenter + verticalAlignment: TextInput.AlignVCenter + Component.onCompleted: this.text = "0" + } + } + + sourceComponent: (index % (bits + 1) == bits) + || (index <= bits) ? bit_index : bit +} diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml index 72270ad..8ffa6e1 100644 --- a/qml/pages/FirstPage.qml +++ b/qml/pages/FirstPage.qml @@ -1,206 +1,62 @@ -import QtQuick 2.0 +import QtQuick 2.2 import Sailfish.Silica 1.0 - -Page { - property var correctBinary: []; - - property var pads: [ - ["0", "0", "0", "0"], - ["0", "0", "0", "0"], - ["0", "0", "0", "0"], - ["0", "0", "0", "0"] - ]; - - property var correctRows: { - "0": false, - "1": false, - "2": false, - "3": false - } - - function check(row, index, checked) { - pads[row][index] = checked ? "1" : "0"; - const typedBinary = parseInt(pads[row].join("")); - const neededBinary = parseInt(dec2bin(eval("rand_" + row).text)); - const isCorrect = typedBinary === neededBinary; - correctRows[row.toString()] = isCorrect; - - if (isCorrect) eval("rand_" + row).color = "green"; - else eval("rand_" + row).color = "white"; - - console.log("Correct rows:" + JSON.stringify(correctRows)); - - if (Object.keys(correctRows).every(function(k){ return correctRows[k] })) { - gameover.text = qsTr("Yeeha!"); - newGameBtn.visible = true; - timer.stop() - } - else { - gameover.text = ""; - newGameBtn.visible = false; - timer.start() - } - } - - function dec2bin(dec){ - return parseInt((dec >>> 0).toString(2)); - } - - function getRandom() { - return Math.floor(Math.random() * 15) + 1; - } - - function newGame() { - pageStack.push(Qt.resolvedUrl("FirstPage.qml")) - } - - id: page - allowedOrientations: Orientation.All - - SilicaFlickable { - anchors.fill: parent - - PullDownMenu { - MenuItem { - text: qsTr("Leaderboard") - onClicked: pageStack.push(Qt.resolvedUrl("LeaderBoard.qml")) - } - } - - contentHeight: column.height - - Column { - id: column - width: page.width - spacing: Theme.paddingLarge - anchors.horizontalCenter: parent.horizontalCenter - - PageHeader { - title: qsTr("Binary Fun") - } - - Grid { - anchors.horizontalCenter: parent.horizontalCenter - columns: 5 - - // UGLINESS STARTS IN 3.. 2.. 1.. ! - - Switch { - onClicked: check(0, 0, checked) - } - - Switch { - onClicked: check(0, 1, checked) - } - - Switch { - onClicked: check(0, 2, checked) - } - - Switch { - onClicked: check(0, 3, checked) - } - - Label { - id: rand_0 - text: getRandom() - } - - // - - Switch { - onClicked: check(1, 0, checked) - } - - Switch { - onClicked: check(1, 1, checked) - } - - Switch { - onClicked: check(1, 2, checked) - } - - Switch { - onClicked: check(1, 3, checked) - } - - Label { - id: rand_1 - text: getRandom() - } - - // - - Switch { - onClicked: check(2, 0, checked) - } - - Switch { - onClicked: check(2, 1, checked) - } - - Switch { - onClicked: check(2, 2, checked) - } - - Switch { - onClicked: check(2, 3, checked) - } - - Label { - id: rand_2 - text: getRandom() +import ".." + +ApplicationWindow { + initialPage: pageComponent + + Component { + id: pageComponent + + Page { + id: page + allowedOrientations: Orientation.All + + SilicaFlickable { + anchors.fill: parent + contentHeight: root.height + + PullDownMenu { + MenuItem { + text: qsTr("Leaderboard") + onClicked: pageStack.push(Qt.resolvedUrl( + "LeaderBoard.qml")) + } + } + + Column { + property int bits: 4 + property var matrix: new Array(Math.pow(bits + 1, 2)); + + id: root + width: page.width + height: page.height + spacing: Theme.paddingLarge + + PageHeader { + title: "Binary Fun" + } + + function check(index) { + root.matrix[index] ^= 1; + } + + Grid { + id: grid + anchors.verticalCenter: parent.verticalCenter + columns: root.bits + 1 + rows: root.bits + 1 + Repeater { + id: repeater + model: Math.pow(root.bits + 1, 2) + delegate: Bit { + bits: root.bits + index: modelData + width: page.width / (root.bits + 1) + } + } + } } - - // - - Switch { - onClicked: check(3, 0, checked) - } - - Switch { - onClicked: check(3, 1, checked) - } - - Switch { - onClicked: check(3, 2, checked) - } - - Switch { - onClicked: check(3, 3, checked) - } - - Label { - id: rand_3 - text: getRandom() - } - } - - Button { - id: newGameBtn - text: qsTr("Play again!") - visible: false - anchors.horizontalCenter: parent.horizontalCenter - onClicked: newGame() - } - - Label { - id: gameover - anchors.horizontalCenter: parent.horizontalCenter - } - - Label { - id: timerLabel - text: "0.0" - anchors.horizontalCenter: parent.horizontalCenter - } - - Timer { - id: timer - interval: 10 - running: true - repeat: true - onTriggered: timerLabel.text = (parseFloat(timerLabel.text) + 0.01).toFixed(2).toString() } } } diff --git a/translations/BinaryFun-de.ts b/translations/BinaryFun-de.ts index 9e31b46..548a5d2 100644 --- a/translations/BinaryFun-de.ts +++ b/translations/BinaryFun-de.ts @@ -10,21 +10,9 @@ FirstPage - - Yeeha! - Juhuu! - Leaderboard - Bestenliste - - - Binary Fun - Binary Fun - - - Play again! - Nochmal spielen! + diff --git a/translations/BinaryFun.ts b/translations/BinaryFun.ts index 26f13c8..b322625 100644 --- a/translations/BinaryFun.ts +++ b/translations/BinaryFun.ts @@ -10,22 +10,10 @@ FirstPage - - Yeeha! - - Leaderboard - - Binary Fun - - - - Play again! - - LeaderBoard -- cgit v1.2.3