Exemplo n.º 1
0
  protected Letter(int playerIdx, char letter) {
    _listener = new LetterTouchListener(this);
    _playerIdx = playerIdx;
    _letter = letter;

    WordController.getInstance(playerIdx).addLetterContextChangeListener(this);
    PlayerController.addPlayerListener(this);
  }
Exemplo n.º 2
0
    public boolean onTouch(View v, MotionEvent event) {
      if (_playerIdx != _activePlayerIdx) return false;

      LetterContext letterContext = _model.getLetterContext();
      if (_selectCountTable.get(_playerIdx) == null) _selectCountTable.put(_playerIdx, 0);
      int selectCount = _selectCountTable.get(_playerIdx);

      if (event.getAction() == MotionEvent.ACTION_DOWN) {
        _oldLetterContext = letterContext;
        _model.setLetterContext(LetterContext.PRESSED);
      } else {
        switch (_oldLetterContext) {
          case NEUTRAL:
            _model.setLetterContext(LetterContext.ELIMINATED);
            break;
          case ELIMINATED:
            if (selectCount < 4) {
              _model.setLetterContext(LetterContext.SELECTED);
              _selectCountTable.put(_playerIdx, selectCount + 1);
            } else _model.setLetterContext(LetterContext.NEUTRAL);
            break;
          case SELECTED:
            _model.setLetterContext(LetterContext.NEUTRAL);
            _selectCountTable.put(_playerIdx, selectCount - 1);
            break;
          default:
            break;
        }
        _oldLetterContext = letterContext;
      }

      onLetterContextChanged(_model); // Updates letter context table right away
      WordController.getInstance(_playerIdx).fireLetterContextChangeEvent(_model);

      return false;
    }