Exemplo n.º 1
0
    public void paint(Graphics g) {
      g = this.startPaint(g);
      int width = this.getSize().width;
      int height = this.getSize().height;
      g.clearRect(0, 0, width, height);
      int cell_size, xstart, ystart;
      double panel_aspect_ratio = (double) width / height;
      double grid_aspect_ratio = (double) grid[0].length / grid.length;
      if (panel_aspect_ratio > grid_aspect_ratio) {
        cell_size = (int) ((double) height / grid.length + 0.5);
        xstart = (int) (width / 2 - (grid[0].length / 2.0 * cell_size + 0.5));
        ystart = 0;
      } else {
        cell_size = (int) ((double) width / grid[0].length + 0.5);
        xstart = 0;
        ystart = (int) (height / 2 - (grid.length / 2.0 * cell_size + 0.5));
      }

      if (paint_background) {
        g.setColor(
            BACKGROUND_COLORS[
                (num_rows_deleted / DELETED_ROWS_PER_LEVEL) % BACKGROUND_COLORS.length]);
        g.fillRect(xstart, ystart, COLUMNS * cell_size, ROWS * cell_size);
      }

      for (int i = 0; i < grid.length; i++) {
        for (int j = 0; j < grid[0].length; j++) {
          if (grid[i][j] != EMPTY) {
            g.setColor(PIECE_COLORS[grid[i][j]]);
            int x = xstart + j * cell_size;
            int y = ystart + i * cell_size;
            g.fill3DRect(x, y, cell_size, cell_size, true);
          }
        }
      }
      this.endPaint();
    }
Exemplo n.º 2
0
 public void frostCake(Color myColor, Graphics myGraphics) {
   myGraphics.setColor(myColor);
   myGraphics.fill3DRect(15, 5, 200, 200, true);
   myGraphics.draw3DRect(15, 5, 200, 190, true);
 }
Exemplo n.º 3
0
 public void drawBlock(Graphics g, int r, int c, int mode) {
   Color curr = g.getColor();
   g.setColor(Color.black);
   int inc = 2;
   int xpos = inc + (c * wt), ypos = inc + (r * ht);
   switch (mode) {
     case 1:
       { // drawn on a square with an unclicked
         // bomb
         drawBomb(g, xpos, ypos);
         break;
       }
     case 2:
       { // draws a cell with a number on it
         g.setColor(Color.lightGray);
         g.fillRect(xpos, ypos, wt, ht);
         if (field[r][c] > 0) {
           g.setFont(new Font("Serif", Font.BOLD, 12));
           g.setColor(list[field[r][c] - 1]);
           g.drawString(field[r][c] + "", xpos + 5, ypos + 12);
         }
       }
       break;
     case 3:
       { // drawn on the square where the bomb was clicked
         g.setColor(Color.red);
         g.fillRect(xpos, ypos, wt, ht);
         g.setColor(Color.black);
         drawBomb(g, xpos, ypos);
       }
       break;
     case 4:
       { // draws a plain unrevealed cell
         g.setColor(Color.lightGray);
         g.fill3DRect(xpos, ypos, wt, ht, true);
       }
       break;
     case 5:
       { // a Flag.
         g.setColor(Color.lightGray);
         g.fill3DRect(xpos, ypos, wt, ht, true);
         g.setColor(Color.red);
         g.fillRect(xpos + 4, ypos + 3, 4, 4);
         g.setColor(Color.red.darker());
         g.drawLine(xpos + 8, ypos + 3, xpos + 8, ypos + 6);
         g.drawLine(xpos + 8, ypos + 6, xpos + 5, ypos + 6);
         g.drawLine(xpos + 6, ypos + 5, xpos + 7, ypos + 5);
         g.drawLine(xpos + 7, ypos + 5, xpos + 7, ypos + 4);
         g.setColor(new Color(128, 128, 128));
         g.drawLine(xpos + 5, ypos + 12, xpos + 11, ypos + 12);
         g.drawLine(xpos + 7, ypos + 11, xpos + 9, ypos + 11);
         g.setColor(Color.black);
         g.drawLine(xpos + 8, ypos + 7, xpos + 8, ypos + 11);
         g.drawLine(xpos + 6, ypos + 12, xpos + 10, ypos + 12);
       }
       break;
     case 6:
       { // A red cross - flag over non mine block
         g.setColor(Color.red);
         g.drawLine(xpos + 3, ypos + 3, xpos + 11, ypos + 11);
         g.drawLine(xpos + 4, ypos + 3, xpos + 12, ypos + 11);
         g.drawLine(xpos + 12, ypos + 3, xpos + 4, ypos + 11);
         g.drawLine(xpos + 3, ypos + 11, xpos + 11, ypos + 3);
         g.setColor(Color.red.darker());
         g.drawLine(xpos + 3, ypos + 12, xpos + 4, ypos + 12);
         g.drawLine(xpos + 4, ypos + 12, xpos + 7, ypos + 9);
         g.drawLine(xpos + 8, ypos + 9, xpos + 11, ypos + 12);
         g.drawLine(xpos + 11, ypos + 12, xpos + 12, ypos + 12);
         g.drawLine(xpos + 3, ypos + 4, xpos + 6, ypos + 7);
         g.drawLine(xpos + 12, ypos + 4, xpos + 9, ypos + 7);
       }
       break;
     case 7:
       {
         g.setColor(Color.lightGray);
         g.fillRect(xpos, ypos, wt, ht);
       }
       break;
   }
   g.setColor(curr);
 }