コード例 #1
0
  public void displayOptions() {
    Image img;

    if (gamemode == gameModeBasic) {
      img = imageBasic;
    } else if (gamemode == gameModeInter) {
      img = imageInter;
    } else {
      img = imageAdvanced;
    }
    ;

    // account for system tray!
    displayImageAtXY(img, 89 - img.getWidth(), 0);
  }
コード例 #2
0
  public void showResult(int count) {
    Image img = null;
    int imageX, imageY = 0;

    // 6 for system tray, and then account for all 4 results
    imageX = 89 - imageBull.getWidth() * 4 - imageInter.getWidth();

    if (gamemode == gameModeBasic) {
      for (int i = 0; i < result[count - 1].length(); i++) {
        switch (result[count - 1].charAt(i)) {
          case 'b':
            img = imageBull;
            break;
          case 'w':
            img = imageCow;
            break;
          case '-':
            img = imageWrong;
            break;
        }
        displayImageAtXY(img, imageX, imageY);
        imageX += img.getWidth();
      }
    } else {
      // number of bulls
      int bulls = Character.digit(result[count - 1].charAt(0), 10);
      int cows = Character.digit(result[count - 1].charAt(2), 10);
      int imageXB = imageX, imageXW = imageX;
      int imageYB = 0, imageYW = 0;

      for (int i = 0; i < bulls; i++) {
        displayImageAtXY(imageBull, imageXB, imageYB);
        imageXB += imageBull.getWidth();
      }

      if (bulls != 0) {
        imageYW = imageBull.getHeight();
      }

      for (int i = 0; i < cows; i++) {
        displayImageAtXY(imageCow, imageXW, imageYW);
        imageXW += imageCow.getWidth();
      }

      if (bulls == 0 && cows == 0) {
        displayImageAtXY(imageWrong, imageX, imageY);
      }
    }
  }
コード例 #3
0
 public void displayImageAtXY(Image img, int x, int y) {
   this.label.draw("", img, x, y, img.getWidth(), img.getHeight(), true);
   this.display.setCurrent(this.label);
 }
コード例 #4
0
  /** Called when the penlet is activated by menu */
  public void activateApp(int reason, Object[] args) {
    // gamestate
    gamestate = actapp;

    // add listeners
    this.context.addStrokeListener(this);
    context.addPenTipListener(this);

    // Configure the ICR context
    this.icrContext = this.context.getICRContext(1000, this);
    Resource[] resources = {
      this.icrContext.getDefaultAlphabetKnowledgeResource(),
      // this.icrContext.createLKSystemResource(ICRContext.SYSRES_LK_WORDLIST_100K),
      this.icrContext.createSKSystemResource(ICRContext.SYSRES_SK_DIGIT)
    };
    this.icrContext.addResourceSet(resources);

    // create the menu
    this.menuBrowseList = new BrowseList(this.vectorMenuItems, null);

    // load image streams
    Class myPenLetClass = this.getClass();
    inputstreamImage = myPenLetClass.getResourceAsStream("/images/Bull.arw");

    try {
      imageBull = Image.createImage(inputstreamImage);
    } catch (IOException e) {
      imageBull = null;
    }

    inputstreamImage = myPenLetClass.getResourceAsStream("/images/Cow.arw");
    try {
      imageCow = Image.createImage(inputstreamImage);
    } catch (IOException e) {
      imageCow = null;
    }

    inputstreamImage = myPenLetClass.getResourceAsStream("/images/Wrong.arw");
    try {
      imageWrong = Image.createImage(inputstreamImage);
    } catch (IOException e) {
      imageWrong = null;
    }

    inputstreamImage = myPenLetClass.getResourceAsStream("/images/Help.arw");
    try {
      imageHelp = Image.createImage(inputstreamImage);
    } catch (IOException e) {
      imageWrong = null;
    }

    inputstreamImage = myPenLetClass.getResourceAsStream("/images/AdvancedMode.arw");
    try {
      imageAdvanced = Image.createImage(inputstreamImage);
    } catch (IOException e) {
      imageAdvanced = null;
    }

    inputstreamImage = myPenLetClass.getResourceAsStream("/images/InterMediateMode.arw");
    try {
      imageInter = Image.createImage(inputstreamImage);
    } catch (IOException e) {
      imageInter = null;
    }

    inputstreamImage = myPenLetClass.getResourceAsStream("/images/BasicMode.arw");
    try {
      imageBasic = Image.createImage(inputstreamImage);
    } catch (IOException e) {
      imageBasic = null;
    }

    inputstreamImage = myPenLetClass.getResourceAsStream("/images/GBGuesses.arw");
    try {
      imageGameBoard = Image.createImage(inputstreamImage);
    } catch (IOException e) {
      imageGameBoard = null;
    }

    inputstreamImage = myPenLetClass.getResourceAsStream("/images/GBClear.arw");
    try {
      imageClearButton = Image.createImage(inputstreamImage);
    } catch (IOException e) {
      imageClearButton = null;
    }

    inputstreamImage = myPenLetClass.getResourceAsStream("/images/GBSound.arw");
    try {
      imageSoundButton = Image.createImage(inputstreamImage);
    } catch (IOException e) {
      imageSoundButton = null;
    }

    inputstreamImage = myPenLetClass.getResourceAsStream("/images/GBNewGame.arw");
    try {
      imageNewGameButton = Image.createImage(inputstreamImage);
    } catch (IOException e) {
      imageNewGameButton = null;
    }

    if (reason == ACTIVATED_BY_MENU) {

      // display the first menu item
      this.display.setCurrent(this.menuBrowseList);
      currentMenuSelection = this.menuBrowseList.getFocusIndex();
      playMenuPrompt(currentMenuSelection);
    } else {
      /* activated by another event. state that codebreaker active
      and launch into new game */
      String[] filenames;
      filenames = new String[3];
      filenames[0] = "codebreaker";
      filenames[1] = "newgame";
      filenames[2] = "rectangle";
      playSound(filenames);
      gamestate = newGame(false);
    }
  }