Working on a Simon says game

having issues with line 27 and 28, I’m not sure how to properly write that line
<//r,b,g,y
boolean colours = {false,false,false,false};
color coloursTrue = {color(255, 0, 0) , color(0,0,255) , color(0,255,0) , color(255,255,0)};
color coloursFalse = {color(100, 0, 0) , color(0,0,100) , color(0,100,0) , color(100,100,0)};
ArrayList pattern = new ArrayList();

void setup(){
size(600,600);
background(200);
}

void draw(){
fill(100); ellipse(300,300,500,500);

if (colours[0]){fill(coloursTrue[0]);} else {fill(coloursFalse[0]);} arc(300, 300, 500, 500, -PI, -HALF_PI);
if (colours[1]){fill(coloursTrue[0]);} else {fill(coloursFalse[1]);} arc(300, 300, 500, 500, -HALF_PI, 0);
if (colours[2]){fill(coloursTrue[0]);} else {fill(coloursFalse[2]);} arc(300, 300, 500, 500, 0, HALF_PI);
if (colours[3]){fill(coloursTrue[0]);} else {fill(coloursFalse[3]);} arc(300, 300, 500, 500, HALF_PI, PI);

line(50,300,550,300);
line(300,50,300,550);
}

void showPattern () {
pattern.add((int)random(0, 4));

for (int i = 0; i < size(pattern); i++) {
colours[pattern.get(i)] = true;
}
}>

here is my version

it’s rgb by the way

press any key to change pattern

I don’t know the game so I don’t know what is supposed to happen

//r,g,b

boolean[] colours = {false, false, false, false};
color[] coloursTrue = {color(255, 0, 0), color(0, 0, 255), color(0, 255, 0), color(255, 255, 0)};
color[] coloursFalse = {color(100, 0, 0), color(0, 0, 100), color(0, 100, 0), color(100, 100, 0)};
ArrayList<Boolean> pattern = new ArrayList();

void setup() {
  size(600, 600);
  background(200);
}

void draw() {
  fill(100);
  ellipse(300, 300, 500, 500);

  // ----------------------------------------------
  // show 4 arcs
  if (colours[0]) {
    fill(coloursTrue[0]);
  } else {
    fill(coloursFalse[0]);
  }
  arc(300, 300, 500, 500, -PI, -HALF_PI);

  if (colours[1]) {
    fill(coloursTrue[0]);
  } else {
    fill(coloursFalse[1]);
  }
  arc(300, 300, 500, 500, -HALF_PI, 0);

  if (colours[2]) {
    fill(coloursTrue[0]);
  } else {
    fill(coloursFalse[2]);
  }
  arc(300, 300, 500, 500, 0, HALF_PI);

  if (colours[3]) {
    fill(coloursTrue[0]);
  } else {
    fill(coloursFalse[3]);
  }
  arc(300, 300, 500, 500, HALF_PI, PI);

  // ---------------------------------------------------
  line(50, 300, 550, 300);
  line(300, 50, 300, 550);
}

//---------------------------------------------------------------------------

void keyPressed() {
  showPattern();
}

void showPattern() {
  // RESET
  pattern.clear();

  // fill
  for (int i = 0; i < 4; i++) {
    if (random(1)>0.5)
      pattern.add(true);
    else pattern.add(false);
  }

  // copy pattern to board
  for (int i = 0; i < pattern.size(); i++) {
    colours[i] = pattern.get(i);
  }
}
// ---

1 Like

well, you have lots of typos in the draw() function in the if-clause

  if (colours[1]) {
    fill(coloursTrue[0]);

your “0” must be [1]

error occurs 3 times

looks much better now…

1 Like

I’m incredibly confused on what this is tryna do, it lights up some of the buttons red?

Simon (googling the game it’s just called Simon, i always called it Simon says, whoops) is a memory game where the board will show a pattern of colours, and then you have to repeat it back by pressing the buttons, and it increases by 1 every time, that explanation isn’t great but its the best I can do

also I just realized i formatted the code wrong, apologies, I’m new

the little note at the start was just for me to remember what order the 4 colours are in on the lists, i do know its rgb thats just sorta the order

as I said that is because of your typo in draw()

correct the 3 typos and it’s much better.

As I said I don’t know the game, you can change the code in showPattern().
Is one or more field enlightened?

1 Like

could you explain what the typo is in different words? (really sorry, I’m slow)

1 Like

in this line you have 3 arrays which are parallel

Suggestion:

you need to use “1” in all places (in this line), but you have “0” in the 2nd array

Correction:

                                1

if (colours[1]){fill(coloursTrue[1]);} else {fill(coloursFalse[1]);} arc(300, 300, 500, 500, -HALF_PI, 0);

Remark

This also applies for the other 3 lines

indexes for the arrays must be


0     0      0
1     1      1 
2     2      2
3     3      3
1 Like

ahhh, i see that now, thanks!

1 Like