I’m trying to make a simple tic tac toe game in processing. I don’t understand why the functions don’t follow the if() statements.
CODE:
int counter=0;
void setup(){
size(500,500);
background(255);
strokeWeight(15);
line(150,0,150,500);
line(350,0,350,500);
line(0,150,500,150);
line(0,350,500,350);
}
void draw(){
if(counter%2==0)
{
ellipse();
}
else{
triangle();
}
}
void keyReleased(){
counter=counter+1;
println(counter);
}
void ellipse(){
if (key=='a'){
fill(0);
ellipse(75,75,50,50);
}
if(key=='b'){
fill(0);
ellipse(250,75,50,50);
}
if(key=='c'){
fill(0);
ellipse(425,75,50,50);
}
if(key=='d'){
fill(0);
ellipse(75,250,50,50);
}
if(key=='e'){
fill(0);
ellipse(250,250,50,50);
}
if(key=='f'){
fill(0);
ellipse(425,250,50,50);
}
if(key=='g'){
fill(0);
ellipse(75,425,50,50);
}
if(key=='h'){
fill(0);
ellipse(250,425,50,50);
}
if(key=='i'){
fill(0);
ellipse(425,425,50,50);
}
}
void triangle(){
if(key=='1'){
fill(0);
triangle(35,125,115,125,75,25);
}
if(key=='2'){
fill(0);
triangle(210,125,290,125,250,25);
}
if(key=='3'){
fill(0);
triangle(385,125,465,125,425,25);
}
if(key=='4'){
fill(0);
triangle(35,300,115,300,75,200);
}
if(key=='5'){
fill(0);
triangle(210,300,290,300,250,200);
}
if(key=='6'){
fill(0);
triangle(385,300,465,300,425,200);
}
if(key=='7'){
fill(0);
triangle(35,475,115,475,75,375);
}
if(key=='8'){
fill(0);
triangle(210,475,290,475,250,375);
}
if(key=='9'){
fill(0);
triangle(385,475,465,475,425,375);
}
}