summaryrefslogtreecommitdiffstats
path: root/demos/declarative/samegame
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-07-16 05:00:59 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-07-16 05:00:59 (GMT)
commit319eba26b183c5d67f1950255bf3758b8fd64011 (patch)
treeb92aacae64cddd8d7026e099ae219e2dbaa9b901 /demos/declarative/samegame
parenta484b83cbc968a8088e6fd1b0bb39570ba157c93 (diff)
downloadQt-319eba26b183c5d67f1950255bf3758b8fd64011.zip
Qt-319eba26b183c5d67f1950255bf3758b8fd64011.tar.gz
Qt-319eba26b183c5d67f1950255bf3758b8fd64011.tar.bz2
SameGame notifies player of game over
As requested by Aaron.
Diffstat (limited to 'demos/declarative/samegame')
-rw-r--r--demos/declarative/samegame/SameGame.qml6
-rw-r--r--demos/declarative/samegame/content/SameDialog.qml4
-rw-r--r--demos/declarative/samegame/content/samegame.js26
3 files changed, 29 insertions, 7 deletions
diff --git a/demos/declarative/samegame/SameGame.qml b/demos/declarative/samegame/SameGame.qml
index c929c91..9ae87bd 100644
--- a/demos/declarative/samegame/SameGame.qml
+++ b/demos/declarative/samegame/SameGame.qml
@@ -29,13 +29,13 @@ Rect {
anchors.topMargin: 10
anchors.horizontalCenter: parent.horizontalCenter
MediaButton { id: btnA; text: "New Game"; onClicked: {initBoard();} }
- MediaButton { id: btnB; text: "Swap Theme"; onClicked: {swapTileSrc(); dialog.opacity = 1;}
- }
+ MediaButton { id: btnB; text: "Swap Theme"; onClicked: {swapTileSrc(); dialog.opacity = 1;
+ dialog.text="Takes effect next game.";} }
Text{ text: "Score: " + gameCanvas.score; width:100 }
}
SameDialog {
id: dialog
anchors.centeredIn: parent
- text: "Takes effect next game."
+ text: "Hello World"
}
}
diff --git a/demos/declarative/samegame/content/SameDialog.qml b/demos/declarative/samegame/content/SameDialog.qml
index eed52f0..a0718f2 100644
--- a/demos/declarative/samegame/content/SameDialog.qml
+++ b/demos/declarative/samegame/content/SameDialog.qml
@@ -5,8 +5,8 @@ Rect {
opacity: 0
opacity: Behavior {
SequentialAnimation {
- NumberAnimation {property: "opacity"; duration: 1000 }
- NumberAnimation {property: "opacity"; to: 0; duration: 1000 }
+ NumberAnimation {property: "opacity"; duration: 1500 }
+ NumberAnimation {property: "opacity"; to: 0; duration: 1500 }
}
}
color: "white"
diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js
index 1163bae..d2a3cbc 100644
--- a/demos/declarative/samegame/content/samegame.js
+++ b/demos/declarative/samegame/content/samegame.js
@@ -145,13 +145,35 @@ function shuffleDown()
function victoryCheck()
{
- //Only awards bonuses at the moment
+ //awards bonuses
deservesBonus = true;
for(xIdx=maxX-1; xIdx>=0; xIdx--)
if(board[index(xIdx, maxY - 1)] != null)
deservesBonus = false;
if(deservesBonus)
- gameCanvas.score += 250;
+ gameCanvas.score += 500;
+ //Checks for game over
+ if(deservesBonus || noMoreMoves()){
+ dialog.text = "Game Over. Your score is " + gameCanvas.score;
+ dialog.opacity = 1;
+ }
+}
+
+function noMoreMoves()
+{
+ return !floodMoveCheck(0, maxY-1, -1);
+}
+
+function floodMoveCheck(xIdx, yIdx, type)
+{
+ if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0)
+ return false;
+ if(board[index(xIdx, yIdx)] == null)
+ return false;
+ myType = board[index(xIdx, yIdx)].type;
+ if(type == myType)
+ return true;
+ return floodMoveCheck(xIdx + 1, yIdx, myType) || floodMoveCheck(xIdx, yIdx - 1, myType);
}
//Need a simpler method of doing this?