TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
A simple Memory Game with 3 different sizes and multiple letters. More...
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <random>
#include <vector>
#include <unistd.h>
Go to the source code of this file.
Namespaces | |
namespace | games |
(Mini)game implementations. | |
namespace | games::memory_game |
Functions for the Memory Game implementation. | |
Functions | |
template<typename T > | |
constexpr T | SLEEP (T seconds) |
for sleep() | |
template<typename T > | |
bool | games::memory_game::is_number (const T &input) |
Utility function to verify if the given input is a number or not. This is very useful to prevent the program being stuck in a loop. | |
template<typename T > | |
void | games::memory_game::init (std::vector< T > *table) |
Initializes the table with the letters. | |
template<typename T > | |
void | games::memory_game::print_table (const std::vector< T > &table) |
Utility function to print the table. | |
template<typename T > | |
void | games::memory_game::reset_data (const std::vector< T > &table, int *answer, int *old_answer, int *memory_count) |
Utility function that resets the data if the user enters an invalid value. | |
template<typename T > | |
void | games::memory_game::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. | |
template<typename T > | |
bool | games::memory_game::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. | |
template<typename T > | |
void | games::memory_game::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. | |
int | main () |
Main function. | |
A simple Memory Game with 3 different sizes and multiple letters.
The game consists on finding the pair of all the given letters depending on the table size. Once all of the instances are all found, the game will end and will ask you if you'd like to play again or not.
It provides 3 different sizes available that the user can choose (4x2, 5x2, 7x2). 7x2 being the biggest table size and hardest mode. The bigger the size, the more letters are available.
Definition in file memory_game.cpp.
int main | ( | void | ) |
Main function.
< Size of the table.
< Selection of the size (4x2, 5x2, 7x2).
< The answer (number index) that the user chose.
< Previous answer (number index).
< Counter to check if the user has already answered two values.
< Whether the user has answered 1 value or not (previous answered values do not count).
Definition at line 360 of file memory_game.cpp.
|
constexpr |
for sleep()
for std::shuffle() for std::srand() for std::time() for IO operations for std::mt19937 for std::vector
Definition at line 36 of file memory_game.cpp.