Пример #1
0
  /**
   * change the image of this die to show a particular value
   *
   * @param value the value to be displayed on the die face
   */
  public void displayValue(int value) {
    // grab pixel array for the large image of all die faces
    int[][] dicePixelArray_ = diceGImage.getPixelArray();

    // create a pixelArray for the die face that is to be displayed, that is of the right size
    int[][] diePixelArray = new int[DIE_HEIGHT][DIE_WIDTH];

    // fill the card pixel array with the appropriate pixels from the dice pixel array
    for (int row = 0; row < DIE_HEIGHT; row++) {
      for (int col = 0; col < DIE_WIDTH; col++) {
        diePixelArray[row][col] = dicePixelArray_[row][(value - 1) * DIE_WIDTH + col];
      }
    }

    // reset this image to one constructed from the card pixel array
    GImage dieGImage = new GImage(diePixelArray);
    this.setImage(dieGImage.getImage());
  }