diff options
author | Marvin Borner | 2020-04-04 00:20:11 +0200 |
---|---|---|
committer | Marvin Borner | 2020-04-04 00:20:11 +0200 |
commit | f38d98d95e3b9e67f4000998474df302ebc0cf92 (patch) | |
tree | 56c672b15091e363976126e6787a1e5af6818108 | |
parent | 922b65b3eaeb975224adcdfda8a2595cd76309d5 (diff) |
Added working checking mechanism
Sorry for the previous force-push, I messed up ;)
-rw-r--r-- | BinaryFun.pro.user | 2 | ||||
-rw-r--r-- | qml/Bit.qml | 11 | ||||
-rw-r--r-- | qml/pages/FirstPage.qml | 9 |
3 files changed, 19 insertions, 3 deletions
diff --git a/BinaryFun.pro.user b/BinaryFun.pro.user index 6d77191..9c9c20a 100644 --- a/BinaryFun.pro.user +++ b/BinaryFun.pro.user @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE QtCreatorProject> -<!-- Written by QtCreator 4.9.1, 2020-04-03T17:11:41. --> +<!-- Written by QtCreator 4.9.1, 2020-04-04T00:19:47. --> <qtcreator> <data> <variable>EnvironmentId</variable> diff --git a/qml/Bit.qml b/qml/Bit.qml index 3e7dd7b..7bb63ce 100644 --- a/qml/Bit.qml +++ b/qml/Bit.qml @@ -11,6 +11,7 @@ Loader { width: Theme.paddingLarge * 2 height: width onClicked: root.check(index) + Component.onCompleted: root.matrix[index] = 0 } } @@ -22,7 +23,15 @@ Loader { height: width horizontalAlignment: TextInput.AlignHCenter verticalAlignment: TextInput.AlignVCenter - Component.onCompleted: this.text = "0" + Component.onCompleted: { + if (index > bits) { + var num = Math.floor(Math.random() * Math.pow(bits - 1, 2)) + 1; + this.text = num; + root.matrix[index] = num; + } else { + this.text = "?"; + } + } } } diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml index 8ffa6e1..8df939f 100644 --- a/qml/pages/FirstPage.qml +++ b/qml/pages/FirstPage.qml @@ -26,7 +26,7 @@ ApplicationWindow { Column { property int bits: 4 - property var matrix: new Array(Math.pow(bits + 1, 2)); + property var matrix: new Array(Math.pow(bits + 1, 2)) id: root width: page.width @@ -39,6 +39,13 @@ ApplicationWindow { function check(index) { root.matrix[index] ^= 1; + console.log(root.matrix); + console.log(Number(root.matrix.slice(5, 9).join("")).toString()); + console.log(parseInt((root.matrix[9] >>> 0).toString(2))); + + if (Number(root.matrix.slice(5, 9).join("")).toString() === (root.matrix[9] >>> 0).toString(2)) { + console.log("YAY"); + } } Grid { |