for a project for school we have to make a game
but there is a timelimit while playing the game, the player can only play for 3 minutes
I have allreayd googled for quite a while, but I still can't find how to
so basicly my problem is:
1 how can I run a clock/timer?
2 how can I make it run in the background of a program so it will only influence the gameplay when the 3 minutes barriere is reached
Clock
Started by Shaddix, Apr 23 2009 04:20 AM
3 replies to this topic
#1
Posted 23 April 2009 - 04:20 AM
|
|
|
#2
Posted 23 April 2009 - 07:57 AM
To start with, you want to get the system time when the game starts. Then, for every action, you can check the time and compare it to the time when the game started.
#3
Posted 24 April 2009 - 12:21 AM
To check system time I guess this method in the Calendar class works good:
int time = Calendar.getInstance( ).getTimeInMillis( );
#4
Posted 26 April 2009 - 06:19 AM
Then, to get it to run in the background you need to instantiate a new thread.
Something like:
HTH
Something like:
public class Timer implements runnable{
public void run(){
Calendar finish = Calendar.getInstance();
finish.add(Calendar.MINUTE, 3);
while(true){
if(finish.before(Calendar.getInstance())){
System.out.println("You've been playing for three minutes now");
break;
}
}
}
}
Thread t = new Thread(new Timer()); t.start();
HTH


Sign In
Create Account


Back to top









