|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectJTP.GameTimer
public class GameTimer
Class for controlling timed levels. Uses Timer class provide by swing framework.
Constructor Summary | |
---|---|
GameTimer(String beepSoundName,
Screen s,
GamePlayer gp)
Constructs a new GameTimer instance with the given
attributes. |
Method Summary | |
---|---|
long |
getAccumulatedTime()
Returns time added up by using incrementAccumulatedTime()
method for active timer. |
long |
getAccumulatedTimeSeconds()
Returns time added up by using incrementAccumulatedTime()
method, in seconds, for active timer. |
boolean |
hasStarted()
Indicates whether start() method has been called. |
void |
incrementAccumulatedTime()
Adds the currently leftover time to the total for active timer. |
boolean |
isActive()
Indicates whether a time limit has been set. |
void |
reset()
Resets start and stop times for all timers as well as setting active timer back to the default. |
void |
reset(int activeTimer)
Resets start and stop times for all timers as well as setting active timer back to specified one. |
void |
resetAccumulatedTime()
Resets the time added up by using incrementAccumulatedTime()
method back to zero for active timer. |
void |
resume()
Continues countdown of a timer stopped by stop() . |
void |
setTimeLimit(int timeLimit)
Sets time limit to use. |
void |
start()
Starts the active timer if a time limit has been set. |
void |
stop()
Stops the active timer. |
void |
stopAll()
Stops all (both) timers. |
void |
swapActiveTimer()
Sets other timer to active one. |
long |
timeLeft()
Returns time remaining for active timer. |
long |
timeLeft(int index)
Returns time remaining. |
boolean |
timeUpdateRequested()
Used to decide whether the whole screen or just timer display has to be rendered. |
String |
toString()
Returns time remaining for active timer in mm:ss format. |
String |
toString(int index)
Returns time remaining in mm:ss format. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public GameTimer(String beepSoundName, Screen s, GamePlayer gp)
GameTimer
instance with the given
attributes. Note: The timer is not started upon construction.
s
- parent rendering instancegp
- gameplay instanceMethod Detail |
---|
public void start()
public boolean hasStarted()
start()
method has been called.
true
if start()
has been called since
construction or the last reset()
call.public void stop()
public void stopAll()
public void resume()
stop()
.
public void swapActiveTimer()
public void reset()
public void reset(int activeTimer) throws IllegalArgumentException
activeTimer
- either GamePlayer.P1
or
GamePlayer.P2
IllegalArgumentException
- if activeTimer
is not one
of GamePlayer.P1
or GamePlayer.P2
.public void resetAccumulatedTime()
incrementAccumulatedTime()
method back to zero for active timer.
public void setTimeLimit(int timeLimit) throws IllegalArgumentException
timeLimit
- time in seconds. Set this to zero for no time limit.
IllegalArgumentException
- if timeLimit < 0
.public void incrementAccumulatedTime()
public long getAccumulatedTime()
incrementAccumulatedTime()
method for active timer.
public long getAccumulatedTimeSeconds()
incrementAccumulatedTime()
method, in seconds, for active timer. Note: The returned value will have
been rounded up to the nearest second.
public boolean timeUpdateRequested()
public boolean isActive()
true
if a time limit has been set.public long timeLeft()
public long timeLeft(int index)
index
- either GamePlayer.P1
or
GamePlayer.P2
.
public String toString()
mm:ss
format.
toString
in class Object
String
representation.public String toString(int index) throws IllegalArgumentException
mm:ss
format.
index
- either GamePlayer.P1
or
GamePlayer.P2
.
String
representation.
IllegalArgumentException
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |