示例#1
0
  // What to do when a valid move has been made.
  protected void processValidMove(Move m) {
    edu.wpi.sudoku.model.SudokuBoard board = Model.getBoard();

    m.execute(board);
    Model.addMove(m);

    if (board.isComplete()) {
      // boardSolved();
      new UpdateController()
          .sendFinish(
              lobby, PlayerManager.get().getPlayerById(lobby.getContext().getUser()).getScore());
    }

    // Have we completed a Cell? If so, make the locked sound. Otherwise
    // go and make a small sound.
    Cell c = Cell.enclosingCell(m.getSquare());
    CellNormal cn = new CellNormal(c);
    boolean full = true; // assume we are done.
    for (edu.wpi.sudoku.model.Square s : cn) {
      if (board.isEmpty(s)) {
        full = false;
        break;
      }
    }

    if (full) {
      OneSoundPlayer.playSound(this.getClass().getResource("/sounds/operations/lockingSound.WAV"));
    } else {
      OneSoundPlayer.playSound(this.getClass().getResource("/sounds/operations/snapSound.WAV"));
    }
  }
示例#2
0
  /**
   * This method initializes everything.
   *
   * <p>Also prefetches the sounds we are going to use.
   *
   * @return void
   */
  private void initialize() {

    /** Responder who knows how to query the existing board to find the available options. */
    optionFinder =
        new IFindOptions() {

          public Option findGuesses(Point p) {
            edu.wpi.sudoku.model.Square sq = gameCanvas.getSquare(p.x, p.y);

            // set it in the board.
            edu.wpi.sudoku.model.SudokuBoard board = Model.getBoard();

            String s = board.guesses(sq);
            return new Option(sq, s);
          }
        };

    // register ability to deal with clicks/drags. Note that
    // this applet PLAYS the role of the DigitSelection
    digitSelection =
        new IDigitSelection() {
          /**
           * Reports set of digit(s) in the range of 1..9 at a given Point.
           *
           * @param p Point reflecting original location of user intent.
           * @param opt Option of available digits.
           * @param modifiers shift/ctrl information for original click.
           */
          public void report(Point p, Option opt, int modifiers) {
            // take action based upon report.
            // Determine which square is being refered to
            edu.wpi.sudoku.model.Square s = gameCanvas.getSquare(p.x, p.y);
            // set it in the board.
            edu.wpi.sudoku.model.SudokuBoard board = Model.getBoard();

            // user is guessing. THese should be converted
            // into actual MOVE classes.
            if ((modifiers & MouseEvent.CTRL_MASK) == MouseEvent.CTRL_MASK) {
              board.clearGuesses(s);
            } else {
              board.clearGuesses(s);
              for (int d : opt) {
                board.addGuess(s, d);
              }
            }

            refreshView();
          }

          /**
           * Reports digit in the range of 1..9 at a given Point.
           *
           * @param p Point reflecting original location of user intent.
           * @param digit digit selected by user.
           * @param modifiers shift/ctrl information for original click.
           */
          public void report(Point p, int digit, int modifiers) {
            // take action based upon report.
            // Determine which square is being refered to
            edu.wpi.sudoku.model.Square s = gameCanvas.getSquare(p.x, p.y);

            // set it in the board.
            edu.wpi.sudoku.model.SudokuBoard board = Model.getBoard();

            /**
             * Constructor of move.
             *
             * <p>Global -- FiRj refers to the cell in file Fi and rank Rj. Proper values for Fi are
             * letters 'a' through 'i' while Rj values are 1..9
             */
            Properties props = new Properties();
            try {
              props.setProperty("file", String.valueOf(s.getFile()));
              props.setProperty("rank", String.valueOf(s.getRank()));
              props.setProperty("digit", String.valueOf(digit));

            } catch (Exception e) {
              // alert user.
              Toolkit.getDefaultToolkit().beep();
            }
            // ignore the score at this point; let controller deal with it
            status.updateState(props, 0);
          }
        };

    this.setSize(530, 500);
    this.setName("outerPanel");
    this.add(getInnerPanel(), null);

    //		// initialize model as well to be a random game.
    //		Model.initialize();
    //		sgm = new SudokuGameManager(Model.getBoard());
    //		requestNewGame(Configuration.baseLevel());
    //
    // prefetch sounds.
    OneSoundPlayer.downloadSound(
        this.getClass().getResource("/sounds/operations/lockingSound.WAV"));
    OneSoundPlayer.downloadSound(this.getClass().getResource("/sounds/operations/snapSound.WAV"));
  }