summaryrefslogtreecommitdiffstats
path: root/demos/declarative/samegame/content
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-09-02 02:59:09 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-09-02 02:59:09 (GMT)
commit1ccca16e3e032cb90d09dc4a161fe35114d8360d (patch)
tree0f2a41a37f3270cdcf145dfa83345dedd63793dc /demos/declarative/samegame/content
parentdbdaaa78c6b7c7a9498de9703d15b654eab163de (diff)
downloadQt-1ccca16e3e032cb90d09dc4a161fe35114d8360d.zip
Qt-1ccca16e3e032cb90d09dc4a161fe35114d8360d.tar.gz
Qt-1ccca16e3e032cb90d09dc4a161fe35114d8360d.tar.bz2
SameGame high score server support.
This commit contains all the functionality for sending high scores to a server, and the server. The server files have been installed at http://qtfx-nokia.trolltech.com.au/samegame for internal testing.
Diffstat (limited to 'demos/declarative/samegame/content')
-rwxr-xr-xdemos/declarative/samegame/content/samegame.js46
1 files changed, 45 insertions, 1 deletions
diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js
index f04fb4c..355dbfd 100755
--- a/demos/declarative/samegame/content/samegame.js
+++ b/demos/declarative/samegame/content/samegame.js
@@ -6,13 +6,22 @@ var tileSize = 40;
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 timer;
var component;
//Index function used instead of a 2D array
-function index(xIdx,yIdx){
+function index(xIdx,yIdx) {
return xIdx + (yIdx * maxX);
}
+function timeStr(msecs) {
+ var secs = Math.floor(msecs/1000);
+ var m = Math.floor(secs/60);
+ var ret = "" + m + "m " + (secs%60) + "s";
+ return ret;
+}
+
function initBoard()
{
for(i = 0; i<maxIndex; i++){
@@ -34,6 +43,7 @@ function initBoard()
startCreatingBlock(xIdx,yIdx);
}
}
+ timer = new Date();
}
var fillFound;//Set after a floodFill call to the number of tiles found
@@ -136,6 +146,8 @@ function victoryCheck()
if(deservesBonus || !(floodMoveCheck(0,maxY-1, -1))){
dialog.text = "Game Over. Your score is " + gameCanvas.score;
dialog.opacity = 1;
+ timer = new Date() - timer;
+ //if(scoresURL != "") sendHighScore(name);
}
}
@@ -209,3 +221,35 @@ function startCreatingBlock(xIdx,yIdx){
component.statusChanged.connect(finishCreatingBlock());
return;
}
+
+function tweetHighScore(twitterName, twitterPass) {
+ if(twitterName == '' || twitterPass == '')
+ return false;//Can't login like that
+
+ var scoreStr = "I just played the QML SameGame, and got " + gameCanvas.score + " points on a "
+ + maxX + "x" + maxY + " grid. It took me " + timeStr(timer) + ".";
+ var postData = "status=" + scoreStr;
+ var postman = new XMLHttpRequest();
+ postman.open("POST", "http://twitter.com/statuses/update.xml", true, twitterName, twitterPass);
+ postman.onreadystatechange = function() {
+ if (postman.readyState == postman.DONE) {
+ dialog.text = "Your score has been tweeted for you.";
+ dialog.opacity = 1;
+ }
+ }
+ postman.send(postData);
+}
+
+function sendHighScore(name) {
+ var postman = new XMLHttpRequest()
+ var postData = "name="+name+"&score="+gameCanvas.score
+ +"&gridSize="+maxX+"x"+maxY +"&time="+Math.floor(timer/1000);
+ postman.open("POST", scoresURL, true);
+ postman.onreadystatechange = function() {
+ if (postman.readyState == postman.DONE) {
+ dialog.text = "Your score has been uploaded.";
+ dialog.opacity = 1;
+ }
+ }
+ postman.send(postData);
+}