# How to make: if timer is finished end game

**URL:** https://discourse.processing.org/t/how-to-make-if-timer-is-finished-end-game/25661
**Category:** Coding Questions
**Created:** [November 24, 2020, 11:24am UTC](https://discourse.processing.org/t/how-to-make-if-timer-is-finished-end-game/25661 "2020-11-24T11:24:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![TheGullible1](https://avatars.discourse-cdn.com/v4/letter/t/7bcc69/32.png) [@TheGullible1](https://discourse.processing.org/u/TheGullible1)
#### Post date: [November 24, 2020, 11:24am UTC](https://discourse.processing.org/t/how-to-make-if-timer-is-finished-end-game/25661/1 "2020-11-24T11:24:01Z")

</div>

Hi, I’m tryna make an if statement consisting of my timer and how to end the game after my countdown of 60 seconds has finished.

i have a class called countdown:

```auto
class CountDown //start of CountDown class
{ 
  private int durationSeconds; 

  public CountDown(int duration) 
  { 
    this.durationSeconds = duration;
  }    
  public int getRemainingTime() //return the seconds left on the timer or 0 
  { //millis() processing command, returns time in 1000ths sec since program started 
    return max(0, durationSeconds - millis()/1000) ;
  }
} //end of class

```

and in my main I have:

```auto
CountDown timer; //declare instance variable of CountDown

void setup()
{
size(400,500);
timer = new CountDown(60); //call CountDown constructor – 60 secs
}

void draw()
{
 fill(255, 255, 0);
  textSize(26);
  text("Score: " + score, 10, 50);

  text(timer.getRemainingTime(), 20, 20); //display seconds remaining top left
}

```

what I’m trying to do is, once my timer finishes I want the GameMode == FINISHED. but I don’t know how to say once timer is finished I tried  
if timer.getremainingtime = 0 then do this… but sadly that doesn’t work as well.

---

<div class="post-metadata">

### Author: ![MiguelSanches](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/miguelsanches/32/11172_2.png) [@MiguelSanches](https://discourse.processing.org/u/MiguelSanches)
#### Post date: [November 24, 2020, 11:31am UTC](https://discourse.processing.org/t/how-to-make-if-timer-is-finished-end-game/25661/2 "2020-11-24T11:31:21Z")

</div>

Hi @TheGullible1

The class method getRemainingTime() returns the remaining time of the timer as an integer

```auto
return max(0, durationSeconds - millis()/1000) ;

```

If the timer gets to 0, it will always return 0 so an If condition can check if the timer hit 0 and finish the game.  
As an example check the code below:

```auto
class CountDown //start of CountDown class
{ 
  private int durationSeconds; 

  public CountDown(int duration) 
  { 
    this.durationSeconds = duration;
  }    
  public int getRemainingTime() //return the seconds left on the timer or 0 
  { //millis() processing command, returns time in 1000ths sec since program started 
    return max(0, durationSeconds - millis()/1000) ;
  }
} //end of class

CountDown timer; //declare instance variable of CountDown

void setup()
{
size(400,500);
timer = new CountDown(10); //call CountDown constructor – 60 secs
}
int score = 0;
void draw()
{
  background(240);
 fill(0);
  textSize(26);
  text("Score: " + score, 10, 50);

  text(timer.getRemainingTime(), 20, 20); //display seconds remaining top left
  if(timer.getRemainingTime() == 0){ //Check if the timer finished countdown
   text("FINISH", width/2, height/2); 
  }
}

```

Hope it helps! 🙂  
Best regards

---

<div class="post-metadata">

### Author: ![TheGullible1](https://avatars.discourse-cdn.com/v4/letter/t/7bcc69/32.png) [@TheGullible1](https://discourse.processing.org/u/TheGullible1)
#### Post date: [November 24, 2020, 11:39am UTC](https://discourse.processing.org/t/how-to-make-if-timer-is-finished-end-game/25661/3 "2020-11-24T11:39:17Z")

</div>

Thank you so much, it worked perfectly \<3
