-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeClass.h
83 lines (65 loc) · 1.49 KB
/
TimeClass.h
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
#pragma once
#include<iostream>
#include<windows.h>
#include<ctime>
#include<time.h>
using namespace std;
vector <int> hour;
vector <int> minute;
vector <int> second;
static int RoundT = 0;
bool Wait(const unsigned long& Time);
void sleep(long wait)
{
clock_t start = clock();
while (clock() - start < wait);
}
class Time
{
private:
int time;
public:
void settime(int h , int m , int s)
{
hour.push_back(h);
minute.push_back(m);
second.push_back(s);
RoundT++;
}
};
class Timer : public Time
{
private:
public:
void gettime(int Round)
{
cout << hour.at(Round-1) << ":" << minute.at(Round - 1) << ":" << second.at(Round - 1) << endl;
}
void settimer(int Round)
{
int counter = hour.at(Round - 1) * 3600 + minute.at(Round - 1) * 60 + second.at(Round - 1);
if (!Wait(1000));
while (counter >= 1)
{
cout << "Time remaining: " << counter ;
if (!Wait(1000));
counter--;
}
}
};
bool Wait(const unsigned long& Time)
{
clock_t Tick = clock_t(float(clock()) / float(CLOCKS_PER_SEC) * 1000.f);
if (Tick < 0) // if clock() fails, it returns -1
return 0;
clock_t Now = clock_t(float(clock()) / float(CLOCKS_PER_SEC) * 1000.f);
if (Now < 0)
return 0;
while ((Now - Tick) < Time)
{
Now = clock_t(float(clock()) / float(CLOCKS_PER_SEC) * 1000.f);
if (Now < 0)
return 0;
}
return 1;
}