homework policy * asking questions
int[] Felder = new int[9];
int spielerFlag = 0;
int x = 0;
int y = 0;
int win = 0;
int tp = 0;
boolean reset = false;
void setup() {
size(displayWidth, displayHeight);
strokeWeight(10);
frameRate(60);
smooth(5);
for (int i=0; i<9; i++) {// das ist der reset man muss nur noch ein delay nutzen
Felder[i]=0;
}
background(169, 169, 169);
zeichneSpielfeld();
}
void draw() {
int count =0;
for (int i : Felder) {
if (i==1) {
zeichneEllipse((count%3)*200+200, int(count/3)*200+100+100, 100);
}
if (i==2) {
zeichneKreuz((count%3)*200+200, int(count/3)*200+50+150, 150);
}
count++;
}
Text();
gameOver();
Reset();
}
void zeichneKreuz(int xM, int yM, int a) {
stroke(0, 255, 0);
line(xM-a/2, yM+a/2, xM+a/2, yM-a/2);
line(xM+a/2, yM+a/2, xM-a/2, yM-a/2);
}
void zeichneEllipse(int xM, int yM, int a) {
stroke(255, 0, 0);
fill(255, 255, 255);
ellipse(xM, yM, a, a);
}
void Reset() {
if (reset == true) {
fill(0, 0, 0);
text("Reset in 5 Sekunden", 780, 300);
}
delay(5000);
{
}
}
void mousePressed() {
if (mouseX>100 && mouseX<700 && mouseY>100 && mouseY<700) {
y= int((mouseY-100)/200);
x= int((mouseX-100)/200);
int count = y*3+x;
if (Felder[count]==0) {
if (spielerFlag == 0) {
Felder[y*3+x] = 1;
}
if (spielerFlag==1) {
Felder[y*3+x] = 2;
}
tp++;
spielerFlag = (spielerFlag+1)%2;
}
}
}
void zeichneSpielfeld() {
stroke(0, 0, 0);
rect(100, 100, 600, 600);
line(100, 300, 700, 300);
line(100, 500, 700, 500);
line(300, 100, 300, 700);
line(500, 100, 500, 700);
}
void gameOver() {
if (Felder[0] == 1 && Felder[1] == 1 && Felder[2] == 1 ) {
win = 1;
}
if (Felder[3] == 1 && Felder[4] == 1 && Felder[5] ==1 ) {
win = 1;
}
if (Felder[6] == 1 && Felder[7] == 1 && Felder[8] ==1 ) {
win = 1;
}
if (Felder[0] == 1 && Felder[3] == 1 && Felder[6] ==1 ) {
win = 1;
}
if (Felder[1] == 1 && Felder[4] == 1 && Felder[7] ==1 ) {
win = 1;
}
if (Felder[2] == 1 && Felder[5] ==1 && Felder[8] ==1 ) {
win = 1;
}
if (Felder[0] == 1 && Felder[4] ==1 && Felder[8] ==1 ) {
win = 1;
}
if (Felder[2] == 1 && Felder[4] ==1 && Felder[6] ==1 ) {
win = 1;
}
if (Felder[0] == 2 && Felder[1] == 2 && Felder[2] == 2 ) {
win = 2;
}
if (Felder[3] == 2 && Felder[4] == 2 && Felder[5] ==2 ) {
win = 2;
}
if (Felder[6] == 2 && Felder[7] == 2 && Felder[8] ==2 ) {
win = 2;
}
if (Felder[0] == 2 && Felder[3] == 2 && Felder[6] ==2 ) {
win = 2;
}
if (Felder[1] == 2 && Felder[4] == 2 && Felder[7] ==2 ) {
win = 2;
}
if (Felder[2] == 2 && Felder[5] ==2 && Felder[8] ==2 ) {
win = 2;
}
if (Felder[0] == 2 && Felder[4] ==2 && Felder[8] ==2 ) {
win = 2;
}
if (Felder[2] == 2 && Felder[4] ==2 && Felder[6] ==2 ) {
win = 2;
}
boolean remis = false;
if (tp == 9) {
remis = true;
}
if (win == 1) {
print("Kreis hat gewonnen!");
noLoop();
reset = true;
}
if (win == 2) {
print("Kreuz hat gewonnen!");
noLoop();
reset = true;
}
if (win == 0 && remis == true) {
print("Unentschieden!");
reset = true;
}
}
void Text() {
textSize(60);
fill(255, 0, 0);
text("Tic", 265, 80);
fill(0, 255, 0);
text("Tac", 348, 80);
fill(0, 0, 255);
text("Toe", 445, 80);
}
So my code works in the fact that I can play Tic Tac Toe but I wanted to make like an automatic reset 5 sec after someone won/remis. I tried doing it with delay(naptime); but I think I did something wrong because after I wrote delay(5000); in my reset code evrything in the tic tac toe game had a delay. I want to make it like the board gets set to 0 and you can play another round.