-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFencingTimer.cpp
132 lines (114 loc) · 2.69 KB
/
FencingTimer.cpp
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//Copyright (c) Piet Wauters 2022 <[email protected]>
#include "FencingTimer.h"
#include <iostream>
using namespace std;
FencingTimer::FencingTimer()
{
//ctor
m_ResolutionCounter = m_DisplayResolution;
MakeNewString();
}
FencingTimer::~FencingTimer()
{
//dtor
}
void FencingTimer::MakeNewString()
{
if((m_Minutes == 0) && (m_Seconds < 10))
{
sprintf(m_TimerString,"%u.%02u",m_Seconds,m_Hundredths);
}
else
{
sprintf(m_TimerString,"%u:%02u",m_Minutes,m_Seconds);
}
}
void FencingTimer::GetFormattedStringTime(char *Destination, int MinutePrecision, int HundredthsPrecision)
{
// Minutes can have 1 or 2 digits
// Seconds always have 2 digits
// Hundredths can have 0, 1 or 2 digits
char temp[8];
if(m_Minutes > 9) // I need 2 digits regardless of the minuteprecision
{
sprintf(Destination,"%02u:%02u",m_Minutes,m_Seconds);
}
else
{
if(MinutePrecision > 1)
sprintf(Destination,"%02u:%02u",m_Minutes,m_Seconds);
else
sprintf(Destination,"%1u:%02u",m_Minutes,m_Seconds);
}
if(HundredthsPrecision > 0)
{
if(HundredthsPrecision == 1)
{
sprintf(temp,".%u",(m_Hundredths)/10);
}
else
{
sprintf(temp,".%02u",m_Hundredths);
}
strcat(Destination,temp);
}
}
bool FencingTimer::DoTick()
{
if(!m_TimerIsRunning)
return false;
m_Ticks++;
if(m_Ticks < m_TicksInOneHundreth)
return false;
m_Ticks = 1;
bool returnvalue = false;
if(m_Hundredths > 0)
{
m_Hundredths--;
if(m_ShowingHundredths)
{
m_ResolutionCounter--;
if(!m_ResolutionCounter)
{
MakeNewString();
m_ResolutionCounter = m_DisplayResolution;
returnvalue = true;
}
}
}
else
{
returnvalue = true;
if(m_Seconds > 0)
{
m_Seconds--;
m_Hundredths = 99;
if((m_Minutes == 0) && (m_Seconds < 10))
{
m_ShowingHundredths = true;
return false;
}
else
m_ShowingHundredths = false;
}
else
{
if(m_Minutes > 0)
{
m_Minutes--;
m_Seconds=59;
m_Hundredths = 99;
}
else
{
m_TimerIsRunning = false;
return true;
}
MakeNewString();
m_Seconds = 59;
return true;
}
MakeNewString();
}
return returnvalue;
}