Making a dice game and only one die is appearing

whats up everyone im new here so not sure if this is the proper spot to post this, ive been working in processing for about a month now for my intro to programming class and im making a dice game for class, it randomly generates two numbers to display on the dice in the sketch but only one die always shows, any advice?

//Carmine 
//
//Lab 2
//
//Gambling Lab
//

int die1 = int (random(6))+1;
int die2 = int (random(6))+1;

void setup() {
  size(400, 300);
  rectMode(CORNERS);
  fill(49, 199, 242);
  rect(40, 20, 160, 180);
  rect(190, 20, 310, 180);
  println (" you rolled die1 "+ die1);
  println ( " you rolled die2 " + die2);
}
void draw() {

  if (die1 ==1) {
    fill(255, 0, 0);
    ellipseMode(CORNERS);
    ellipse(90, 90, 110, 110);
  } else if (die1==2) {
    fill(255, 0, 0);
    ellipseMode(CORNERS);
    ellipse(50, 30, 70, 50);
    ellipse(130, 150, 150, 170);
  } else if (die1==3) {
    fill(255, 0, 0);
    ellipseMode(CORNERS);
    ellipse(50, 30, 70, 50);
    ellipse(90, 90, 110, 110);
    ellipse(130, 150, 150, 170);
  } else if (die1==4) {
    fill(255, 0, 0);
    ellipseMode(CORNERS);
    ellipse(50, 30, 70, 50);
    ellipse(130, 30, 150, 50);
    ellipse(50, 150, 70, 170);
    ellipse(130, 150, 150, 170);
  } else if (die1==5) {
    fill(255, 0, 0);
    ellipseMode(CORNERS);
    ellipse(50, 30, 70, 50);
    ellipse(130, 30, 150, 50);
    ellipse(50, 150, 70, 170);
    ellipse(130, 150, 150, 170);
    ellipse(90, 90, 110, 110);
  } else if (die1==6) {
    fill(255, 0, 0);
    ellipseMode(CORNERS);
    //top left dot
    ellipse(50, 30, 70, 50);
    //top right dot
    ellipse(130, 30, 150, 50);
    //bottom right dot
    ellipse(130, 150, 150, 170);
    //bottom left dot
    ellipse(50, 150, 70, 170);
    //middle left dot
    ellipse(50, 90, 70, 110);
    //middle right dot
    ellipse(130, 90, 150, 110);
    {
      if (die2==1) {
        fill(255, 0, 0);
        ellipseMode(CORNERS);
        ellipse(240, 90, 260, 110);
      } else if (die2==2) {
        fill(255, 0, 0);
        ellipseMode(CORNERS);
        ellipse(200, 30, 220, 50);
        ellipse(280, 150, 300, 170);
      } else if (die2==3) {
        fill(255, 0, 0);
        ellipseMode(CORNERS);
        ellipse(200, 30, 220, 50);
        ellipse(240, 90, 260, 110);
        ellipse(280, 150, 300, 170);
      } else if (die2==4) {
        fill(255, 0, 0);
        ellipseMode(CORNERS);
        ellipse(200, 30, 220, 50);
        ellipse(280, 30, 300, 50);
        ellipse(200, 150, 220, 170);
        ellipse(280, 150, 300, 170);
      } else if (die2==5) {
        fill(255, 0, 0);
        ellipseMode(CORNERS);
        ellipse(200, 30, 220, 50);
        ellipse(280, 30, 300, 50);
        ellipse(200, 150, 220, 170);
        ellipse(280, 150, 300, 170);
        ellipse(240, 90, 260, 110);
      } else if (die2==6) {
        fill(255, 0, 0);
        ellipseMode(CORNERS);
        ellipse(200, 30, 220, 50);
        ellipse(280, 30, 300, 50);
        ellipse(200, 150, 220, 170);
        ellipse(280, 150, 300, 170);
        ellipse(200, 90, 220, 110);
        ellipse(280, 90, 300, 110);
      }
    }
  }
}

Answers

  • Have you tried debugging your code at all?

    Hint: walk through your code for each of the possible values for die1. What happens if your die1 value is 1? What happens if it's 2? What happens if it's 6?

  • i have for both and thats why i came here.. when i set the values it still will not change the image displayed

  • edited March 2018 Answer ✓

    On line 67 you have a {

    This should probably be a }

    You probably also have too many }'s at the end.

    Didn't the weird indenting tip you off?

  • Answer ✓

    Given that you call

    fill(255, 0, 0);
    ellipseMode(CORNERS);
    

    on every single case, you can move it outside the conditions, line 21, and not repeat it 12 times.

    You are also not clearing the screen between rolls. background()

    You are also drawing the dice 60 times a second when they don't change. noLoop()

  • @tfguy44 thanks that seems to be my issue, im still making syntax errors that are silly like that, i thought for the new if the { was needed. also when i ctrl+T that made the indenting

  • @koogs thanks for that, when i originally tried doing that it didnt work correctly, most likely it wasnt in the right spot

Sign In or Register to comment.