aboutsummaryrefslogtreecommitdiffhomepage
path: root/qml
diff options
context:
space:
mode:
authorMarvin Borner2020-04-03 18:34:39 +0200
committerMarvin Borner2020-04-03 22:08:27 +0200
commit922b65b3eaeb975224adcdfda8a2595cd76309d5 (patch)
tree9d9a1b89503d4f985c6d675e307b4027c19d1ede /qml
parent53ad9a4e95dab0b9cd56b829eac4062a5c46e560 (diff)
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 :)
Diffstat (limited to 'qml')
-rw-r--r--qml/Bit.qml31
-rw-r--r--qml/pages/FirstPage.qml258
2 files changed, 88 insertions, 201 deletions
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()
}
}
}