2
import QtMultimedia 5.0
3
import "binarydict.js" as Wordlist
4
import QtQuick.Particles 2.0
5
import QtQuick.LocalStorage 2.0
9
property bool flipped: false
10
property variant db: null
11
width: 48 * 7 + 2 * 7 + 2
12
height: 48 * 10 + 2 * 10 + 50
15
origin.x: flipable.width/2
16
origin.y: flipable.height/2
17
axis.x: 0; axis.y: 1; axis.z: 0 // set axis.y to 1 to rotate around y-axis
18
angle: 0 // the default angle
21
Component.onCompleted: {
22
var db = LocalStorage.openDatabaseSync("dropping-letters", "1.0", "Dropping Letters", 1000);
23
db.transaction(function(tx) {
24
// Create the database if it doesn't already exist
25
tx.executeSql('CREATE TABLE IF NOT EXISTS Scores(score INT, time TEXT)');
26
var res = tx.executeSql('SELECT score from Scores order by score DESC LIMIT 1');
27
if (res.rows.length === 0) {
28
bestscore.updateScore(0);
30
bestscore.updateScore(res.rows.item(0).score);
38
PropertyChanges { target: rotation; angle: 180 }
39
when: flipable.flipped
43
when: !flipable.flipped
49
NumberAnimation { target: rotation; property: "angle"; duration: 200 }
56
width: 48 * 7 + 2 * 7 + 2
57
height: 48 * 10 + 2 * 10 + 50
60
anchors.centerIn: parent
63
model: ["DROP", "PING", "LETT", "ERS "]
66
property int lineIndex: index
67
property string modelString: modelData
69
model: modelData.split("")
78
anchors.centerIn: parent
79
font.pixelSize: titleletter.height * 0.6
81
font.family: "Helvetica"
84
State { name: "showing"; when: flipable.state == "front"
85
PropertyChanges { target: titleletter; y: 0 }
87
State { name: "notshowing"; when: flipable.state != "front"
88
PropertyChanges { target: titleletter; y: -500 }
94
duration: (35 * parent.modelString.length * (4-parent.lineIndex)) + (
96
NumberAnimation { easing.type: Easing.OutQuart }
107
anchors.top: logo.bottom
108
anchors.topMargin: 15
109
anchors.horizontalCenter: logo.horizontalCenter
115
property int bestsofar: 0
117
anchors.top: playbutton.bottom
118
anchors.topMargin: 15
119
anchors.horizontalCenter: logo.horizontalCenter
122
function updateScore(score) {
123
if (score >= bestscore.bestsofar) {
124
bestscore.text = "Best score: " + score;
125
bestscore.bestsofar = score;
131
enabled: !flipable.flipped
134
for (var i=0; i<7; i++) {
135
lm.append({'letters': [] });
137
flipable.flipped = true
145
width: 48 * 7 + 2 * 7 + 2
146
height: 48 * 10 + 2 * 10 + 50
147
property var selectedItems: []
150
import re; fp=open('/usr/share/dict/words');
151
shorts=[re.sub('[^a-zA-Z]','',x.lower().strip()) for x in fp if len(x)<7];
152
from collections import Counter; c=Counter(''.join(shorts)); least=c.most_common()[-1][1];
153
print dict([(x.upper(),c[x]/least) for x in c])
155
property variant letterFreqs: {
156
'A': 66, 'C': 22, 'B': 19, 'E': 72, 'D': 28, 'G': 18, 'F': 12, 'I': 41, 'H': 20,
157
'K': 14, 'J': 4, 'M': 22, 'L': 40, 'O': 48, 'N': 35, 'Q': 1, 'P': 22, 'S': 75,
158
'R': 43, 'U': 26, 'T': 37, 'W': 13, 'V': 7, 'Y': 19, 'X': 3, 'Z': 4
160
property variant letterScores: {
161
"A":1,"B":3,"C":3,"D":2,"E":1,"F":4,"G":2,"H":4,"I":1,"J":8,"K":5,"L":1,
162
"M":3,"N":1,"O":1,"P":3,"Q":10,"R":1,"S":1,"T":1,"U":1,"V":4,"W":4,"X":8,
165
property int score: 0
167
function getRandomWeightedLetter() {
168
// could work out sumOfWeights once, but this is easier to understand
169
var sumOfWeights = 0;
170
for (var k in main.letterFreqs) { sumOfWeights += main.letterFreqs[k]; }
171
var selection = Math.floor(Math.random() * sumOfWeights);
172
for (var k in main.letterFreqs) {
173
if (selection < main.letterFreqs[k]) return k;
174
selection -= main.letterFreqs[k];
180
source: "Easy Lemon 60 second.ogg"
182
onStopped: music.play()
183
muted: !volume.audible
188
source: "407__tictacshutup__click-1-off-click.ogg"
190
muted: !volume.audible
195
source: "80921__justinbw__buttonchime02up.ogg"
197
muted: !volume.audible
202
source: "106727__kantouth__cartoon-bing-low.ogg"
204
muted: !volume.audible
209
source: "45137__dj-chronos__dark-church-bell.ogg"
212
flipable.flipped = false
214
muted: !volume.audible
223
anchors.left: main.left
224
anchors.top: main.top
227
property int frame: 0
228
property bool reverse: false
229
property bool audible: true
232
source: "volume-sprite.png"
233
x: -parent.frame * parent.width
241
if (parent.reverse) {
243
if (parent.frame == 0) volumetimer.running = false;
246
if (parent.frame == 5) volumetimer.running = false;
253
if (!parent.audible) {
255
parent.reverse = true;
256
volumetimer.running = true;
257
parent.audible = true;
260
parent.reverse = false;
261
volumetimer.running = true;
262
parent.audible = false;
270
anchors.centerIn: parent
272
font.pixelSize: main.height
280
anchors.right: main.right
281
anchors.top: main.top
287
anchors.centerIn: parent
289
text: "" + main.score
303
SequentialAnimation {
326
running: flipable.flipped
328
triggeredOnStart: true
330
var idx = Math.round(Math.random() * (lm.count - 1));
331
lm.get(idx).letters.append({ letter: main.getRandomWeightedLetter() });
332
if (lm.get(idx).letters.count >= 10) {
335
var db = LocalStorage.openDatabaseSync("dropping-letters", "1.0", "Dropping Letters", 1000);
336
db.transaction(function(tx) {
337
tx.executeSql("insert into Scores values (?,?)", [main.score, 0]);
338
bestscore.updateScore(main.score);
349
anchors.top: main.top
350
anchors.left: main.left
351
anchors.right: playarea.right
352
anchors.bottom: playarea.top
353
anchors.rightMargin: 50
354
anchors.leftMargin: 50
355
anchors.bottomMargin: 2
357
color: accum.text == "" ? "#a4a4a4" : (accum.isValid ? "green" : "red")
360
anchors.centerIn: parent
363
font.pixelSize: parent.height * 0.7
364
font.family: "Helvetica"
365
property bool isValid: false
366
function findBinaryWord( word ) {
367
var bd = Wordlist.wordlist;
369
// Don't search if there's nothing to look through
373
// Get the number of words in the dictionary bin
374
var words = bd[l].length / l,
375
// The low point from where we're starting the binary search
377
// The max high point
379
// And the precise middle of the search
380
mid = Math.floor( words / 2 );
381
// We continue to look until we reach a final word
382
while ( high >= low ) {
383
// Grab the word at our current position
384
var found = bd[l].substr( l * mid, l );
385
// If we've found the word, stop now
386
if ( word === found ) {
389
// Otherwise, compare
390
// If we're too high, move lower
391
if ( word < found ) {
393
// If we're too low, go higher
397
// And find the new search point
398
mid = Math.floor( (low + high) / 2 );
404
accum.isValid = findBinaryWord(accum.text);
412
var thisscore = 0, wordlength = accum.text.length;
415
// tell the boxes to destroy themselves
416
main.selectedItems.forEach(function(b) {
417
thisscore += main.letterScores[b.containedLetter];
420
main.selectedItems = [];
421
main.score += thisscore * wordlength;
422
scoredisplay.text = "" + (thisscore * wordlength);
423
showscoredisplay.start();
427
main.selectedItems.forEach(function(b) { b.selected = false; })
428
main.selectedItems = [];
436
anchors.top: main.top
437
anchors.topMargin: 50
438
anchors.left: main.left
439
anchors.leftMargin: 2
445
NumberAnimation { properties: "y"; easing.type: Easing.OutBounce; duration: 1000 }
448
NumberAnimation { properties: "y"; easing.type: Easing.OutBounce }
450
property int idx: index
452
height: main.height - 52
458
property bool selected: false
459
property int idx: index
460
property string containedLetter: letter
467
if (lm.get(parent.idx).letters.count >= 10) {
469
} else if (!selected) {
471
} else if (accum.isValid) {
478
y: main.height + box.height
480
anchors.centerIn: parent
482
font.pixelSize: box.height * 0.6
484
font.family: "Helvetica"
491
accum.text += letter;
493
main.selectedItems[main.selectedItems.length] = box;
495
if (box === main.selectedItems[main.selectedItems.length - 1]) {
496
main.selectedItems.pop(main.selectedItems.length - 1);
497
box.selected = false;
498
accum.text = accum.text.substr(0, accum.text.length - 1);
503
Behavior on opacity {
504
SequentialAnimation {
505
ScriptAction { script: pulseEmitter.burst(1000); }
506
NumberAnimation { properties:"opacity"; duration: 500 }
507
ScriptAction { script: lm.get(box.parent.idx).letters.remove(box.idx); }
511
State { name: "alive" },
514
PropertyChanges { target: box; opacity: 0 }
521
anchors.centerIn: parent
524
source: "redStar.png"
535
velocity: AngleDirection { magnitude: 256; angleVariation: 360; magnitudeVariation: 200; }
b'\\ No newline at end of file'