[haiku-commits] r35519 - haiku/trunk/src/apps/sudoku

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 19 Feb 2010 10:16:11 +0100 (CET)

Author: axeld
Date: 2010-02-19 10:16:11 +0100 (Fri, 19 Feb 2010)
New Revision: 35519
Changeset: http://dev.haiku-os.org/changeset/35519/haiku

Modified:
   haiku/trunk/src/apps/sudoku/SudokuField.cpp
   haiku/trunk/src/apps/sudoku/SudokuField.h
   haiku/trunk/src/apps/sudoku/SudokuWindow.cpp
Log:
* Added SudokuField::IsEmpty() method.
* The window now automatically generates a new sudoku if empty on start.
* Made SudokuField::IsSolved() const.


Modified: haiku/trunk/src/apps/sudoku/SudokuField.cpp
===================================================================
--- haiku/trunk/src/apps/sudoku/SudokuField.cpp 2010-02-19 08:50:42 UTC (rev 
35518)
+++ haiku/trunk/src/apps/sudoku/SudokuField.cpp 2010-02-19 09:16:11 UTC (rev 
35519)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2007, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx All rights reserved.
+ * Copyright 2007-2010, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
  * Distributed under the terms of the MIT License.
  */
 
@@ -224,7 +224,7 @@
 
 
 bool
-SudokuField::IsSolved()
+SudokuField::IsSolved() const
 {
        for (uint32 y = 0; y < fSize; y++) {
                for (uint32 x = 0; x < fSize; x++) {
@@ -237,6 +237,20 @@
 }
 
 
+bool
+SudokuField::IsEmpty() const
+{
+       for (uint32 y = 0; y < fSize; y++) {
+               for (uint32 x = 0; x < fSize; x++) {
+                       if (ValueAt(x, y) != 0)
+                               return false;
+               }
+       }
+
+       return true;
+}
+
+
 void
 SudokuField::SetHintMaskAt(uint32 x, uint32 y, uint32 hintMask)
 {

Modified: haiku/trunk/src/apps/sudoku/SudokuField.h
===================================================================
--- haiku/trunk/src/apps/sudoku/SudokuField.h   2010-02-19 08:50:42 UTC (rev 
35518)
+++ haiku/trunk/src/apps/sudoku/SudokuField.h   2010-02-19 09:16:11 UTC (rev 
35519)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2007, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx All rights reserved.
+ * Copyright 2007-2010, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
  * Distributed under the terms of the MIT License.
  */
 #ifndef SUDOKU_FIELD_H
@@ -14,6 +14,7 @@
        kInitialValue   = 0x01,
 };
 
+
 class SudokuField : public BArchivable {
 public:
        SudokuField(uint32 size);
@@ -30,7 +31,8 @@
        void SetTo(const SudokuField* other);
        void Reset();
 
-       bool IsSolved();
+       bool IsSolved() const;
+       bool IsEmpty() const;
 
        uint32 Size() const { return fSize; }
        uint32 BlockSize() const { return fBlockSize; }
@@ -71,4 +73,5 @@
        field*  fFields;
 };
 
+
 #endif // SUDOKU_FIELD_H

Modified: haiku/trunk/src/apps/sudoku/SudokuWindow.cpp
===================================================================
--- haiku/trunk/src/apps/sudoku/SudokuWindow.cpp        2010-02-19 08:50:42 UTC 
(rev 35518)
+++ haiku/trunk/src/apps/sudoku/SudokuWindow.cpp        2010-02-19 09:16:11 UTC 
(rev 35519)
@@ -288,6 +288,9 @@
 
        fProgressWindow = new ProgressWindow(this,
                new BMessage(kMsgAbortSudokuGenerator));
+
+       if (fSudokuView->Field()->IsEmpty())
+               PostMessage(kMsgGenerateSudoku);
 }
 
 


Other related posts:

  • » [haiku-commits] r35519 - haiku/trunk/src/apps/sudoku - axeld