Exemplo n.º 1
0
 // Starts this die rolling
 public void roll() {
   super.roll();
   int width = tableRight - tableLeft;
   int height = tableBottom - tableTop;
   xCenter = tableLeft;
   yCenter = tableTop + height / 2;
   xSpeed = width * (Math.random() + 1) * speedFactor;
   ySpeed = height * (Math.random() - .5) * 2. * speedFactor;
 }
Exemplo n.º 2
0
  // Draws this die when rolling with a random number of dots
  private void drawRolling(Graphics g) {
    int x = xCenter - dieSize / 2 + (int) (3 * Math.random()) - 1;
    int y = yCenter - dieSize / 2 + (int) (3 * Math.random()) - 1;
    g.setColor(Color.RED);

    if (x % 2 != 0) g.fillRoundRect(x, y, dieSize, dieSize, dieSize / 4, dieSize / 4);
    else g.fillOval(x - 2, y - 2, dieSize + 4, dieSize + 4);

    Die die = new Die();
    die.roll();
    drawDots(g, x, y, die.getNumDots());
  }