* Added SudokuField::IsEmpty() method.
* The window now automatically generates a new sudoku if empty on start. * Made SudokuField::IsSolved() const. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35519 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2007, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2007-2010, Axel Dörfler, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -224,7 +224,7 @@ SudokuField::Dump()
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SudokuField::IsSolved()
|
SudokuField::IsSolved() const
|
||||||
{
|
{
|
||||||
for (uint32 y = 0; y < fSize; y++) {
|
for (uint32 y = 0; y < fSize; y++) {
|
||||||
for (uint32 x = 0; x < fSize; x++) {
|
for (uint32 x = 0; x < fSize; x++) {
|
||||||
@@ -237,6 +237,20 @@ SudokuField::IsSolved()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
void
|
||||||
SudokuField::SetHintMaskAt(uint32 x, uint32 y, uint32 hintMask)
|
SudokuField::SetHintMaskAt(uint32 x, uint32 y, uint32 hintMask)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2007, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2007-2010, Axel Dörfler, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef SUDOKU_FIELD_H
|
#ifndef SUDOKU_FIELD_H
|
||||||
@@ -14,6 +14,7 @@ enum {
|
|||||||
kInitialValue = 0x01,
|
kInitialValue = 0x01,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class SudokuField : public BArchivable {
|
class SudokuField : public BArchivable {
|
||||||
public:
|
public:
|
||||||
SudokuField(uint32 size);
|
SudokuField(uint32 size);
|
||||||
@@ -30,7 +31,8 @@ public:
|
|||||||
void SetTo(const SudokuField* other);
|
void SetTo(const SudokuField* other);
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
bool IsSolved();
|
bool IsSolved() const;
|
||||||
|
bool IsEmpty() const;
|
||||||
|
|
||||||
uint32 Size() const { return fSize; }
|
uint32 Size() const { return fSize; }
|
||||||
uint32 BlockSize() const { return fBlockSize; }
|
uint32 BlockSize() const { return fBlockSize; }
|
||||||
@@ -71,4 +73,5 @@ private:
|
|||||||
field* fFields;
|
field* fFields;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // SUDOKU_FIELD_H
|
#endif // SUDOKU_FIELD_H
|
||||||
|
|||||||
@@ -288,6 +288,9 @@ SudokuWindow::SudokuWindow()
|
|||||||
|
|
||||||
fProgressWindow = new ProgressWindow(this,
|
fProgressWindow = new ProgressWindow(this,
|
||||||
new BMessage(kMsgAbortSudokuGenerator));
|
new BMessage(kMsgAbortSudokuGenerator));
|
||||||
|
|
||||||
|
if (fSudokuView->Field()->IsEmpty())
|
||||||
|
PostMessage(kMsgGenerateSudoku);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user