aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMarvin Borner2020-04-04 14:18:37 +0200
committerMarvin Borner2020-04-04 14:18:37 +0200
commit0574b4b19fc6592453a0323e2f927925d98ed76c (patch)
treeadfc4f9276749a779cbabecab62d29f40de9e69b
parentf38d98d95e3b9e67f4000998474df302ebc0cf92 (diff)
Working win-check for every row
-rw-r--r--qml/pages/FirstPage.qml23
1 files changed, 18 insertions, 5 deletions
diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml
index 8df939f..d19d1dd 100644
--- a/qml/pages/FirstPage.qml
+++ b/qml/pages/FirstPage.qml
@@ -26,6 +26,7 @@ ApplicationWindow {
Column {
property int bits: 4
+ property var correct: new Array(bits)
property var matrix: new Array(Math.pow(bits + 1, 2))
id: root
@@ -37,14 +38,26 @@ ApplicationWindow {
title: "Binary Fun"
}
+ function nearest(number) {
+ if (number % (bits + 1) === 0) {
+ return number
+ } else {
+ return number - (number % (bits + 1))
+ }
+ }
+
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)));
+ var near = nearest(index);
+
+ if (Number(root.matrix.slice(near, near + bits).join("")).toString() === (root.matrix[near + bits] >>> 0).toString(2)) {
+ correct[near / (bits + 1) - 1] = 1;
+ } else {
+ correct[near / (bits + 1) - 1] = 0;
+ }
- if (Number(root.matrix.slice(5, 9).join("")).toString() === (root.matrix[9] >>> 0).toString(2)) {
- console.log("YAY");
+ if (correct.filter(function(i) { return i === 1 }).length === bits) {
+ console.log("WON!!");
}
}