-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock-puzzle.cpp
More file actions
68 lines (59 loc) · 1.93 KB
/
clock-puzzle.cpp
File metadata and controls
68 lines (59 loc) · 1.93 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
#include <iostream>
#include <ctime>
#include <thread>
#include <chrono>
using namespace std;
string getCurrentTime() {
time_t currentTime = time(0);
tm *localTime = localtime(¤tTime);
char timeString[10];
snprintf(timeString, sizeof(timeString), "%02d:%02d:%02d", localTime->tm_hour, localTime->tm_min, localTime->tm_sec);
return string(timeString);
}
void displayClock(int level) {
string time = getCurrentTime();
if (level == 1) {
cout << "\033[1;32m" << "Clock (Level 1): " << time << "\033[0m" << endl;
} else if (level == 2) {
cout << "\033[1;34m" << "Clock (Level 2): " << time << "\033[0m" << endl;
} else if (level == 3) {
cout << "\033[1;31m" << "Clock (Level 3): " << time << "\033[0m" << endl;
}
}
bool checkPuzzleAnswer(int level) {
string answer;
if (level == 1) {
cout << "Puzzle 1: What is 2 + 2? ";
cin >> answer;
return answer == "4";
} else if (level == 2) {
cout << "Puzzle 2: What is the capital of France? ";
cin >> answer;
return answer == "Paris" || answer == "paris";
} else if (level == 3) {
cout << "Puzzle 3: Spell 'programming' backward: ";
cin >> answer;
return answer == "gnimmargorp";
}
return false;
}
int main() {
int level = 1;
bool puzzleSolved = false;
while (level <= 3) {
system("clear");
displayClock(level);
cout << "\nSolve the puzzle to progress to the next level.\n";
puzzleSolved = checkPuzzleAnswer(level);
if (puzzleSolved) {
cout << "\nCorrect! Moving to Level " << level + 1 << "...\n";
this_thread::sleep_for(chrono::seconds(2));
level++;
} else {
cout << "\nWrong answer! Try again.\n";
this_thread::sleep_for(chrono::seconds(2));
}
}
cout << "\n🎉 Congratulations! You completed all levels! 🎉\n";
return 0;
}