-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.cpp
97 lines (91 loc) · 2.94 KB
/
timer.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
#include "board.h"
#include "timer.h"
#include <windows.h>
#include <iostream>
using namespace std;
/**
* @brief Retrieves the current local time as a string.
*
* This function obtains the current local time and returns it as a
* string in a human-readable format. The time is formatted according
* to the system's locale and returned as a character array.
*
* @return char* A string representing the current local time.
*/
char *Timer::getCurrentTime()
{
time_t rawTime;
struct tm *localTime;
time(&rawTime); // Get the current time
localTime = localtime(&rawTime); // Convert to local time structure
return asctime(localTime); // Convert to string and return
}
/**
* @brief Displays a countdown from 3 to 1 before the game starts.
*
* This function displays the numbers 3, 2, and 1 in sequence, each for a short duration.
* The numbers are centered on the screen and are erased after being displayed.
*
* @return void
*/
void Timer::displayCountdown()
{
Board board;
const int countdownDuration = 1; // Duration to display each number (in seconds)
const int numSize = 6; // Size of the numbers 1 and 2
const int largerNumSize = 7; // Size of the number 3
// Display and erase the number '1'
for (int y = 0; y < numSize; y++)
{
for (int x = 0; x < numSize; x++)
{
board.setCursorPosition(PLAY_AREA_WIDTH / 2 + x - 3, SCREEN_HEIGHT / 2 + y - 3);
std::cout << digitOne[y][x]; // Display '1'
}
}
Sleep(countdownDuration);
for (int y = 0; y < numSize; y++)
{
for (int x = 0; x < numSize; x++)
{
board.setCursorPosition(PLAY_AREA_WIDTH / 2 + x - 3, SCREEN_HEIGHT / 2 + y - 3);
std::cout << " "; // Erase '1'
}
}
// Display and erase the number '2'
for (int y = 0; y < numSize; y++)
{
for (int x = 0; x < numSize; x++)
{
board.setCursorPosition(PLAY_AREA_WIDTH / 2 + x - 3, SCREEN_HEIGHT / 2 + y - 3);
std::cout << digitTwo[y][x]; // Display '2'
}
}
Sleep(countdownDuration);
for (int y = 0; y < numSize; y++)
{
for (int x = 0; x < numSize; x++)
{
board.setCursorPosition(PLAY_AREA_WIDTH / 2 + x - 3, SCREEN_HEIGHT / 2 + y - 3);
std::cout << " "; // Erase '2'
}
}
// Display and erase the number '3'
for (int y = 0; y < largerNumSize; y++)
{
for (int x = 0; x < largerNumSize; x++)
{
board.setCursorPosition(PLAY_AREA_WIDTH / 2 + x - 3, SCREEN_HEIGHT / 2 + y - 3);
std::cout << digitThree[y][x]; // Display '3'
}
}
Sleep(countdownDuration);
for (int y = 0; y < largerNumSize; y++)
{
for (int x = 0; x < largerNumSize; x++)
{
board.setCursorPosition(PLAY_AREA_WIDTH / 2 + x - 3, SCREEN_HEIGHT / 2 + y - 3);
std::cout << " "; // Erase '3'
}
}
}