-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
198 lines (192 loc) · 8.43 KB
/
main.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include "./include/global.hh"
#include "./include/participant.hh"
#include "./include/sentence.hh"
int main()
{
while (1)
{
color;
clr_here;
printMainHeader();
cout << "\n\n W E L C O M E T O T Y P I T ! \n\n\n\n\n";
pause_here;
clr_here;
printMainHeader();
cout << "Choose an option:\n";
cout << "\n[1]: Play"
"\n[2]: Add a sentence"
"\n[3]: Exit"
"\n\n";
int choice = 0;
cin >> choice;
getchar();
while (choice < 1 || choice > 3)
cout << "Enter a valid choice (1|2|3)!\n", cin >> choice, getchar();
if (choice == 1)
{
clr_here;
printMainHeader();
int numberOfParticipants = 0;
cout << "Enter total number of participants:\n";
while (numberOfParticipants <= 0)
{
cin >> numberOfParticipants;
getchar();
if (numberOfParticipants <= 0)
cout << "Was that supposed to make any kind of sense?!\nAdd some sense and enter again!\n";
}
clr_here;
printMainHeader();
vector<participant> participants;
for (int i = 0; i < numberOfParticipants; i++)
{
participant temp(i + 1);
participants.push_back(temp);
}
clr_here;
////////////////////////////////////////////////////////////////////////////////////////////////////////////
printMainHeader();
int difficulty = 0;
while (difficulty < 1 || difficulty > 3)
{
cout << "Enter the difficulty level (1-Easy || 2-Medium || 3-Hard):\n";
cin >> difficulty;
getchar();
if (difficulty < 1 || difficulty > 3)
{
cout << "Invalid difficulty level!\n";
}
}
clr_here;
////////////////////////////////////////////////////////////////////////////////////////////////////////////
printMainHeader();
int rounds = 0;
cout << "Enter the number of rounds you want to play:\n";
cin >> rounds;
getchar();
clr_here;
////////////////////////////////////////////////////////////////////////////////////////////////////////////
printMainHeader();
cout << "\nRead the instructions below carefully.\n\n\n";
cout << ">>INSTRUCTIONS:" << endl;
cout << "1)At the start of each round a sentence (difficulty level: ";
switch (difficulty)
{
case 1:
cout << "easy";
break;
case 2:
cout << "medium";
break;
case 3:
cout << "hard";
break;
default:
break;
}
cout << ") will be shown on your screen." << endl;
cout << "2)Participants take turns one by one. First one to go is ";
participants[0].printName();
cout << ". The order remains same for every round." << endl;
//cout << "3)Each participant has to type 'READY' (case-sensitive and without the inverted commas) and press the 'ENTER' key to start his timer." << endl;
cout << "3)Each participant (on their turn) can see the sentence they have to type before their timer has started and once done, they can press any key to start typing and the timer starts automatically.\n";
cout << "4)After that, once finished, press 'ENTER' key to end the timer and hence the turn." << endl;
cout << /* and once done, type 'NEXT' & press the 'ENTER' key to continue...*/ "\nNOTE: Screen will be cleared with the next keypress." << endl;
string temp;
// do
// {
// cin >> temp;
// getchar();
// } while (temp != "NEXT" && temp != "next");
pause_here;
clr_here;
printMainHeader();
cout << "\nRead the scoring & ranking rules carefully.\n\n\n";
cout << ">>SCORING & RANKING:" << endl;
cout << "1)Score of a participant is equal to: A/B (i.e. A divided by B) " << endl;
cout << "where: A = number of characters in their correct place in the participant's input sentence and if that number's less than 50% of total number of characters in the given sentence then it gets reduced to zero and hence the net score." << endl;
cout << "& B = time taken by the participant to type in seconds." << endl;
cout << "2)Ofcourse, the participant with higher score gets better rank." << endl;
cout << "3)But in case of a tie, tie breakers used are (in order):" << endl;
cout << "(i) Average Accuracy" << endl;
cout << "(ii) Average Speed" << endl;
cout << "(iii)Maximum Score" << endl;
cout << "(iv) If the tie's still not broken, 4th criteria is your luck!" << endl;
cout << "\n";
cout << /* and once done, type 'START' & press the 'ENTER' key to continue...\n*/ "\nNOTE: Screen will be cleared with the next keypress.\n";
// do
// {
// cin >> temp;
// getchar();
// } while (temp != "START" && temp != "start");
pause_here;
////////////////////////////////////////////////////////////////////////////////////////////////////////////
for (int i = 0; i < rounds; i++)
{
sentence givenSentence(difficulty);
string sen1 = givenSentence.getSentence();
for (int j = 0; j < numberOfParticipants; j++)
{
temp = "";
clr_here;
printMainHeader();
printRoundHeader(i + 1);
participants[j].printName();
cout << "'s turn\n\n";
cout << "Given Sentence: \n\n";
cout << sen1 << "\n\n";
string sen2 = "";
pause_here;
// cout << "Type 'READY' and press the 'ENTER' key to start the timer.\n";
// while (sen2 != "READY")
// getline(cin >> ws, sen2);
clr_here;
printMainHeader();
printRoundHeader(i + 1);
cout << sen1 << "\n\n";
clock_t timer = clock();
getline(cin >> ws, sen2);
double timeTaken = (((double)clock()) - timer) / ((double)CLOCKS_PER_SEC);
int score = 0;
for (int k = 0; k < min(sen1.size(), sen2.size()); k++)
{
if (sen1[k] == sen2[k])
score++;
}
clr_here;
printMainHeader();
printRoundHeader(i + 1);
participants[j].printName();
cout << " took " << timeTaken << " seconds to type with an accuracy of " << ((double)(score * 100) / sen1.size()) << "%.\n";
if (score < floor((double)sen1.size() / 2))
score = 0;
cout << "You scored " << ((double)score / timeTaken) << " in this round!\n\n";
participants[j].addScore(((double)score / timeTaken));
cout << "\nYour total score till now is: ";
participants[j].printTotalScore();
cout << "\n\n\n";
// cout << "\n\n\nType 'CONTINUE' and press the 'ENTER' key to continue...\n";
// while (temp != "CONTINUE" && temp != "continue")
// getline(cin >> ws, temp);
pause_here;
}
showLeaderboard(participants, numberOfParticipants);
}
}
else if (choice == 2)
{
clr_here;
printMainHeader();
sentence s(1);
s.addSentence();
}
else
{
clr_here;
printMainHeader();
cout << "Exiting typit...\nHope to see you back soon!\n";
return 0;
}
}
return 0;
}