Function to assign the results to the table.
Also checkes if the user has answered all the values already, as well as verify if the user made a match or not.
291 {
292
293
294
295 for (int i = 0; i < (*table).size() + 1; i++) {
296 if (i == (*answer)) {
297 if (
match((*table), table_empty, (*answer), first_time, old_answer,
298 memory_count) == true) {
299 (*table_empty)[i - 1] = (*table)[i - 1];
300 (*first_time) = true;
301 }
302 }
303 }
304
305 if ((*memory_count) == 1) {
306 (*first_time) = false;
307 (*memory_count) = 0;
308 }
309
310 char try_again = 'n';
311
312
313
314 for (int i = 0; i < (*table).size() + 1; i++) {
315 if ((*table_empty)[i] == 0) {
316 break;
317 } else if (i == (*table).size() - 1) {
319
320 std::cout <<
"\n\nYou won. Congratulations! Do you want to play "
321 "again? (y/n)\n";
323 << "Size " << (*table).size()
324 << " will be used. This can be changed by re-running the game.";
326 if (try_again == 'y') {
327
328
329 for (int i = 0; i < (*table_empty).size(); i++) {
330 (*table_empty)[i] = 0;
331 }
332
334 } else if (try_again == 'n') {
335 std::cout <<
"\nThanks for playing the game!\n";
337
339 } else {
340 std::cout <<
"\nInvalid input (exitting...).\n";
342
344 }
345 }
346 }
347
348
349 ask_data((*table_empty), answer, old_answer, memory_count);
350 assign_results(table_empty, table, answer, first_time, old_answer,
351 memory_count);
352}
constexpr T SLEEP(T seconds)
for sleep()
Definition memory_game.cpp:36
bool match(const std::vector< T > &table, std::vector< T > *table_empty, const int &answer, bool *first_time, int *old_answer, int *memory_count)
Checks if the two values given by the user match.
Definition memory_game.cpp:235
void assign_results(std::vector< T > *table_empty, std::vector< T > *table, int *answer, bool *first_time, int *old_answer, int *memory_count)
Function to assign the results to the table.
Definition memory_game.cpp:289
void ask_data(const std::vector< T > &table, int *answer, int *old_answer, int *memory_count)
Function that asks the user for their input in the table they previously chose.
Definition memory_game.cpp:161
void init(std::vector< T > *table)
Initializes the table with the letters.
Definition memory_game.cpp:80