-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypingMaster.h
More file actions
143 lines (125 loc) · 4.01 KB
/
TypingMaster.h
File metadata and controls
143 lines (125 loc) · 4.01 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
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
133
134
135
136
137
138
139
140
141
// TypingMaster.h
#pragma once
#include <iostream>
#include <string>
#include <vector>
#include <chrono>
#include <iomanip>
#include <algorithm>
#include <random>
#include <fstream>
#include <unordered_map>
#include <thread>
class TypingMaster {
public:
// Construction
TypingMaster();
// Entry point for running the app
void run();
private:
struct LevelConfig {
int id;
std::string name;
std::string description;
std::vector<char> allowedKeys;
std::vector<std::string> templates;
int itemCount;
int timeLimitSeconds;
bool isSentenceLevel;
};
struct Stats {
int wordsAttempted = 0;
int wordsCorrect = 0;
int wordsWrong = 0;
int score = 0;
double accuracy = 0.0;
double totalTimeSeconds = 0.0;
};
struct UserProfile {
std::string username;
std::size_t passwordHash = 0; // dummy hash for demo purposes
int gamesPlayed = 0;
int totalWords = 0;
int totalCorrect = 0;
double totalTimeSeconds = 0.0;
int highScore = 0;
double bestAccuracy = 0.0;
double bestWpm = 0.0;
};
// Settings
bool caseSensitive;
bool colorsEnabled;
bool unicodeUI;
bool soundEnabled;
int currentLevelIndex;
std::vector<LevelConfig> levels;
Stats sessionStats; // aggregated over the session
// Auth/DB
std::string currentUser;
std::unordered_map<std::string, UserProfile> users;
std::string dbFilePath = "users.db";
// UI helpers
void clearScreen() const;
void drawBorder(int width) const;
void printCentered(const std::string& text, int width) const;
void printHeader(const std::string& title, const std::string& subtitle = "") const;
std::string progressBar(double ratio, int width = 32) const;
std::string colorGreen() const;
std::string colorRed() const;
std::string colorYellow() const;
std::string colorCyan() const;
std::string colorBlue() const;
std::string colorMagenta() const;
std::string colorReset() const;
std::string borderTopLeft() const;
std::string borderTopRight() const;
std::string borderBottomLeft() const;
std::string borderBottomRight() const;
std::string borderHorizontal() const;
std::string borderVertical() const;
std::string borderSeparatorLeft() const;
std::string borderSeparatorRight() const;
std::string emojiOr(const std::string& emoji, const std::string& ascii) const;
// Sound helpers
void playKeyClick(int count) const;
void playBackspaceClick(int count) const;
void playSuccessTone() const;
void playErrorTone() const;
// Screens
void showWelcome() const;
void showHowToPlay() const;
void showStatistics() const;
int showMainMenu();
int showLevelSelect();
void showUserProfile() const;
void startMultiplayer();
std::string selectExistingUser(const std::string& prompt, const std::string& exclude = "") const;
// Game flow
void initLevels();
void configureConsoleCapabilities();
void startGame();
void playLevel(int levelIndex);
void playLevelWithItems(int levelIndex, const std::vector<std::string>& items, Stats& outStats);
void printLevelIntro(const LevelConfig& level) const;
std::vector<std::string> generateLevelItems(int levelIndex, unsigned int seed) const;
// Utilities
static std::string trim(const std::string& s);
static std::string toLower(const std::string& s);
static bool equals(const std::string& a, const std::string& b, bool caseSensitive);
static void shuffleVector(std::vector<std::string>& v);
static bool timeExceeded(const std::chrono::steady_clock::time_point& start, int limitSeconds);
std::string performanceStars(double accuracy) const;
std::string encouragement(double accuracy) const;
static double computeWpm(int wordsAttempted, double timeSeconds);
std::string speedSuggestion(double wpm, double accuracy) const;
// Stats helpers
void resetSessionStats();
void accumulateSessionStats(const Stats& levelStats);
// Auth/DB helpers (dummy)
void loadDatabase();
void saveDatabase() const;
void loginOrRegister();
bool verifyPassword(const std::string& username, const std::string& password) const;
static std::size_t hashPassword(const std::string& password);
void updateUserWithLevelStats(const Stats& levelStats);
};