コード例 #1
0
  /**
   * Called when a new stroke is created on the pen. The stroke information is added to the
   * ICRContext
   */
  public void strokeCreated(long time, Region areaID, PageInstance page) {
    /* the icr engine is only needed when a game is in progress
     * and the game board has been completely drawn
     */

    // only process if the stroke is not part of a single tap
    if (time > singletaptime) {
      if (gamestate == gameinprogress && gameBoardReady) {
        // only interested in recognizing if it is written in the guess region
        if (areaID.getAreaId() == guessRegion) {
          // check if game is over
          if (gamestate == gameinprogress) {
            this.icrContext.addStroke(page, time);
            StrokeStorage ss = new StrokeStorage(page);
            Rectangle rect = ss.getStrokeBoundingBox(time);
            if (numberofxcoordinates < 4) {
              xcoordinates[numberofxcoordinates] = rect.getX();
              numberofxcoordinates++;
            }
          }
        }
      } else {
        if (gamestate == makegameboard || gamestate == startgameboard) {
          int areaid;

          areaid = areaID.getAreaId();
          gamestate = makegameboard;

          if (areaid != guessRegion
              && areaid != clearRegion
              && areaid != soundRegion
              && areaid != newGameRegion) {
            RegionCollection rc = this.context.getCurrentRegionCollection();
            StrokeStorage ss = new StrokeStorage(page);
            Rectangle rect = ss.getStrokeBoundingBox(time);
            if (makingRegionRect) {
              RegionRect = rect;
              makingRegionRect = false;
            } else {
              RegionRect = Rectangle.getUnion(RegionRect, rect);
            }
            if (rc.isOverlappingExistingRegion(RegionRect)) {
              // overlaps existing region, beep and do not do anything
              playSound("SL_Error");
            }
          }
        }
      }
    }

    // reset the single tap time
    singletaptime = 0;
  }
コード例 #2
0
  public void penDown(long time, Region areaID, PageInstance page) {
    int id;

    id = areaID.getAreaId();
    if (id != 0 && gameBoardReady) {
      if (clearRegion == id) {
        /* User has tapped the "clear icon".
         * check to see if the game is over?
         * if there are entries in the current guess.
         * clear them. else clear the previous entry
         */
        if (gamestate == gameinprogress) {
          if (guess[guesscount - 1].length() > 0) {
            guess[guesscount - 1] = "";
            result[guesscount - 1] = "";
          } else if (guesscount > 1) {
            guesscount--;
            guess[guesscount - 1] = "";
            result[guesscount - 1] = "";
          }
          promptForGuess(guesscount);
        }
        return;
      }

      if (soundRegion == id) {
        soundToggle();
        return;
      }

      if (newGameRegion == id) {
        if (gamestate == 0
            || gamestate == actapp
            || gamestate == gameover
            || gamestate == gameinprogress
            || gamestate == gamepaused) {
          gamestate = newGame(true);
        }
        return;
      }

      if (guessRegion == id && gamestate == gamepaused) {
        gamestate = gameinprogress;
        promptForGuess(guesscount);
        return;
      }

      if (guessRegion == id && gamestate == gameinprogress) {
        if (this.player.isAudioPlayerPlaying()) {
          this.player.stop();
        }
        return;
      }
    }
  }