aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMarvin Borner2020-04-04 20:24:18 +0200
committerMarvin Borner2020-04-04 20:24:18 +0200
commit81cc34bfcc8d7ec695a4d70c4c1c82b9035bf272 (patch)
treefd885f80b2670c29924f79b6b54343ed50b65d9a
parentd452393fdc957503b0387932f442851265175f08 (diff)
Different modes, fixed timer, zero doubletap, etc..
-rw-r--r--BinaryFun.pro3
-rw-r--r--qml/BinaryFun.qml2
-rw-r--r--qml/Bit.qml10
-rw-r--r--qml/cover/CoverPage.qml12
-rw-r--r--qml/pages/FirstPage.qml110
-rw-r--r--qml/pages/Game.qml124
-rw-r--r--qml/pages/LeaderBoard.qml2
-rw-r--r--qml/pages/Menu.qml64
-rw-r--r--translations/BinaryFun-de.ts37
-rw-r--r--translations/BinaryFun.ts33
10 files changed, 259 insertions, 138 deletions
diff --git a/BinaryFun.pro b/BinaryFun.pro
index d75cf78..2450f51 100644
--- a/BinaryFun.pro
+++ b/BinaryFun.pro
@@ -19,7 +19,8 @@ SOURCES += src/BinaryFun.cpp
DISTFILES += qml/BinaryFun.qml \
qml/Bit.qml \
qml/cover/CoverPage.qml \
- qml/pages/FirstPage.qml \
+ qml/pages/Game.qml \
+ qml/pages/Menu.qml \
rpm/BinaryFun.changes.in \
rpm/BinaryFun.changes.run.in \
rpm/BinaryFun.spec \
diff --git a/qml/BinaryFun.qml b/qml/BinaryFun.qml
index 829cf95..9378223 100644
--- a/qml/BinaryFun.qml
+++ b/qml/BinaryFun.qml
@@ -4,7 +4,7 @@ import "pages"
ApplicationWindow
{
- initialPage: Component { FirstPage { } }
+ initialPage: Component { Menu { } }
cover: Qt.resolvedUrl("cover/CoverPage.qml")
allowedOrientations: defaultAllowedOrientations
}
diff --git a/qml/Bit.qml b/qml/Bit.qml
index c017760..be6d0f6 100644
--- a/qml/Bit.qml
+++ b/qml/Bit.qml
@@ -23,6 +23,7 @@ Loader {
id: bit_index
Label {
id: bit_label
+ color: Theme.highlightColor
text: parent.index.toString()
width: Theme.paddingLarge * 2
height: width
@@ -36,19 +37,18 @@ Loader {
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]);
+ transformed.unshift((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 {
+ } else if (index !== bits){
var num = Math.floor(Math.random() * (Math.pow(2, bits) - 1)) + 1;
this.text = num;
root.matrix[index] = num;
+ } else {
+ this.text = "0/1";
}
}
}
diff --git a/qml/cover/CoverPage.qml b/qml/cover/CoverPage.qml
index cf58ea4..f0c1ec2 100644
--- a/qml/cover/CoverPage.qml
+++ b/qml/cover/CoverPage.qml
@@ -7,16 +7,4 @@ CoverBackground {
anchors.centerIn: parent
text: qsTr("Binary Fun")
}
-
- CoverActionList {
- id: coverAction
-
- CoverAction {
- iconSource: "image://theme/icon-cover-next"
- }
-
- CoverAction {
- iconSource: "image://theme/icon-cover-pause"
- }
- }
}
diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml
deleted file mode 100644
index bfc1ba0..0000000
--- a/qml/pages/FirstPage.qml
+++ /dev/null
@@ -1,110 +0,0 @@
-import QtQuick 2.2
-import Sailfish.Silica 1.0
-import ".."
-
-ApplicationWindow {
- initialPage: pageComponent
-
- Component {
- id: pageComponent
-
- Page {
- id: page
- allowedOrientations: Orientation.All
-
- SilicaFlickable {
- anchors.fill: parent
- contentHeight: root.height
-
- PullDownMenu {
- MenuItem {
- text: qsTr("Leaderboard")
- onClicked: pageStack.push(Qt.resolvedUrl("LeaderBoard.qml"))
- }
- }
-
- Column {
- property int bits: 4
- property var correct: new Array(bits)
- property var matrix: new Array(Math.pow(bits + 1, 2))
-
- id: root
- width: page.width
- height: page.height
- spacing: Theme.paddingLarge
-
- PageHeader {
- title: qsTr("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;
- 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;
- 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) {
- info_label.text = "Yeeehaa!";
- timer.running = false;
- }
- }
-
- Grid {
- property int row: 0
-
- id: grid
- anchors.bottom: page.bottom
- columns: root.bits + 1
- rows: root.bits + 1
- Repeater {
- id: repeater
- model: Math.pow(root.bits + 1, 2)
- delegate: Bit {
- bits: root.bits
- index: modelData
- width: page.width / (root.bits + 1)
- }
- }
- }
-
- 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()
- }
- }
- }
- }
- }
-}
diff --git a/qml/pages/Game.qml b/qml/pages/Game.qml
new file mode 100644
index 0000000..8f95f58
--- /dev/null
+++ b/qml/pages/Game.qml
@@ -0,0 +1,124 @@
+import QtQuick 2.2
+import Sailfish.Silica 1.0
+import ".."
+
+Page {
+ property int bits: 0 // gets passed by previous page
+
+ id: page
+ allowedOrientations: Orientation.All
+
+ SilicaFlickable {
+ anchors.fill: parent
+ contentHeight: root.height
+
+ /*PullDownMenu {
+ MenuItem {
+ text: qsTr("Leaderboard")
+ onClicked: pageStack.push(Qt.resolvedUrl("LeaderBoard.qml"))
+ }
+ }*/
+
+ Column {
+ property int bits: page.bits
+ property var correct: new Array(bits)
+ property var matrix: new Array(Math.pow(bits + 1, 2))
+ property var start_time: 0
+
+ id: root
+ width: page.width
+ height: page.height
+ spacing: Theme.paddingLarge
+
+ PageHeader {
+ title: qsTr("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;
+ var near = nearest(index);
+ var current_score = parseInt(info_label.text.substr(0, info_label.text.indexOf('/')))
+
+ 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 = current_score + 1 + " / " + root.bits;
+ } else {
+ if (correct[near / (bits + 1) - 1] === 1) {
+ info_label.text = current_score - 1 + " / " + root.bits;
+ }
+
+ correct[near / (bits + 1) - 1] = 0;
+ }
+
+ if (correct.filter(function(i) { return i === 1 }).length === bits) {
+ info_label.text = "Yeeehaaw!";
+ timer_label.text = ((new Date().getTime() - start_time) / 1000) + "s - Not bad!"
+ timer.running = false;
+ new_game.visible = true;
+ }
+ }
+
+ Grid {
+ property int row: 0
+
+ id: grid
+ anchors.bottom: page.bottom
+ columns: root.bits + 1
+ rows: root.bits + 1
+ Repeater {
+ id: repeater
+ model: Math.pow(root.bits + 1, 2)
+ delegate: Bit {
+ bits: root.bits
+ index: modelData
+ width: page.width / (root.bits + 1)
+ }
+ }
+ }
+
+ 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: "0s"
+ anchors.horizontalCenter: parent.horizontalCenter
+ // anchors.top: won.bottom
+ anchors.bottom: page.bottom
+ }
+
+ Timer {
+ id: timer
+ interval: 1000
+ running: true
+ repeat: true
+ onTriggered: {
+ if (root.start_time === 0)
+ root.start_time = (new Date()).getTime();
+ timer_label.text = parseInt(timer_label.text.substr(0, timer_label.text.indexOf('s'))) + 1 + "s";
+ }
+ }
+
+ Button {
+ id: new_game
+ text: qsTr("Play again!")
+ visible: false
+ anchors.horizontalCenter: parent.horizontalCenter
+ onClicked: pageStack.replace(Qt.resolvedUrl("Game.qml"), {bits: root.bits})
+ }
+ }
+ }
+}
diff --git a/qml/pages/LeaderBoard.qml b/qml/pages/LeaderBoard.qml
index 596b0e2..93dad0e 100644
--- a/qml/pages/LeaderBoard.qml
+++ b/qml/pages/LeaderBoard.qml
@@ -1,4 +1,4 @@
-import QtQuick 2.0
+import QtQuick 2.2
import Sailfish.Silica 1.0
Page {
diff --git a/qml/pages/Menu.qml b/qml/pages/Menu.qml
new file mode 100644
index 0000000..39de258
--- /dev/null
+++ b/qml/pages/Menu.qml
@@ -0,0 +1,64 @@
+import QtQuick 2.2
+import Sailfish.Silica 1.0
+
+Page {
+ id: page
+ allowedOrientations: Orientation.All
+
+ SilicaFlickable {
+ anchors.fill: parent
+ contentHeight: column.height
+
+ Column {
+ id: column
+ width: page.width
+ height: page.height
+ spacing: Theme.paddingLarge
+
+ PageHeader {
+ title: qsTr("Binary Fun")
+ }
+
+ ButtonLayout {
+ anchors.horizontalCenter: parent.horizontalCenter
+ anchors.verticalCenter: parent.verticalCenter
+ rowSpacing: Theme.paddingLarge * 2
+
+ Button {
+ text: qsTr("Very easy (2 Bit)")
+ onClicked: {
+ pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 2});
+ }
+ }
+
+ Button {
+ text: qsTr("Easy (4 Bit)")
+ onClicked: {
+ pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 4});
+ }
+ }
+
+ Button {
+ text: qsTr("Medium (6 Bit)")
+ onClicked: {
+ pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 6});
+ }
+ }
+
+ Button {
+ text: qsTr("Hard (8 Bit)")
+ onClicked: {
+ pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 8});
+ }
+ }
+
+ Button {
+ text: qsTr("Godlike (10 Bit)")
+ onClicked: {
+ pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 10});
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/translations/BinaryFun-de.ts b/translations/BinaryFun-de.ts
index 4c92f47..fc5adab 100644
--- a/translations/BinaryFun-de.ts
+++ b/translations/BinaryFun-de.ts
@@ -9,15 +9,15 @@
</message>
</context>
<context>
- <name>FirstPage</name>
- <message>
- <source>Leaderboard</source>
- <translation type="unfinished"></translation>
- </message>
+ <name>Game</name>
<message>
<source>Binary Fun</source>
<translation type="unfinished">Binary Fun</translation>
</message>
+ <message>
+ <source>Play again!</source>
+ <translation type="unfinished"></translation>
+ </message>
</context>
<context>
<name>LeaderBoard</name>
@@ -26,4 +26,31 @@
<translation type="unfinished"></translation>
</message>
</context>
+<context>
+ <name>Menu</name>
+ <message>
+ <source>Binary Fun</source>
+ <translation type="unfinished">Binary Fun</translation>
+ </message>
+ <message>
+ <source>Easy (4 Bit)</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Medium (6 Bit)</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Hard (8 Bit)</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Very easy (2 Bit)</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Godlike (10 Bit)</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
</TS>
diff --git a/translations/BinaryFun.ts b/translations/BinaryFun.ts
index cdbdf90..1201108 100644
--- a/translations/BinaryFun.ts
+++ b/translations/BinaryFun.ts
@@ -9,13 +9,13 @@
</message>
</context>
<context>
- <name>FirstPage</name>
+ <name>Game</name>
<message>
- <source>Leaderboard</source>
+ <source>Binary Fun</source>
<translation type="unfinished"></translation>
</message>
<message>
- <source>Binary Fun</source>
+ <source>Play again!</source>
<translation type="unfinished"></translation>
</message>
</context>
@@ -26,4 +26,31 @@
<translation type="unfinished"></translation>
</message>
</context>
+<context>
+ <name>Menu</name>
+ <message>
+ <source>Binary Fun</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Easy (4 Bit)</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Medium (6 Bit)</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Hard (8 Bit)</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Very easy (2 Bit)</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Godlike (10 Bit)</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
</TS>