summaryrefslogtreecommitdiffstats
path: root/demos
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-10-29 07:56:05 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-10-29 07:56:05 (GMT)
commitca1361116bf36d1afe9cbcc293e171260978f315 (patch)
tree3f44b91b0f00a1dbcbfa9615ecce504fcfb07458 /demos
parente532322a7bb58f6b2527fa42063b5bccde318105 (diff)
downloadQt-ca1361116bf36d1afe9cbcc293e171260978f315.zip
Qt-ca1361116bf36d1afe9cbcc293e171260978f315.tar.gz
Qt-ca1361116bf36d1afe9cbcc293e171260978f315.tar.bz2
Add local highscores to SameGame
Diffstat (limited to 'demos')
-rw-r--r--demos/declarative/samegame/content/Dialog.qml2
-rwxr-xr-xdemos/declarative/samegame/content/samegame.js43
-rw-r--r--demos/declarative/samegame/samegame.qml9
3 files changed, 47 insertions, 7 deletions
diff --git a/demos/declarative/samegame/content/Dialog.qml b/demos/declarative/samegame/content/Dialog.qml
index 661257b..f9a281a 100644
--- a/demos/declarative/samegame/content/Dialog.qml
+++ b/demos/declarative/samegame/content/Dialog.qml
@@ -11,7 +11,7 @@ Rectangle {
page.opacity = 1;
}
signal closed();
- color: "white"; border.width: 1; width: myText.width + 20; height: 60;
+ color: "white"; border.width: 1; width: myText.width + 20; height: myText.height + 40;
opacity: 0
opacity: Behavior {
NumberAnimation { duration: 1000 }
diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js
index 1b81f87..4d5a6be 100755
--- a/demos/declarative/samegame/content/samegame.js
+++ b/demos/declarative/samegame/content/samegame.js
@@ -6,6 +6,7 @@ var maxIndex = maxX*maxY;
var board = new Array(maxIndex);
var tileSrc = "content/BoomBlock.qml";
var scoresURL = "http://qtfx-nokia.trolltech.com.au/samegame/scores.php";
+var scoresURL = "";
var timer;
var component = createComponent(tileSrc);
@@ -157,10 +158,8 @@ function victoryCheck()
//Checks for game over
if(deservesBonus || !(floodMoveCheck(0,maxY-1, -1))){
timer = new Date() - timer;
- if(scoresURL != "")
- scoreName.show("You've won! Please enter your name: ");
- else
- dialog.show("Game Over. Your score is " + gameCanvas.score);
+ scoreName.show("You won! Please enter your name: ");
+ //dialog.show("Game Over. Your score is " + gameCanvas.score);
}
}
@@ -207,6 +206,42 @@ function createBlock(xIdx,yIdx){
return true;
}
+function saveHighScore(name) {
+ if(scoresURL!="")
+ sendHighScore(name);
+ //OfflineStorage
+ var db = openDatabase("SameGameScores", "1.0", "Local SameGame High Scores",100);
+ var dataStr = "INSERT INTO Scores VALUES(?, ?, ?, ?)";
+ var data = [name, gameCanvas.score, maxX+"x"+maxY ,Math.floor(timer/1000)];
+ db.transaction(
+ function(tx) {
+ tx.executeSql('CREATE TABLE IF NOT EXISTS Scores(name TEXT, score NUMBER, gridSize TEXT, time NUMBER)',[]);
+ tx.executeSql(dataStr, data);
+
+ tx.executeSql('SELECT * FROM Scores WHERE gridSize = "12x17" ORDER BY score desc LIMIT 10',[],
+ function(tx, rs) {
+ var r = "\nHIGH SCORES for a standard sized grid\n\n"
+ for(var i = 0; i < rs.rows.length; i++){
+ r += (i+1)+". " + rs.rows.item(i).name +' got '
+ + rs.rows.item(i).score + ' points in '
+ + rs.rows.item(i).time + ' seconds.\n';
+ }
+ dialog.show(r);
+ },
+ function(tx, error) {
+ print("ERROR:", error.message);
+ }
+ );
+ },
+ function() {
+ print("ERROR in transaction");
+ },
+ function() {
+ //print("Transaction successful");
+ }
+ );
+}
+
function sendHighScore(name) {
var postman = new XMLHttpRequest()
var postData = "name="+name+"&score="+gameCanvas.score
diff --git a/demos/declarative/samegame/samegame.qml b/demos/declarative/samegame/samegame.qml
index 38a781a..4560b56 100644
--- a/demos/declarative/samegame/samegame.qml
+++ b/demos/declarative/samegame/samegame.qml
@@ -37,16 +37,21 @@ Rectangle {
Dialog { id: dialog; anchors.centerIn: parent; z: 21 }
Dialog {
id: scoreName; anchors.centerIn: parent; z: 22;
+ Text {
+ id: spacer
+ opacity: 0
+ text: " You won! Please enter your name:"
+ }
TextInput {
id: editor
onAccepted: {
if(scoreName.opacity==1&&editor.text!="")
- sendHighScore(editor.text);
+ saveHighScore(editor.text);
scoreName.forceClose();
}
anchors.verticalCenter: parent.verticalCenter
width: 72; focus: true
- anchors.right: scoreName.right
+ anchors.left: spacer.right
}
}