[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kmines/viranch/qtquick] src/qml: Explode the mine field if a mine is stepped on and show all the mi
From:       Viranch Mehta <viranch.mehta () gmail ! com>
Date:       2013-03-28 11:59:43
Message-ID: 20130328115943.01FDDA60E4 () git ! kde ! org
[Download RAW message or body]

Git commit f4cfe0846154a376313b57ed2df08748aa19b3f6 by Viranch Mehta.
Committed on 07/08/2012 at 09:46.
Pushed by viranch into branch 'viranch/qtquick'.

Explode the mine field if a mine is stepped on and show all the mines

M  +8    -6    src/qml/CellItem.qml
M  +11   -1    src/qml/logic.js

http://commits.kde.org/kmines/f4cfe0846154a376313b57ed2df08748aa19b3f6

diff --git a/src/qml/CellItem.qml b/src/qml/CellItem.qml
index df67370..a418519 100644
--- a/src/qml/CellItem.qml
+++ b/src/qml/CellItem.qml
@@ -20,7 +20,7 @@ import org.kde.games.core 0.1 as KgCore
 
 KgCore.CanvasItem {
     id: cell
-    spriteKey: border!="" ? border : (pressed || revealed ? "cell_down" : "cell_up")
+    spriteKey: border!="" ? border : exploded ? "explosion" : (pressed || revealed ? \
"cell_down" : "cell_up")  
     property string border
 
@@ -29,9 +29,11 @@ KgCore.CanvasItem {
 
     property bool pressed: false
     property bool revealed: false
+    property bool exploded: false
     property bool flagged: cellState == 1
     property bool questioned: cellState == 2
     property int cellState: 0
+    property bool error: !hasMine && flagged
 
     signal clicked
 
@@ -59,19 +61,19 @@ KgCore.CanvasItem {
 
     KgCore.CanvasItem {
         anchors.fill: parent
-        spriteKey: ["", "flag", "question"][cellState]
-        visible: cellState>0
+        visible: (parent.hasMine||flagged) && revealed
+        spriteKey: "mine"
     }
 
     KgCore.CanvasItem {
         anchors.fill: parent
-        visible: parent.hasMine && revealed
-        spriteKey: "mine"
+        spriteKey: revealed && error ? "error" : ["", "flag", "question"][cellState]
+        visible: cellState>0
     }
 
     KgCore.CanvasItem {
         anchors.fill: parent
-        visible: digit>0 && revealed
+        visible: digit>0 && revealed && !error
         spriteKey: "arabic" + ["One", "Two", "Three", "Four", "Five", "Six", \
"Seven", "Eight"][digit-1]  }
 }
diff --git a/src/qml/logic.js b/src/qml/logic.js
index 7a24c50..a7ffef5 100644
--- a/src/qml/logic.js
+++ b/src/qml/logic.js
@@ -14,7 +14,8 @@ function revealCell(index) {
     }
     var cell = field.itemAtIndex(index);
     if (cell.hasMine) {
-        //cell.exploded = true;
+        cell.exploded = true;
+        revealAllMines();
         canvas.gameOver(false);
     } else if (cell.digit == 0) {
         revealEmptyCells(index);
@@ -22,6 +23,15 @@ function revealCell(index) {
     }
 }
 
+function revealAllMines() {
+    for (var i=0; i<field.rows*field.columns; i++) {
+        var item = field.itemAtIndex(i);
+        if ( (item.flagged && !item.hasMine) || (!item.flagged && item.hasMine) ) {
+            item.revealed = true;
+        }
+    }
+}
+
 function revealEmptyCells(index) {
     // recursively reveal neighbour cells until we find cells with digit
     var list = adjacentCells(index);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic