Hi guys, I am making a memory game for my school project and i just have a few things that i would like to add to it to make it better. In my game, i have a 5x5 grid that has letters hidden by $ underneath. So when the user inputs say Row4 Col 1 the Letter appears. The point is to get 2 pairs to match up. Now what i woudl like to do is make it so that when the number flips over, it is colored green. Its nothing major but just easier to see, because S and $ are quite similar and are hard to pick up if you are starting at a screen for 20 seconds $$$$$$$$$$$$$$$$$$$$$$$$S$$$.

Any ideas how i would do that? i have my code so i hope we can figure this out. Now there are a few errors but please ignore those. And the Ascii drawing is pretty bad so i will change it =p.

#include <iostream>   
#include <algorithm>            
#include <ctype.h>                
#include <time.h> 
#include <fstream>
#include <string>
#define _WIN32_WINNT 0x0500
#include <windows.h>
#pragma comment(lib,"winmm.lib")
using namespace std;

	



int Index1;
int Index2;
int Index3;
int Index4;
int Index5;
int Index6;
int row1;
int column1;
int row2;
int column2;


//The amount of money that acuts liek score.  
int Scr = 0;
int score = 500000;

void Score()
{   

	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
	cout << "MONEY! $ " << score <<" $ MONEY!"<< endl;
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);

}


//This is to read the score at the beginning of the game, wont work for some reason -______-
void ScoreG()

{
    string line;
  ifstream myfile ("score");

      cout << myfile << endl;
    
    myfile.close();
  

 

}

//These can be extended based on the board size and so on.
//These are what we are trying to guess, it could be numbers, letters or even symbols. 
char rand_1[16] = {'A','G','H','J','K','A','S','D','F','G','S','D','F','H','J','K'};

//I tried to resize the console window by changing its top size property but it didnt quite work
void Size()
{

 HWND console = GetConsoleWindow();
  RECT r;
  GetWindowRect(console, &r); //stores the console's current dimensions

  //MoveWindow(window_handle, x, y, width, height, redraw_window);
  MoveWindow(console, r.left, r.top, 700, 600, TRUE);
  for (int j = 0; j < 100; ++j)
    {
      for (int i = 0x41; i < 0x5B; ++i)
        cout << (char)i;
    }
  cout << endl;
  
  MoveWindow(console, r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE);


}


//displays a 5x5 board.
//as previously stated, number of pairs of letters need to be changed according to the size of the board
struct BoardData
{
	char ch[5][5];
};

//declares the functions here so that they can be used later on in the program
//things dont have to be declared before the function is called since function is declared before everything else. 
BoardData Brd_1[2];
void SPLASH();//welcome sreen and message box
void Input_1();//input for first choice
void Input_2();//gets input for second choice
void Output();//outputs to screen
void Score();//prints out the money
void Num1();//chk first set of numbers
void Num2();//chk 2nd set of numbers
void MATCHINGOFCARDS();//matches th cards
void EndGame();//ends the game
void Size();//checks the size 




//start up screen
void SPLASH()
{
	
	// Displays a GUI message box. 
	//int MessageBox(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType);
	//	char *msg;
	//	msg= "BOOT";

	//Lets you set caption for message box
	LPCTSTR Cap = L"Memmory Game";
	int mbox = MessageBox(NULL, 
		L"                                      Welcome to the Memmory Game!\n\n"
		L"There are a few simple rules that you have to learn to play this game\n "
		L"1) First enter the Row Number of the card that you wish to flip over .\n"
		L"2) Then enter the Coloumn number of the card that you wish flip over  .\n"
		L"3) Then enter the Row number of the second card that you wish flip over .\n"
		L"4) Then enter the Coloumn number of the second card that you wish flip over .\n\n\n"
		L"                                       Would you like to play HANGMAN? ",Cap, MB_YESNO );



	switch (mbox)
	{
	case IDYES:
		break;
	case IDNO:
		//GAMEA();
		exit(0);
		break;
	case IDCANCEL:
		exit(0);
		break;
	}
	ScoreG();


cout<<"                  ..######.....###.....######..##.....##"<<endl;
cout<<"                  .##....##...##.##...##....##.##.....##"<<endl;
cout<<"                  .##........##...##..##.......##.....##"<<endl;
cout<<"                  .##.......##.....##..######..#########"<<endl;
cout<<"                  .##.......#########.......##.##.....##"<<endl;
cout<<"                  .##....##.##.....##.##....##.##.....##"<<endl;
cout<<"                  ..######..##.....##..######..##.....##"<<endl;
cout<<"          .##.....##.########.##.....##..#######..########..##....##"<<endl;
cout<<"          .###...###.##.......###...###.##.....##.##.....##..##..##."<<endl;
cout<<"          .####.####.##.......####.####.##.....##.##.....##...####.."<<endl;
cout<<"          .##.###.##.######...##.###.##.##.....##.########.....##..."<<endl;
cout<<"          .##.....##.##.......##.....##.##.....##.##...##......##..."<<endl;
cout<<"          .##.....##.##.......##.....##.##.....##.##....##.....##..."<<endl;
cout<<"          .##.....##.########.##.....##..#######..##.....##....##..."<<endl;


system("pause");







SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
cout<<"   ____________________________        "<<endl;
cout<<"   |                           |       "<<endl;
cout<<"   |                           |       "<<endl;
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
cout<<"   |             ______________|____________   "<<endl; 
cout<<"   |            |                           |   "<<endl;
cout<<"   |            |                           |   "<<endl;
cout<<"   |            |                           |   "<<endl;
cout<<"   |            |                           |   "<<endl;

	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
cout<<"   |            |               ____________|________________  "<<endl;
cout<<"   |____________|              |                             | "<<endl;
cout<<"                |              |                             | "<<endl;  
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
cout<<"                |              |                             | "<<endl;
cout<<"                |              |             ###             | "<<endl;
cout<<"                |______________|            #   #            | "<<endl;
cout<<"                               |           #-----#           | "<<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
cout<<"                               |          #       #          | "<<endl;
cout<<"                               |         #         #         | "<<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 11);
cout<<"                               |                             | "<<endl;
cout<<"                               |_____________________________| "<<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);


system("pause");
system("cls");


}


void GRID()
{

	{
		//puts coloumns of 1-4, this may change based on difivulty selected.  You can add more numbers based on 
		// big your drid is
		cout << endl;
		cout << "     " << "1    2    3    4" <<endl;
		cout << endl;
		cout << endl;
		//this is to match the index with the board to see of the size is correct and output spacing
		for( Index2 = 1; Index2 < 5; Index2++)
		{
			for ( Index3 = 0; Index3 < 5; Index3++)
			{
				cout << Brd_1[0].ch[Index2][Index3] << "    ";
			}
			cout << endl;
			cout << endl;
			cout << endl;
		}
	}

}


//main part of the program
void main()
{
	srand((unsigned)time(0));
	SPLASH();
	// start playing the file continuosly and asynchronously
		PlaySound(L"bak.wav", 0, SND_FILENAME|SND_LOOP|SND_ASYNC);
		// Listen to it for 5 secs
		//Sleep(1000);
		// Stop playing
		//PlaySound(0,0,0);
	//generates the random letters on the board
	
	using std::random_shuffle;
	//member of std function, allows for shuffeling of numbers or letters from array
	random_shuffle(rand_1,rand_1+16);
	for( Index5 = 1; Index5 < 5; Index5++)
	{
		for ( Index6 = 1; Index6 < 5; Index6++)
		{
			do
			{
				//randomizes the letters in this bit of code, all while number of pairs are under 16
				Brd_1[1].ch[Index5][Index6]=*(rand_1+Scr);
				Scr++;
				break;
			}while(Scr < 16);
		}
	}
	Brd_1[0].ch[0][0] = ' ';
//manages size of rows and places out $$ signs
	for ( int row = 1; row < 5; row++)
	{
		Brd_1[0].ch[0][row] = 48 + row;
		Brd_1[0].ch[row][0] = 48 + row;
		for(int col = 1; col < 5; col++)
		{
			Brd_1[0].ch[row][col] = '$$';// these can be replaced with anything, &, *, ^, %, # and so on
		}
	}
	
	GRID();
	
	MATCHINGOFCARDS();
	
}



void Num1()//first number function
{

   
	Input_1();//Gets the first set of numbers from the user
	system("cls");
	Output();//out puts the updated board
	Score();//updates/manages score. you dont have to call this but its an uptodate score, otherwise the score
			//wont display while you are entering in letters and board is reset. 
	
	Num2();
}

void Num2()
{
	Input_2();
	system("cls");
	//error check: if a coordinate was already matched
	if(row1 == row2 && column1 == column2)
	{
		Brd_1[0].ch[row1][column1] = '$';
		Output();
		Score();
		//if same points are picked then an error will accour
		cout << "Error: Do not enter the co-ordinates of the same point." << endl;
		cout << endl;
		cout << endl;
		//system("cls");
		Output();
	     Num1();
		system("cls");
	}
}

//inputs the first point
void Input_1() 
{
	cout << endl;
	cout <<"Enter the coloumn Number and Row number of the card you wish to pick" << endl;
	
	cout << "Row: ";
	cin >> row1;
	cout << "Column: ";
	cin >> column1;

	//error check: if input is greater than what is on the board
	if(column1 > 4 || row1 > 4)
	{//if you enter number than the size of the board at 5x5, but in c++ its 0-4
		cout << " No Cards match your input! " << endl;
		cout << endl;
		Input_1();
	}
	cout << endl;
	cout << endl;

	//error check: if a coordinate was already matched
	if(Brd_1[0].ch[row1][column1] == ' ')//replace the matched space with a blank if its repicked
	{
		system("cls");
		Output();
		cout << "You have already guessed that spot, please pick a different one."<<endl;
		cout << endl;
		cout << endl;
		Input_1();
	}
	cout << endl;
	cout << endl;
	Brd_1[0].ch[row1][column1] = Brd_1[1].ch[row1][column1];
}


void Input_2()
{//get the second set of pairs from the user
	cout << endl;
	cout << "Enter the coloumn Number and Row number of the card you wish to pick" << endl;
	cout << "Row: ";
	cin >> row2;
	cout << "Column: ";
	cin >> column2;
	if(column2 > 4 || row2 > 4)
	{
		cout << " No Cards match your input! " << endl;
		Input_2();
	}
	cout << endl;
	cout << endl;
	if(Brd_1[0].ch[row2][column2] == ' ')
	{
		system("cls");
		Output();
		cout << "Error: The spot you chose was already matched.";
		cout << endl;
		cout << endl;
		Input_2();
	}
	cout << endl;
	cout << endl;
	Brd_1[0].ch[row2][column2]=Brd_1[1].ch[row2][column2];
}

//The game board is outputed to the scree, it is used many times. 
void Output()                                                   
{                                                                
	for( Index1 = 0; Index1 < 5; Index1++)
	{
		for(Index4 = 0; Index4 < 5; Index4++)
		{
		cout << Brd_1[0].ch[Index1][Index4] << "    ";
		}
		cout << endl << endl << endl;
	}
}

void MATCHINGOFCARDS()
{

	Score();
	Num1();
	Output();
	Score();


	//if the input matches the letters on the board, make a match 
	if(Brd_1[1].ch[row1][column1] == Brd_1[1].ch[row2][column2])
	{
		cout << "CHACHING YOU GOT IT CORRECT!!" << endl;
		cout<<"YOU WON $5000 CONGRATS! "<<endl;
		score = score + 5000;
		Brd_1[0].ch[row1][column1] = ' ';
		Brd_1[0].ch[row2][column2] = ' ';
		score = score + 10;
		// start playing the file continuosly and asynchronously
		PlaySound(L"Ding.wav", 0, SND_FILENAME|SND_LOOP|SND_ASYNC);
		// Listen to it for 5 secs
		Sleep(1000);
		// Stop playing
		PlaySound(0,0,0);


// start playing the file continuosly and asynchronously
		PlaySound(L"bak.wav", 0, SND_FILENAME|SND_LOOP|SND_ASYNC);
		// Listen to it for 5 secs
		//Sleep(1000);
		// Stop playing
		//PlaySound(0,0,0);
	//generates the random letters on the board

		
	}
	else
	{

		cout << "YOU CARDS DONT MATCH! ";
		score = score -10000;

	}
	if(Brd_1[1].ch[row1][column1] != Brd_1[1].ch[row2][column2])
	{
		Brd_1[0].ch[row1][column1] = '$','$';
		Brd_1[0].ch[row2][column2] = '$','$';
	}
	Sleep(1600);
	system("cls");
	Output();

	//check: if there are no * left
	for (Index2 = 1; Index2 < 2; Index2++)
	{
		for ( Index3 = 1; Index3 < 2; Index3++)
			//check is borrowed from the tic tac game where you would check each spot in the array, if 
			//all spots appear ' ' then the game is finished
		{
			if (Brd_1[0].ch[Index2][Index3] == ' ' && Brd_1[0].ch[Index2][Index3+1] == ' ' && Brd_1[0].ch[Index2][Index3+2] == ' ' && Brd_1[0].ch[Index2][Index3+3] == ' ' && Brd_1[0].ch[Index2+1][Index3] == ' ' && Brd_1[0].ch[Index2+1][Index3+1] == ' ' && Brd_1[0].ch[Index2+1][Index3+2] == ' ' && Brd_1[0].ch[Index2+1][Index3+3] == ' ' && Brd_1[0].ch[Index2+2][Index3] == ' ' && Brd_1[0].ch[Index2+2][Index3+1] == ' ' && Brd_1[0].ch[Index2+2][Index3+2] == ' ' && Brd_1[0].ch[Index2+2][Index3+3] == ' ' && Brd_1[0].ch[Index2+3][Index3] == ' ' && Brd_1[0].ch[Index2+3][Index3+1] == ' ' && Brd_1[0].ch[Index2+3][Index3+2] == ' ' && Brd_1[0].ch[Index2+3][Index3+3] == ' ')
			{
				system("cls");
				
	

			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
			cout<<"             #     # ####### #     #    #     # ### #     #    ### "<<endl;
			cout<<"              #   #  #     # #     #    #  #  #  #  ##    #    ### "<<endl;
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
			cout<<"               # #   #     # #     #    #  #  #  #  # #   #    ### "<<endl;
			cout<<"                #    #     # #     #    #  #  #  #  #  #  #     #  "<<endl;
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 6);
			cout<<"                #    #     # #     #    #  #  #  #  #   # #        "<<endl;
			cout<<"                #    #     # #     #    #  #  #  #  #    ##    ### "<<endl;
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
			cout<<"                #    #######  #####      ## ##  ### #     #    ### "<<endl;

//display the you win screen
// start playing the file continuosly and asynchronously
		PlaySound(L"chr.wav", 0, SND_FILENAME|SND_LOOP|SND_ASYNC);
		// Listen to it for 5 secs
		Sleep(3000);
		// Stop playing
		PlaySound(0,0,0);

            

//write the score to the score text file based on how much money you earned. 

          fstream file_op("score.txt",ios::out);

        file_op<<score;
        file_op.close();
        
 
				cout << "YOU FINISHED WITH THIS MUCH MONEY TO TAKE HOME!!!! " << score << "." << endl << endl;
//				ScoreP();

				system("pause");
				exit(1);
				
				
			}
		}
	}
	MATCHINGOFCARDS();
}

What you want to achieve will take a lot code than what you might
expect. I would recommend to use '*' as un-fliped mode so the
user wont get confused.

This article has been dead for over six months. Start a new discussion instead.