How to draw bones in java?

Red Dice I was working on a craps game for a class, and I cannot finish the code because I do not know how to draw the actual points on the matrix. I have a table, and the actual mind is simply not dots on the bones. I need help drawing them. And the bones are red. This is what I have:

// Draws a given number of dots on this die
private void drawDots(Graphics g, int x, int y, int numDots)
    {
    g.setColor(Color.WHITE);

    int dotSize = dieSize / 4;
    int step = dieSize / 8;
    int x1 = x + step - 1;
    int x2 = x + 3*step;
    int x3 = x + 5*step + 1;
    int y1 = y + step - 1;
    int y2 = y + 3*step;
    int y3 = y + 5*step + 1;

    switch (numDots)
    {
      case 1:
    g.fillOval(x2, y2, dotSize, dotSize);
    break;
  case 2:
    g.fillOval(x3, y1, dotSize, dotSize);
    g.fillOval(x1, y3, dotSize, dotSize);
    break;
  case 3: 
    g.fillOval(x1, y1, dotSize, dotSize);
    g.fillOval(x2, y2, dotSize, dotSize);
    g.fillOval(x3, y3, dotSize, dotSize);
    break;
  case 4:
    g.fillOval(x1, y1, dotSize, dotSize);
    g.fillOval(x3, y3, dotSize, dotSize);
    g.fillOval(x1, y3, dotSize, dotSize);
    g.fillOval(x3, y3, dotSize, dotSize);
    break;
  case 5: 
    g.fillOval(x1, y1, dotSize, dotSize);
    g.fillOval(x2, y2, dotSize, dotSize);
    g.fillOval(x3, y1, dotSize, dotSize);
    g.fillOval(x1, y3, dotSize, dotSize);
    g.fillOval(x3, y3, dotSize, dotSize);
    break;
  case 6:
    g.fillOval(x1, y1, dotSize, dotSize);
    g.fillOval(x2, y1, dotSize, dotSize);
    g.fillOval(x3, y1, dotSize, dotSize);
    g.fillOval(x1, y3, dotSize, dotSize);
    g.fillOval(x2, y3, dotSize, dotSize);
    g.fillOval(x3, y3, dotSize, dotSize);
    break;


}

}
}

I do not know what I did wrong. When I run his dice roll, but they do not show any dots on them.

+4
source share
1 answer

Bug fixed. My class Die.java did not say what was needed. Thanks for the help!

My class originally said:

import java.util.Random;


public class Die
{
  private final static Random random = new Random();
  public Die()
{

}
  public int getRoll()
 {
   return random.nextInt(6)+1;
  }
  public int getNumDots()
  {
    // TODO Auto-generated method stub
    return 0;
  }
}

When he should have said:

import java.util.Random;


public class Die
{
  private int sides;
  {
  }

    public void roll()
    {
      sides = (int)(Math.random()* 6 +1);
    }
    public int getNumDots()
    {
      return sides;
    }
  }
0
source

Source: https://habr.com/ru/post/1616231/


All Articles