update version
[colorflood] / colorflood / src / field.cpp
index b6a9db4..139aab3 100644 (file)
@@ -114,9 +114,22 @@ Field::FieldSize Field::getSize () const
     return size;
 }
 
+void Field::setSize (int size)
+{
+    Q_ASSERT(size >= 0 && size < NUM_SIZES);
+
+    if (this->size == size)
+        return;
+
+    this->size = (FieldSize)size;
+    randomize();
+}
+
 void Field::randomize ()
 {
     FieldRect rect;
+
+    rect.brush = 0;
     rect.flood = false;
 
     data.clear();
@@ -189,12 +202,6 @@ void Field::floodNeighbours (quint8 brush, int x, int y)
         tryFloodRecurse(brush, x, y + 1);
 }
 
-void Field::mousePressEvent (QMouseEvent *event)
-{
-    if (event->button() == Qt::LeftButton)
-        randomize();
-}
-
 void Field::paintEvent (QPaintEvent *event)
 {
     QPainter painter;
@@ -243,7 +250,7 @@ void Field::flood (int colorIndex)
         }
     }
 
-    update();
+    repaint();
 
     bool allFlooded = true;
 
@@ -259,22 +266,27 @@ void Field::flood (int colorIndex)
         }
     }
 
+    QString msg;
+
     if (allFlooded)
     {
         finished = true;
-
-        QMessageBox box;
         /*: win message */
-        box.setText(tr("You won!"));
-        box.exec();
+        msg = tr("You won!");
     }
     else if (getNumTurnsOfSize(size) == turns)
     {
         finished = true;
+        /*: fail message */
+        msg = tr("You lost!");
+    }
 
+    if (finished)
+    {
         QMessageBox box;
-        /*: fail message */
-        box.setText(tr("You lost!"));
+        box.setWindowTitle("Color Flood");
+        box.setText(msg);
         box.exec();
+        randomize();
     }
 }