aboutsummaryrefslogtreecommitdiffhomepage
path: root/qml
diff options
context:
space:
mode:
authorMarvin Borner2020-04-04 18:42:25 +0200
committerMarvin Borner2020-04-04 18:42:25 +0200
commitd452393fdc957503b0387932f442851265175f08 (patch)
treea00861bef15b4975f7ae616bb141c13c4a5895d6 /qml
parent0574b4b19fc6592453a0323e2f927925d98ed76c (diff)
Sooo many things - you wouldn't believe it!
Diffstat (limited to 'qml')
-rw-r--r--qml/Bit.qml25
-rw-r--r--qml/pages/FirstPage.qml37
2 files changed, 54 insertions, 8 deletions
diff --git a/qml/Bit.qml b/qml/Bit.qml
index 7bb63ce..c017760 100644
--- a/qml/Bit.qml
+++ b/qml/Bit.qml
@@ -15,21 +15,40 @@ Loader {
}
}
+ function pad(n, width) {
+ return n.length >= width ? n : new Array(width - n.length + 1).join('0') + n;
+ }
+
Component {
id: bit_index
Label {
+ id: bit_label
text: parent.index.toString()
width: Theme.paddingLarge * 2
height: width
horizontalAlignment: TextInput.AlignHCenter
verticalAlignment: TextInput.AlignVCenter
Component.onCompleted: {
+ // This code could definitely be improved ;)
if (index > bits) {
- var num = Math.floor(Math.random() * Math.pow(bits - 1, 2)) + 1;
+ grid.row++;
+
+ var indices = root.matrix.slice(0, bits);
+ var transformed = [];
+ indices.forEach(function(elem) {
+ console.log(elem + " " + pad((parseInt(elem) >>> 0).toString(2), bits));
+ transformed.push((pad((parseInt(elem) >>> 0).toString(2), bits))[grid.row - 1]);
+ });
+
+ var transformed_num = parseInt(transformed.join(""), 2);
+ this.text = transformed_num;
+ root.matrix[index] = transformed_num;
+ console.log(indices);
+ console.log(transformed);
+ } else {
+ var num = Math.floor(Math.random() * (Math.pow(2, bits) - 1)) + 1;
this.text = num;
root.matrix[index] = num;
- } else {
- this.text = "?";
}
}
}
diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml
index d19d1dd..bfc1ba0 100644
--- a/qml/pages/FirstPage.qml
+++ b/qml/pages/FirstPage.qml
@@ -19,8 +19,7 @@ ApplicationWindow {
PullDownMenu {
MenuItem {
text: qsTr("Leaderboard")
- onClicked: pageStack.push(Qt.resolvedUrl(
- "LeaderBoard.qml"))
+ onClicked: pageStack.push(Qt.resolvedUrl("LeaderBoard.qml"))
}
}
@@ -35,7 +34,7 @@ ApplicationWindow {
spacing: Theme.paddingLarge
PageHeader {
- title: "Binary Fun"
+ title: qsTr("Binary Fun")
}
function nearest(number) {
@@ -52,18 +51,22 @@ ApplicationWindow {
if (Number(root.matrix.slice(near, near + bits).join("")).toString() === (root.matrix[near + bits] >>> 0).toString(2)) {
correct[near / (bits + 1) - 1] = 1;
+ info_label.text = parseInt(info_label.text.substr(0, info_label.text.indexOf('/'))) + 1 + " / " + root.bits;
} else {
correct[near / (bits + 1) - 1] = 0;
}
if (correct.filter(function(i) { return i === 1 }).length === bits) {
- console.log("WON!!");
+ info_label.text = "Yeeehaa!";
+ timer.running = false;
}
}
Grid {
+ property int row: 0
+
id: grid
- anchors.verticalCenter: parent.verticalCenter
+ anchors.bottom: page.bottom
columns: root.bits + 1
rows: root.bits + 1
Repeater {
@@ -76,6 +79,30 @@ ApplicationWindow {
}
}
}
+
+ Label {
+ id: info_label
+ text: "0 / " + root.bits
+ anchors.horizontalCenter: parent.horizontalCenter
+ // anchors.top: grid.bottom
+ anchors.bottom: page.bottom
+ }
+
+ Label {
+ id: timer_label
+ text: "0.0"
+ anchors.horizontalCenter: parent.horizontalCenter
+ // anchors.top: won.bottom
+ anchors.bottom: page.bottom
+ }
+
+ Timer {
+ id: timer
+ interval: 1
+ running: true
+ repeat: true
+ onTriggered: timer_label.text = (parseFloat(timer_label.text) + 0.01).toFixed(2).toString()
+ }
}
}
}