Arrays: Scissors, Paper, Rock.

If you want to control lots of things in one program – perhaps lots of pokemon on a screen, or lots of minecraft mobs you need a way to store the all the information that tells the computer where and when to draw them.

You will need an ARRAY.

An array is very much like a variable – Its actually a collection of variables.

Remember that variables are like boxes with a name on the front designed to hold particular types of objects.. like numbers for instances (int) or words (strings).

An array is like an egg carton…..  it doesn’t hold one egg it holds 12 … all separated into their own compartments. With an array we can hold lots of numbers or words all held in there own little compartment or cell.

Today we are going to learn how to use a simple array in order to play a game of   paper, scissors, rock.  We are going to make an array  (an egg carton) that holds 5 words.

We are then going to draw one of those words out randomly from our array/egg carton…..

String[] weapons = new String[5];

void setup() {
    size(600,600);
    noLoop();
    
    weapons[0] = "paper"; 
    weapons[1] = "scissors";
    weapons[2] = "rock";
    weapons[3] = "axe";
    weapons[4] = "sword";
}

void draw(){
  textSize(100);
  fill(255);
  int number = (int)random(4);
  text( weapons[number] , 40, 300);  
}