Problem with Tic tac toe
in
Programming Questions
•
5 months ago
Hi everybody!
Sorry for possible bad language in english but i'm french^^
I'm a beginner in processing (and in computer coding) an i have a tic tac toe to do as a small project for my computer class.
My problem is : how can i display crosses and circles in each square? For the moment my crosses and circles are only display in the upper left square, and i really have no idea of how to do that...
Thanks in advance for your help
Here is the code :
boolean a = false;
boolean b = false;
float x = mouseX;
float y = mouseY;
boolean c = true;
void setup(){
size (600, 600);
background (255);
}
void draw(){
if (keyPressed){
if (key == 'x'){
a = true;
b = true;
}
if (key == 'o'){
a = false;
b = true;
}
}
if (b == false){
titre();
menu();
}
else{
if (c == true){
grille();
c = false;
}
}
}
void mouseClicked(){
if ((a == true) && (mouseX < x) && (mouseY < y)){
println ("Je dessine des croix"); //I'm drawing crosses
croix(x, y);
a = false;
}
else{
println ("Je dessine des cercles"); //I'm drawing circles
cercles(x, y);
a = true;
}
}
//Affichage de la grille (grid display)
void grille(){
fill (255);
rect (0, 0, 600, 600);
for (x = 100; x <= 500; x += 200){
for (y = 100; y <= 500; y += 200){
rectMode (CENTER);
noFill();
rect (x, y, 200, 200);
}
}
}
//Affichage du titre (title display)
void titre(){
textSize (70);
text ("Jeu du Morpion", 40, 100); //Tic tac toe game
fill (0);
}
//Affichage du menu (menu display)
void menu(){
textSize (30);
text ("Qui commence?", 10, 400); //Who will begin?
text ("Si les croix commencent, tapez x.", 10, 440); //If crosses begin, type x.
text ("Si les cercles commencent, tapez o.", 10, 480); //If circles begin, type o.
fill (0);
}
//Affichage des cercles (circles display)
void cercles(float x, float y){
noFill();
stroke(0);
ellipseMode (CENTER);
ellipse (x-600, y-600, 190, 190);
}
//Affichage des croix (crosses display)
void croix(float x, float y){
line (x - 600, y - 600, x - 90 - 600, y - 90 - 600);
line (x - 600, y - 600, x + 90 - 600, y - 90 - 600);
line (x - 600, y - 600, x + 90 - 600, y + 90 - 600);
line (x - 600, y - 600, x - 90 - 600, y + 90 - 600);
}
1