diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2009-07-16 05:00:59 (GMT) |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2009-07-16 05:00:59 (GMT) |
commit | 319eba26b183c5d67f1950255bf3758b8fd64011 (patch) | |
tree | b92aacae64cddd8d7026e099ae219e2dbaa9b901 /demos/declarative/samegame/content | |
parent | a484b83cbc968a8088e6fd1b0bb39570ba157c93 (diff) | |
download | Qt-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/content')
-rw-r--r-- | demos/declarative/samegame/content/SameDialog.qml | 4 | ||||
-rw-r--r-- | demos/declarative/samegame/content/samegame.js | 26 |
2 files changed, 26 insertions, 4 deletions
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? |