If all fields for a specific value are set, mark it.

* In this case, the value is drawn a bit less intense than incomplete values.
* Make the keyboard focus background color depend on the actual background
  color.
* No longer allow to drag remove random hint values after removing a value
  from a field.
This commit is contained in:
Axel Dörfler 2012-05-16 02:05:09 +02:00
parent 3a1a1e1b82
commit d6e44c9c82
3 changed files with 40 additions and 12 deletions

View File

@ -251,6 +251,21 @@ SudokuField::IsEmpty() const
}
bool
SudokuField::IsValueCompleted(uint32 value) const
{
uint32 count = 0;
for (uint32 y = 0; y < fSize; y++) {
for (uint32 x = 0; x < fSize; x++) {
if (ValueAt(x, y) == value)
count++;
}
}
return count == Size();
}
void
SudokuField::SetHintMaskAt(uint32 x, uint32 y, uint32 hintMask)
{

View File

@ -33,6 +33,7 @@ public:
bool IsSolved() const;
bool IsEmpty() const;
bool IsValueCompleted(uint32 value) const;
uint32 Size() const { return fSize; }
uint32 BlockSize() const { return fBlockSize; }

View File

@ -814,21 +814,30 @@ SudokuView::MouseDown(BPoint where)
| B_TERTIARY_MOUSE_BUTTON)) != 0) {
// double click or other buttons set a value
if ((fField->FlagsAt(x, y) & kInitialValue) == 0) {
bool wasCompleted;
if (fField->ValueAt(x, y) > 0) {
value = fField->ValueAt(x, y) - 1;
wasCompleted = fField->IsValueCompleted(value + 1);
fField->SetValueAt(x, y, 0);
fShowHintX = x;
fShowHintY = y;
} else {
wasCompleted = fField->IsValueCompleted(value + 1);
fField->SetValueAt(x, y, value + 1);
BMessenger(this).SendMessage(kMsgCheckSolved);
// allow dragging to remove the hint from other fields
fLastHintValueSet = false;
fLastHintValue = value;
fLastField = field;
}
_InvalidateField(x, y);
// allow dragging to remove the hint from other fields
fLastHintValueSet = false;
fLastHintValue = value;
fLastField = field;
if (wasCompleted != fField->IsValueCompleted(value + 1))
Invalidate();
else
_InvalidateField(x, y);
}
return;
}
@ -1204,8 +1213,8 @@ SudokuView::Draw(BRect /*updateRect*/)
|| (fShowKeyboardFocus && x == fKeyboardX
&& y == fKeyboardY))
&& (fField->FlagsAt(x, y) & kInitialValue) == 0) {
//SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
SetLowColor(255, 255, 210);
// TODO: make color more intense
SetLowColor(tint_color(fBackgroundColor, B_DARKEN_2_TINT));
FillRect(_Frame(x, y), B_SOLID_LOW);
} else {
SetLowColor(fBackgroundColor);
@ -1222,13 +1231,16 @@ SudokuView::Draw(BRect /*updateRect*/)
}
SetFont(&fFieldFont);
if (fField->FlagsAt(x, y) & kInitialValue)
if ((fField->FlagsAt(x, y) & kInitialValue) != 0)
SetHighColor(0, 0, 0);
else {
if ((fHintFlags & kMarkInvalid) == 0
|| fField->ValidMaskAt(x, y) & (1UL << (value - 1)))
SetHighColor(0, 0, 200);
else
|| fField->ValidMaskAt(x, y) & (1UL << (value - 1))) {
if (fField->IsValueCompleted(value))
SetHighColor(60, 60, 150);
else
SetHighColor(0, 0, 220);
} else
SetHighColor(200, 0, 0);
}