aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMarvin Borner2019-01-06 17:53:13 +0100
committerMarvin Borner2019-01-06 17:53:13 +0100
commit1795e75c6540cdc88a3bfcf51c05a4881e6dd3e4 (patch)
tree6ba62f473a377c0bd58a76dfdd4dc105a3cfe003
parentbceb42b605696d408d86fad50ddd8d24c1c3499e (diff)
Added functionality
-rw-r--r--qml/pages/FirstPage.qml65
-rw-r--r--translations/BinaryFun-de.ts4
2 files changed, 49 insertions, 20 deletions
diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml
index 9cfd4db..bd6d99e 100644
--- a/qml/pages/FirstPage.qml
+++ b/qml/pages/FirstPage.qml
@@ -2,15 +2,36 @@ import QtQuick 2.0
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]
+ ["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;
+ pads[row][index] = checked ? "1" : "0";
+ const typedBinary = parseInt(pads[row].join(""));
+ const neededBinary = parseInt(dec2bin(eval("rand_" + row).text));
+ correctRows[row.toString()] = typedBinary === neededBinary;
+ console.log(JSON.stringify(correctRows));
+ if (Object.keys(correctRows).every(function(k){ return correctRows[k] }))
+ gameover.text = "Yeeha!";
+ else
+ gameover.text = "";
+ }
+
+ function dec2bin(dec){
+ return parseInt((dec >>> 0).toString(2));
}
function getRandom() {
@@ -32,7 +53,7 @@ Page {
contentHeight: column.height
- Column {
+ Column {
id: column
width: page.width
spacing: Theme.paddingLarge
@@ -49,11 +70,11 @@ Page {
// UGLINESS STARTS IN 3.. 2.. 1.. !
Switch {
- onClicked: check(0, 4, checked)
+ onClicked: check(0, 0, checked)
}
Switch {
- onClicked: check(0, 3, checked)
+ onClicked: check(0, 1, checked)
}
Switch {
@@ -61,21 +82,22 @@ Page {
}
Switch {
- onClicked: check(0, 1, checked)
+ onClicked: check(0, 3, checked)
}
Label {
+ id: rand_0
text: getRandom()
}
//
Switch {
- onClicked: check(1, 4, checked)
+ onClicked: check(1, 0, checked)
}
Switch {
- onClicked: check(1, 3, checked)
+ onClicked: check(1, 1, checked)
}
Switch {
@@ -83,21 +105,22 @@ Page {
}
Switch {
- onClicked: check(1, 1, checked)
+ onClicked: check(1, 3, checked)
}
Label {
+ id: rand_1
text: getRandom()
}
//
Switch {
- onClicked: check(2, 4, checked)
+ onClicked: check(2, 0, checked)
}
Switch {
- onClicked: check(2, 3, checked)
+ onClicked: check(2, 1, checked)
}
Switch {
@@ -105,21 +128,22 @@ Page {
}
Switch {
- onClicked: check(2, 1, checked)
+ onClicked: check(2, 3, checked)
}
Label {
+ id: rand_2
text: getRandom()
}
//
Switch {
- onClicked: check(3, 4, checked)
+ onClicked: check(3, 0, checked)
}
Switch {
- onClicked: check(3, 3, checked)
+ onClicked: check(3, 1, checked)
}
Switch {
@@ -127,13 +151,18 @@ Page {
}
Switch {
- onClicked: check(3, 1, checked)
+ onClicked: check(3, 3, checked)
}
Label {
+ id: rand_3
text: getRandom()
}
}
+
+ Label {
+ id: gameover
+ }
}
}
}
diff --git a/translations/BinaryFun-de.ts b/translations/BinaryFun-de.ts
index 49c680d..388fcb0 100644
--- a/translations/BinaryFun-de.ts
+++ b/translations/BinaryFun-de.ts
@@ -12,11 +12,11 @@
<name>FirstPage</name>
<message>
<source>Show Page 2</source>
- <translation>Zur Seite 2</translation>
+ <translation type="unfinished"></translation>
</message>
<message>
<source>Binary Fun</source>
- <translation>Binary Fun</translation>
+ <translation type="unfinished"></translation>
</message>
</context>
<context>