aboutsummaryrefslogtreecommitdiffhomepage
path: root/qml/pages
diff options
context:
space:
mode:
authorMarvin Borner2019-01-06 18:27:13 +0100
committerMarvin Borner2019-01-06 18:27:13 +0100
commit290dfe49b1070a9e025a5c9bb760a7122849985d (patch)
tree0db5bc53a434f4f6b1a38f84b330d8caa314b0d4 /qml/pages
parent1795e75c6540cdc88a3bfcf51c05a4881e6dd3e4 (diff)
Added timer and replay button
Diffstat (limited to 'qml/pages')
-rw-r--r--qml/pages/FirstPage.qml49
1 files changed, 44 insertions, 5 deletions
diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml
index bd6d99e..d45208f 100644
--- a/qml/pages/FirstPage.qml
+++ b/qml/pages/FirstPage.qml
@@ -22,12 +22,24 @@ Page {
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] }))
+ 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 = "Yeeha!";
- else
+ newGameBtn.visible = true;
+ timer.stop()
+ }
+ else {
gameover.text = "";
+ newGameBtn.visible = false;
+ timer.start()
+ }
}
function dec2bin(dec){
@@ -38,6 +50,10 @@ Page {
return Math.floor(Math.random() * 16);
}
+ function newGame() {
+ pageStack.push(Qt.resolvedUrl("FirstPage.qml"))
+ }
+
id: page
allowedOrientations: Orientation.All
@@ -53,7 +69,7 @@ Page {
contentHeight: column.height
- Column {
+ Column {
id: column
width: page.width
spacing: Theme.paddingLarge
@@ -160,8 +176,31 @@ Page {
}
}
+ Button {
+ id: newGameBtn
+ text: "New Game!"
+ visible: false
+ anchors.horizontalCenter: parent.horizontalCenter
+ onClicked: newGame()
+ }
+
Label {
id: gameover
+ anchors.horizontalCenter: parent.horizontalCenter
+ }
+
+ Label {
+ id: timerLabel
+ text: "0"
+ anchors.horizontalCenter: parent.horizontalCenter
+ }
+
+ Timer {
+ id: timer
+ interval: 10
+ running: true
+ repeat: true
+ onTriggered: timerLabel.text = (parseInt(timerLabel.text) + 1) / 100
}
}
}