String prize = ""; //var to remember cell contents void board( ) { fill(0); // draw the board stroke(250, 250, 0); strokeWeight(5); rect(150, 150, 750, 766); fill(0,255,0); // draw the green button stroke(0); strokeWeight(5); rect(50, 80, 50, 50); noStroke( ); prize( ); // call the function to display cell content } void prize ( ) { //the first part of this function places a "prize" in each cell //the second part replaces one of them with a "golden prize" // Notice how the row and col variables are used to translate between // the list of prizes, which is 1-dimensional, and the 2-dimensional // grid of the game board int row, col, newworld; for (int i = 0; i < 25; i = i +1) { // Need 25 prizes for board if (random(0,2) < 1 ) { //Is it blue or green? fill(0,0,255); //blue prize = prize + 'B'; //record it } else { fill(0,255,0); //green prize = prize + 'G'; //record it } row = i % 5; //what row is it in? col = int(i/5); //what col is it in? ellipse(225+row*150, 225+col*150, 20, 20); //draw it } newworld = int(random(1,25)); //Where is exit to new world? fill(255,255,0); //Set color to gold row = newworld % 5; //Figure it's row col = int(newworld/5); //Figure it's col ellipse(225+row*150, 225+col*150, 20,20); // draw it //Now pull apart the prize string and stick the y for yellow //into it at the right place prize = prize.substring(0,newworld) + "y" + prize.substring(newworld+1,prize.length()); println(prize); //Watch it work! }