-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemporizador.java
106 lines (100 loc) · 2.5 KB
/
Temporizador.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import java.awt.*;
import java.awt.event.*;
/**
* this class should work in two modes:
* calculate the time
* cater the time to the client
*/
class Temporizador
{
Player team;
int timeSec;
int timeMin;
int timeHr;
boolean status=false,ignoreme;//paused by default
public Temporizador(Player c)
{
team=c;
analyzeTimeType();
if(!ignoreme)
{
new javax.swing.Timer(1000,new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(status)
{
timeSec--;
if(timeSec<0)
{
timeSec+=60;
timeMin--;
if(timeMin<0)
{
timeMin+=60;
timeHr--;
if(timeHr<0)
{
//status=false;
}
}
}
if(timeHr<0 && game.isGameActive() )
{
game.endGame(team.getName()+" lost",team.getName()+" Ran out of time ");
status=false;
}
}
}
}).start();
}
}
public Color getTeamColor()
{
return team.getColor();
}
public String getUCITime()
{
String s=null;
if(team.getColor().equals(goti.colWhit))
s="wtime ";
else
s="btime ";
int msc;
if(!ignoreme)
msc=timeSec+(60*timeMin)+(3600*timeHr);
else
msc=2;
msc*=1000;
s+=msc;
//System.out.println(timeSec+" "+timeMin);
return s;
}
public void analyzeTimeType()
{
//TimeType t=game.timeGame;
if(true)//if unlimited time then no point in analyzing
{
ignoreme=true;
return;
}
//timeSec=t.getSeconds();
//timeMin=t.getMinutes();
//timeHr=t.getHours();
}
public String getTime()
{
if(!ignoreme)
return String.format("%02d",timeHr)+":"+String.format("%02d",timeMin)+":"+String.format("%02d",timeSec);
else
return "";
}
public void start()
{
status=true;
}
public void pause()
{
status=false;
}
}