Skip to content
This repository was archived by the owner on May 24, 2023. It is now read-only.

Commit 81cc34b

Browse files
committed
Different modes, fixed timer, zero doubletap, etc..
1 parent d452393 commit 81cc34b

10 files changed

Lines changed: 259 additions & 138 deletions

File tree

BinaryFun.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ SOURCES += src/BinaryFun.cpp
1919
DISTFILES += qml/BinaryFun.qml \
2020
qml/Bit.qml \
2121
qml/cover/CoverPage.qml \
22-
qml/pages/FirstPage.qml \
22+
qml/pages/Game.qml \
23+
qml/pages/Menu.qml \
2324
rpm/BinaryFun.changes.in \
2425
rpm/BinaryFun.changes.run.in \
2526
rpm/BinaryFun.spec \

qml/BinaryFun.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "pages"
44

55
ApplicationWindow
66
{
7-
initialPage: Component { FirstPage { } }
7+
initialPage: Component { Menu { } }
88
cover: Qt.resolvedUrl("cover/CoverPage.qml")
99
allowedOrientations: defaultAllowedOrientations
1010
}

qml/Bit.qml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Loader {
2323
id: bit_index
2424
Label {
2525
id: bit_label
26+
color: Theme.highlightColor
2627
text: parent.index.toString()
2728
width: Theme.paddingLarge * 2
2829
height: width
@@ -36,19 +37,18 @@ Loader {
3637
var indices = root.matrix.slice(0, bits);
3738
var transformed = [];
3839
indices.forEach(function(elem) {
39-
console.log(elem + " " + pad((parseInt(elem) >>> 0).toString(2), bits));
40-
transformed.push((pad((parseInt(elem) >>> 0).toString(2), bits))[grid.row - 1]);
40+
transformed.unshift((pad((parseInt(elem) >>> 0).toString(2), bits))[grid.row - 1]);
4141
});
4242

4343
var transformed_num = parseInt(transformed.join(""), 2);
4444
this.text = transformed_num;
4545
root.matrix[index] = transformed_num;
46-
console.log(indices);
47-
console.log(transformed);
48-
} else {
46+
} else if (index !== bits){
4947
var num = Math.floor(Math.random() * (Math.pow(2, bits) - 1)) + 1;
5048
this.text = num;
5149
root.matrix[index] = num;
50+
} else {
51+
this.text = "0/1";
5252
}
5353
}
5454
}

qml/cover/CoverPage.qml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,4 @@ CoverBackground {
77
anchors.centerIn: parent
88
text: qsTr("Binary Fun")
99
}
10-
11-
CoverActionList {
12-
id: coverAction
13-
14-
CoverAction {
15-
iconSource: "image://theme/icon-cover-next"
16-
}
17-
18-
CoverAction {
19-
iconSource: "image://theme/icon-cover-pause"
20-
}
21-
}
2210
}

qml/pages/FirstPage.qml

Lines changed: 0 additions & 110 deletions
This file was deleted.

qml/pages/Game.qml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import QtQuick 2.2
2+
import Sailfish.Silica 1.0
3+
import ".."
4+
5+
Page {
6+
property int bits: 0 // gets passed by previous page
7+
8+
id: page
9+
allowedOrientations: Orientation.All
10+
11+
SilicaFlickable {
12+
anchors.fill: parent
13+
contentHeight: root.height
14+
15+
/*PullDownMenu {
16+
MenuItem {
17+
text: qsTr("Leaderboard")
18+
onClicked: pageStack.push(Qt.resolvedUrl("LeaderBoard.qml"))
19+
}
20+
}*/
21+
22+
Column {
23+
property int bits: page.bits
24+
property var correct: new Array(bits)
25+
property var matrix: new Array(Math.pow(bits + 1, 2))
26+
property var start_time: 0
27+
28+
id: root
29+
width: page.width
30+
height: page.height
31+
spacing: Theme.paddingLarge
32+
33+
PageHeader {
34+
title: qsTr("Binary Fun")
35+
}
36+
37+
function nearest(number) {
38+
if (number % (bits + 1) === 0) {
39+
return number
40+
} else {
41+
return number - (number % (bits + 1))
42+
}
43+
}
44+
45+
function check(index) {
46+
root.matrix[index] ^= 1;
47+
var near = nearest(index);
48+
var current_score = parseInt(info_label.text.substr(0, info_label.text.indexOf('/')))
49+
50+
if (Number(root.matrix.slice(near, near + bits).join("")).toString() === (root.matrix[near + bits] >>> 0).toString(2)) {
51+
correct[near / (bits + 1) - 1] = 1;
52+
info_label.text = current_score + 1 + " / " + root.bits;
53+
} else {
54+
if (correct[near / (bits + 1) - 1] === 1) {
55+
info_label.text = current_score - 1 + " / " + root.bits;
56+
}
57+
58+
correct[near / (bits + 1) - 1] = 0;
59+
}
60+
61+
if (correct.filter(function(i) { return i === 1 }).length === bits) {
62+
info_label.text = "Yeeehaaw!";
63+
timer_label.text = ((new Date().getTime() - start_time) / 1000) + "s - Not bad!"
64+
timer.running = false;
65+
new_game.visible = true;
66+
}
67+
}
68+
69+
Grid {
70+
property int row: 0
71+
72+
id: grid
73+
anchors.bottom: page.bottom
74+
columns: root.bits + 1
75+
rows: root.bits + 1
76+
Repeater {
77+
id: repeater
78+
model: Math.pow(root.bits + 1, 2)
79+
delegate: Bit {
80+
bits: root.bits
81+
index: modelData
82+
width: page.width / (root.bits + 1)
83+
}
84+
}
85+
}
86+
87+
Label {
88+
id: info_label
89+
text: "0 / " + root.bits
90+
anchors.horizontalCenter: parent.horizontalCenter
91+
// anchors.top: grid.bottom
92+
anchors.bottom: page.bottom
93+
}
94+
95+
Label {
96+
id: timer_label
97+
text: "0s"
98+
anchors.horizontalCenter: parent.horizontalCenter
99+
// anchors.top: won.bottom
100+
anchors.bottom: page.bottom
101+
}
102+
103+
Timer {
104+
id: timer
105+
interval: 1000
106+
running: true
107+
repeat: true
108+
onTriggered: {
109+
if (root.start_time === 0)
110+
root.start_time = (new Date()).getTime();
111+
timer_label.text = parseInt(timer_label.text.substr(0, timer_label.text.indexOf('s'))) + 1 + "s";
112+
}
113+
}
114+
115+
Button {
116+
id: new_game
117+
text: qsTr("Play again!")
118+
visible: false
119+
anchors.horizontalCenter: parent.horizontalCenter
120+
onClicked: pageStack.replace(Qt.resolvedUrl("Game.qml"), {bits: root.bits})
121+
}
122+
}
123+
}
124+
}

qml/pages/LeaderBoard.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import QtQuick 2.0
1+
import QtQuick 2.2
22
import Sailfish.Silica 1.0
33

44
Page {

qml/pages/Menu.qml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import QtQuick 2.2
2+
import Sailfish.Silica 1.0
3+
4+
Page {
5+
id: page
6+
allowedOrientations: Orientation.All
7+
8+
SilicaFlickable {
9+
anchors.fill: parent
10+
contentHeight: column.height
11+
12+
Column {
13+
id: column
14+
width: page.width
15+
height: page.height
16+
spacing: Theme.paddingLarge
17+
18+
PageHeader {
19+
title: qsTr("Binary Fun")
20+
}
21+
22+
ButtonLayout {
23+
anchors.horizontalCenter: parent.horizontalCenter
24+
anchors.verticalCenter: parent.verticalCenter
25+
rowSpacing: Theme.paddingLarge * 2
26+
27+
Button {
28+
text: qsTr("Very easy (2 Bit)")
29+
onClicked: {
30+
pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 2});
31+
}
32+
}
33+
34+
Button {
35+
text: qsTr("Easy (4 Bit)")
36+
onClicked: {
37+
pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 4});
38+
}
39+
}
40+
41+
Button {
42+
text: qsTr("Medium (6 Bit)")
43+
onClicked: {
44+
pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 6});
45+
}
46+
}
47+
48+
Button {
49+
text: qsTr("Hard (8 Bit)")
50+
onClicked: {
51+
pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 8});
52+
}
53+
}
54+
55+
Button {
56+
text: qsTr("Godlike (10 Bit)")
57+
onClicked: {
58+
pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 10});
59+
}
60+
}
61+
}
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)