summaryrefslogtreecommitdiffstats
path: root/demos/declarative
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2009-10-30 05:24:51 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2009-10-30 05:24:51 (GMT)
commit46eec6d54bad7a686b3dd5cd6e4aa8577d38740d (patch)
treee4c828d1d1456b3fafe74a339562263b3f2c156d /demos/declarative
parentd85d7addc5084ee7d5de31dec562437f9c31c35d (diff)
parentd788c0127b86d8245aa0a8e2472562f444d98ee9 (diff)
downloadQt-46eec6d54bad7a686b3dd5cd6e4aa8577d38740d.zip
Qt-46eec6d54bad7a686b3dd5cd6e4aa8577d38740d.tar.gz
Qt-46eec6d54bad7a686b3dd5cd6e4aa8577d38740d.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Conflicts: src/declarative/qml/qmlcomponentjs.cpp src/declarative/qml/qmlcomponentjs_p.h src/declarative/qml/qmlcomponentjs_p_p.h
Diffstat (limited to 'demos/declarative')
-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
}
}