-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameTimer.cs
More file actions
87 lines (69 loc) · 2.7 KB
/
GameTimer.cs
File metadata and controls
87 lines (69 loc) · 2.7 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WindowsGame1
{
public class GameTimer
{
/// <summary>
/// A timer that is Enabled after a certain amount of time.
/// </summary>
/// <remarks>
/// First parameter is the wait time and the second parameter is the active time.
/// </remarks>
System.Timers.Timer ActiveTimer;
System.Timers.Timer WaitTimer;
/// <summary>
/// Returns true is WaitTime is over and ActiveTime is still running.
/// </summary>
public bool Active
{
get { return ActiveTimer.Enabled && !WaitTimer.Enabled; }
}
/// <summary>
/// Returns true if ButtonTimer is Active
/// </summary>
public bool Enabled
{
get { return ActiveTimer.Enabled; }
}
protected int TimerInterval;
protected int WaitTimerInterval;
public GameTimer(int WaitTime, int ActiveTime)
{
this.WaitTimerInterval = WaitTime;
this.TimerInterval = ActiveTime + WaitTime;
this.ActiveTimer = new System.Timers.Timer(TimerInterval);
this.ActiveTimer.Elapsed += new System.Timers.ElapsedEventHandler(ActiveTimer_Elapsed);
this.WaitTimer = new System.Timers.Timer(WaitTimerInterval);
this.WaitTimer.Elapsed += new System.Timers.ElapsedEventHandler(WaitTimer_Elapsed);
}
public GameTimer(float WaitTime, float ActiveTime)
{
this.WaitTimerInterval = (int)WaitTime;
this.TimerInterval = (int)(ActiveTime + WaitTime);
this.ActiveTimer = new System.Timers.Timer(TimerInterval);
this.ActiveTimer.Elapsed += new System.Timers.ElapsedEventHandler(ActiveTimer_Elapsed);
this.WaitTimer = new System.Timers.Timer(WaitTimerInterval);
this.WaitTimer.Elapsed += new System.Timers.ElapsedEventHandler(WaitTimer_Elapsed);
}
public void Start()
{
ActiveTimer.Start();
WaitTimer.Start();
}
void ActiveTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
ActiveTimer.Dispose();
ActiveTimer = new System.Timers.Timer(TimerInterval);
ActiveTimer.Elapsed += new System.Timers.ElapsedEventHandler(ActiveTimer_Elapsed);
}
void WaitTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
WaitTimer.Dispose();
WaitTimer = new System.Timers.Timer(WaitTimerInterval);
WaitTimer.Elapsed += new System.Timers.ElapsedEventHandler(WaitTimer_Elapsed);
}
}
}