# I need to make a reset timer in my Tic Tac Toe game

**URL:** <https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [April 6, 2022, 6:37am UTC](https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149 "2022-04-06T06:37:44Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mori](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Mori](https://discourse.processing.org/u/Mori)\
**Post date:** [April 6, 2022, 6:37am UTC](https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149/1 "2022-04-06T06:37:44Z")

</div>

[homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

```auto
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.

---

<div class="post-metadata">

**Author:** ![Mori](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Mori](https://discourse.processing.org/u/Mori)\
**Post date:** [April 6, 2022, 6:40am UTC](https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149/2 "2022-04-06T06:40:55Z")

</div>

And I dont know how to set the board to 0. My teacher told me I have to use this: for (int i=0; i\<9; i++), for it but I dont know how to do that

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 6, 2022, 10:08am UTC](https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149/3 "2022-04-06T10:08:12Z")

</div>

> [@Mori](#):
>
> ```auto
> void Reset() {
> if (reset == true) {
> fill(0, 0, 0);
> text("Reset in 5 Sekunden", 780, 300);
> }
> delay(5000);
> 
> ```

In your program the delay command  
should be inside the if clause.

It won’t work then anyway either.

Instead say

```auto
if ( millis() - timer > 5000) {
   reset=false;
     for (int i=0; i<9; i++) {// das ist der reset man muss nur noch ein delay nutzen
    Felder[i]=0;
  }
}//

```

---

<div class="post-metadata">

**Author:** ![Mori](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Mori](https://discourse.processing.org/u/Mori)\
**Post date:** [April 6, 2022, 10:47am UTC](https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149/4 "2022-04-06T10:47:50Z")

</div>

First of all thank you for your answer. It still doesnt clear the board. How can I make it so it clears the board?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 6, 2022, 12:05pm UTC](https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149/5 "2022-04-06T12:05:45Z")

</div>

> [@Mori](#):
>
> `background(169, 169, 169);`

You want to have this additionally at start of draw()

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 6, 2022, 12:07pm UTC](https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149/6 "2022-04-06T12:07:24Z")

</div>

set int timer to millis() when you set reset to true please

---

<div class="post-metadata">

**Author:** ![Mori](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Mori](https://discourse.processing.org/u/Mori)\
**Post date:** [April 6, 2022, 2:23pm UTC](https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149/7 "2022-04-06T14:23:37Z")

</div>

you mean it like this?

```auto
int[] Felder = new int[9];
int spielerFlag = 0;
int x = 0;
int y = 0;
int win = 0;
int tp = 0;
boolean reset = false;
int timer = millis();

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;
  }

  zeichneSpielfeld();
}

void draw() {
  background(169, 169, 169);
  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 ( millis() - timer > 5000) {
   reset=true;
     for (int i=0; i<9; i++) {// das ist der reset man muss nur noch ein delay nutzen
    Felder[i]=0;
  }
}//
}
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);
}

```

---

<div class="post-metadata">

**Author:** ![MadSam](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@MadSam](https://discourse.processing.org/u/MadSam)\
**Post date:** [April 6, 2022, 2:34pm UTC](https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149/8 "2022-04-06T14:34:45Z")

</div>

Hi, I don’t know if it can help you, i wrote this little code :

```auto
int mill;
int second = 0;
int start;
void timer(int limit){
  mill = (millis());
  if((second + start) != mill/1000){
    second = second+1;
  }
  println (second);
  if(second > limit){
    start = start + second;
    second = 0;
    // do something...
  }
}
void draw(){
  timer(5);
}

```

Best regards.

---

<div class="post-metadata">

**Author:** ![Mori](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Mori](https://discourse.processing.org/u/Mori)\
**Post date:** [April 6, 2022, 4:39pm UTC](https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149/9 "2022-04-06T16:39:53Z")

</div>

Yes it helped a lot the delay is working now. Do you have any know how I can potentually do the board cleaner?

---

<div class="post-metadata">

**Author:** ![MadSam](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@MadSam](https://discourse.processing.org/u/MadSam)\
**Post date:** [April 6, 2022, 4:57pm UTC](https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149/10 "2022-04-06T16:57:43Z")

</div>

What do you mean by “cleaner”?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 6, 2022, 5:08pm UTC](https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149/11 "2022-04-06T17:08:15Z")

</div>

> [@Mori](#):
>
> ```auto
> zeichneSpielfeld();
> 
> ```

Also this at start of draw after background

---

<div class="post-metadata">

**Author:** ![Mori](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Mori](https://discourse.processing.org/u/Mori)\
**Post date:** [April 6, 2022, 5:11pm UTC](https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149/12 "2022-04-06T17:11:53Z")

</div>

Look what happens now:

```auto
int[] Felder = new int[9];
int spielerFlag = 0;
int x = 0;
int y = 0;
int win = 0;
int tp = 0;
boolean reset = false;
int timer = millis();

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;
  }
}

void draw() {
  background(169, 169, 169);
  zeichneSpielfeld();
  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();
  ResetText();
}
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 ResetText() {
  if (reset == true) {
    fill(0, 0, 0);
    text("Reset in 5 Sekunden", 780, 300);
  }
}
void Reset() {
  if (reset == true) {
    if ( millis() - timer == 5000) {
      print("...");
    }
  }//
}

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);
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 6, 2022, 5:24pm UTC](https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149/13 "2022-04-06T17:24:20Z")

</div>

> [@Mori](#):
>
> ```auto
> void Reset(){
> if ( millis() - timer > 5000) {
> reset=true;
> for (int i=0; i<9; i++) {// das ist der reset man muss nur noch ein delay nutzen
> Felder[i]=0;
> }
> }//
> 
> ```

instead

```auto
void Reset(){
if (reset){ // I forgot this 
if ( millis() - timer > 5000) { // use > here !!!!!
   reset=false; // !!!!!!!!!!!!!!!!!!!!
     for (int i=0; i<9; i++) {// das ist der reset man muss nur noch ein delay nutzen
    Felder[i]=0;
  }
}//
}//

```

---

<div class="post-metadata">

**Author:** ![Mori](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Mori](https://discourse.processing.org/u/Mori)\
**Post date:** [April 6, 2022, 5:30pm UTC](https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149/14 "2022-04-06T17:30:57Z")

</div>

Ok I did it do you have any idea what my teacher meant when he said that I have to use this here to clear the board?

```auto
 for (int i=0; i<9; i++) {// das ist der reset man muss nur noch ein delay nutzen
    Felder[i]=0;

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 6, 2022, 8:01pm UTC](https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149/15 "2022-04-06T20:01:22Z")

</div>

> [@Mori](#):
>
> Ok I did it

So, did it work?

> [@Mori](#):
>
> do you have any idea what my teacher meant when he said that I have to use this here to clear the board?
> 
> ```auto
> for (int i=0; i<9; i++) {// das ist der reset man muss nur noch ein delay nutzen
> Felder[i]=0;
> 
> ```

Your teacher was right. Those are the lines I used.  
For a delay we use the if clause with millis().

**Remarks**

You had `noLoop()` in a few places. No chance to reset anything then!  
We need to say `timer = millis();` when you detect a win or a remis.

**Here is my version**

I also added `if (reset==false) {` where you decide who has won, so it is avoided that `timer = millis()` is executed again and again. Then the timer wouldn’t work anymore.

We also need to reset spielerFlag = 0; and win = 0; for a new game.

Warm regards,

Chrisir

```auto

int[] Felder = new int[9];
int spielerFlag = 0;
int x = 0;
int y = 0;
int win = 0;
int tp = 0;
boolean reset = false;
int timer = millis();
String message; 

void setup() {
  size(displayWidth, displayHeight);
  strokeWeight(10);

  frameRate(60);
  smooth(5);
  for (int i=0; i<9; i++) {// das ist der reset 
    Felder[i]=0;
  }

  background(169, 169, 169);
  zeichneSpielfeld();
}

void draw() {
  background(169, 169, 169);
  zeichneSpielfeld();

  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();
  ResetText();
}

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);
  noFill(); 
  ellipse(xM, yM, a, a);
}

void ResetText() {
  if (reset) {
    fill(0, 0, 0);
    text("Reset in 5 Sekunden", 780, 300);
    text(message, 780, 300+111);
  }
}

void Reset() {
  // Wenn das Spiel vorüber ist
  if (reset) {  
    // Und 5 Sekunden verstrichen sind 
    if ( millis() - timer > 5000) {  
      // reset 
      reset=false;
      message=""; 
      spielerFlag = 0;
      win = 0;
      tp = 0;
      for (int i=0; i<9; i++) {// das ist der reset 
        Felder[i]=0;
      }
    }//
  }
}

void mousePressed() {
  if (mouseX>100 && mouseX<700 && mouseY>100 && mouseY<700) {
    x= int((mouseX-100)/200);
    y= int((mouseY-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);
  fill(0, 0, 255);
  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;
  }

  if (reset==false) {
    boolean remis = false;
    if (tp == 9) {
      remis = true;
    }
    if (win == 1) {
      println("Kreis hat gewonnen!");
      message="Kreis hat gewonnen!";
      reset = true;
      timer = millis();
    }
    if (win == 2) {
      println("Kreuz hat gewonnen!");
      message="Kreuz hat gewonnen!";
      reset = true;
      timer = millis();
    }
    if (win == 0 && remis == true) {
      print("Unentschieden!");
      message="Unentschieden"; 
      reset = true;
      timer = millis();
    }
  }
}
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);
}

```

---

<div class="post-metadata">

**Author:** ![Mori](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Mori](https://discourse.processing.org/u/Mori)\
**Post date:** [April 7, 2022, 8:07am UTC](https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149/16 "2022-04-07T08:07:04Z")

</div>

Thank you so much it works perfectly!

---

<div class="post-metadata">

**Author:** ![Quertz](https://avatars.discourse-cdn.com/v4/letter/q/cc9497/32.png) [@Quertz](https://discourse.processing.org/u/Quertz)\
**Post date:** [April 10, 2022, 2:40pm UTC](https://discourse.processing.org/t/i-need-to-make-a-reset-timer-in-my-tic-tac-toe-game/36149/17 "2022-04-10T14:40:34Z")

</div>

If you use an if in every draw-call to test if the time is over, then you can alternatively just count back a number and reset when that number is 0. That‘s how I do it.
