Exemplo n.º 1
0
 private void refreshDigitButtons() {
   for (DigitButton db : digits1) {
     db.invalidate();
     if (stateInfo.hasSelectedSmallBox && stateInfo.selectedSmallBox.cell1.isEditable)
       db.setClickable(true);
     else db.setClickable(false);
   }
 }
Exemplo n.º 2
0
  public void digitButtonClicked(View v) {
    DigitButton db2 = (DigitButton) v;
    if (!stateInfo.hasSelectedSmallBox) {
      System.err.println("ERROR: No SmallBox selected");
      return;
    }

    if (stateInfo.selectingState == StateInfo.SELECTING_FINAL_VALUE) {
      /*
       * if cell already has same final value to be set, clear it instead
       * otherwise set has final value on cell
       * unset has possible values
       * set final value on cell
       * call invalidate on all digit buttons
       */
      boolean wasConflicting = stateInfo.selectedSmallBox.cell1.isConflicting();

      if (stateInfo.selectedSmallBox.cell1.hasValue
          && stateInfo.selectedSmallBox.cell1.getValue() == db2.number1) {
        stateInfo.selectedSmallBox.clearFinalValue();
      } else {
        stateInfo.selectedSmallBox.setFinalValue(db2.number1, SudokuPuzzleCell.USER_INPUT);
        refreshDigitButtons();
      }

      if (wasConflicting || stateInfo.selectedSmallBox.cell1.isConflicting()) {
        for (SudokuPuzzleCell cell2 : stateInfo.selectedSmallBox.cell1.neighbours) {
          cell2.box1.invalidate();
        }
      }
    } else if (stateInfo.selectingState == StateInfo.SELECTING_POSSIBLE_VALUE) {
      if (stateInfo.selectedSmallBox.containsPossibleValue(db2.number1))
        stateInfo.selectedSmallBox.removePossibleValue(db2.number1);
      else stateInfo.selectedSmallBox.addPossibleValue(db2.number1);
    }
    db2.invalidate();
    testPuzzleCompletion();
  }