Jump to content

Check out my memory game - help needed

- - - - -

  • Please log in to reply
10 replies to this topic

#1
spkenn5

spkenn5

    Newbie

  • Members
  • Pip
  • 9 posts
First of all, I'm gonna write my algorithm..

store solution
prints out menu
gets selection
1 for game
2 for solution
3 to exit
if 1 then go to game
do{
prints board
gets row and column
store row and column
gets row2 and column2
store row2 and column2
}while(row,row2,column,column2 != 0, > 4);
prints board
if row=row2 and column = column2
prints board
match++
else
reset the value of row,row2,column,column2;

and somehow it validates twice.. after it matches then its somehow go to the next if.. and prints it did not match.

need help

here's my code

#include <stdio.h>

#include <string.h>

#include <conio.h>

#include <Windows.h>



void solBoard()

{

	

	char solution[5][5] = {{5,2,1,67},{3,6,4,65},{1,65,2,5},{6,4,67,3}};

			printf("---------\n");

			printf("|%c|%c|%c|%c|\n",solution[0][0],solution[0][1],solution[0][2],solution[0][3]);

			printf("---------\n");

			printf("|%c|%c|%c|%c|\n",solution[1][0],solution[1][1],solution[1][2],solution[1][3]);

			printf("---------\n");

			printf("|%c|%c|%c|%c|\n",solution[2][0],solution[2][1],solution[2][2],solution[2][3]);

			printf("---------\n");

			printf("|%c|%c|%c|%c|\n",solution[3][0],solution[3][1],solution[3][2],solution[3][3]);

			printf("---------\n");

}


void board()

{

		char question[5][5] = {{63,63,63,63},{63,63,63,63},{63,63,63,63},{63,63,63,63}};

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

		printf("---------\n");

}

void mainMenu()

{

	for(int i = 0; i < 25;  i++)

	{

		if(i == 0)

		{

			printf(" E. Card Matching Program");

		}else if(i == 21)

		{

			printf("Main Menu: \n");

			printf("1. Play Game\n");

			printf("2. Solution\n");

			printf("3. Exit\n");

			i = i + 4;

		}else

			printf("\n");

	}

}


void keyAnswer()

{

	char solution[5][5] = {{5,2,1,67},{3,6,4,65},{1,65,2,5},{6,4,67,3}};

	for(int i = 0; i < 25; i++)

	{

		if(i == 10)

		{

			printf("The solution is \n");

			solBoard();

		}else if(i == 13)

		{


			i = i + 9;

		}else

			printf("\n");

	}

}




int main()

{


	int select; 

	char solution[5][5] = {{5,2,1,67},{3,6,4,65},{1,65,2,5},{6,4,67,3}};

	char question[5][5] = {{63,63,63,63},{63,63,63,63},{63,63,63,63},{63,63,63,63}};


	do

	{

		system("cls");

		mainMenu();

		printf("%s","Please enter your selection[1..3]: ");

		scanf("%d", &select);

		fflush(stdin);


		if(select == 1)

		{

			int column = 0;

			int	row = 0;

			int match = 0;

			for(int i = 0; i < 25; i++)

			{

				//do

				//{

				if(i == 0)

					{

						system("cls");


						i = i + 9;

					}else if(i == 24)

					{

					int match = 0;

					int x = 0,y = 0;

					int x1 = 0,y1 =0;

					char solution[5][5] = {{5,2,1,67},{3,6,4,65},{1,65,2,5},{6,4,67,3}};

					char question[5][5] = {{63,63,63,63},{63,63,63,63},{63,63,63,63},{63,63,63,63}};

					char question2[5][5] = {{63,63,63,63},{63,63,63,63},{63,63,63,63},{63,63,63,63}};

					char solution2[5][5] = {{63,63,63,63},{63,63,63,63},{63,63,63,63},{63,63,63,63}};

		

						do

						{

						system("cls");

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

						printf("---------\n");

							

							//printf("%c",question[x][y]);

							do

							{

							printf("%s","Please input column[1..4][0 to exit]: ");

							scanf("%d", &x);

							fflush(stdin);


							printf("%s","Please input row[1..4][0 to exit]: ");

							scanf("%d", &y);

							fflush(stdin);

							question[x-1][y-1] = solution[x-1][y-1];

							solution2[x-1][y-1] = solution[x-1][y-1];

						

							system("cls");

							printf("---------\n");

							printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

							printf("---------\n");

							printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

							printf("---------\n");

							printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

							printf("---------\n");

							printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

							printf("---------\n");

							getchar();

							system("cls");



						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

						printf("---------\n");

						

							printf("%s","Please input column to match[1..4][0 to exit]: ");

							scanf("%d", &x1);

							fflush(stdin);


							printf("%s","Please input row to match[1..4][0 to exit]: ");

							scanf("%d", &y1);

							fflush(stdin);

							question2[x1-1][y1-1] = solution[x1-1][y1-1];

							question[x1-1][y1-1] = question2[x1-1][y1-1];

							printf("\n\n Pick # 1 = %c", solution2[x-1][y-1]);

							printf("\n\n Pick # 2 = %c", question[x1-1][y1-1]);



							}while(x > 4 || y > 4 || x1 > 4 || y1 > 4);


					if(question[x1-1][y1-1] == solution2[x-1][y-1])

					{

						printf("match!");

						match++;

						question[x-1][y-1] = '\0';

						question[x1-1][y1-1] = '\0';

						getchar();

						system("cls");


		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

		printf("---------\n");


						printf("new value qx-1 y-1 = %c\n",question[x-1][y-1]);

						printf("new value qx1-1 y1-1 = %c\n",question[x1-1][y1-1]);

						getchar();

					}

					


					else if(question[x1-1][y1-1] != solution[x-1][y-1])

						{

							printf("did not match!");

							getchar();

							

						system("cls");


		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

		printf("---------\n");


						printf("before value qx-1 y-1 = %c\n",question[x-1][y-1]);

						printf("before value qx1-1 y1-1 = %c\n",question[x1-1][y1-1]);

						question[x1-1][y1-1] = 63;

						question[x-1][y-1] = 63;

						printf("new value qx1-1 y1-1 = %c\n",question[x1-1][y1-1]);

						printf("new value qx-1 y-1 = %c\n",question[x-1][y-1]);

						getchar();

					}



							getchar();

							system("cls");

					}while(match < 8);

	



					

				

					

					

					}	else

							printf("\n");

				//}while(match < 8);

			}	

		

	

	

		

		

		

		

		}

		if(select == 2)

		{

			system("cls");

			keyAnswer();

			getchar();

		}

	}while(select != 3);

	


	//getchar();


}


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Why are you using "else if" instead of just "else"?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
First, I think you have a design flaw in your algorithm, I mean this part:
if row=row2 and column = column2
This will be true only when you pick up the same card (number) which I think is illegal move and also makes little sense (opening an already open card). You should check values in your array instead, something like this:
if array[row] == array[row2] and array[column] == array[column2]
Next, when you print board/solution, you declare a variable (2d array) inside a function but instead you should be passing it as an argument or making it global (which is not really a good idea though). You can take advantage and use function to display question array, instead of all that printf code.
A conclusion is where you got tired of thinking.
#define class struct    // All is public.

#4
spkenn5

spkenn5

    Newbie

  • Members
  • Pip
  • 9 posts
Thanks for the response guys, I made a little change and create a function for selection, things has been easier to see that way.

Can you guys test it out and find out what's missing?
#include <stdio.h>

#include <string.h>

#include <conio.h>

#include <Windows.h>


int x,y;

int x1,y1;


void loadingScr()

{

     printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

     printf("Loading...\n");

     for(int i = 0; i < 80;i++)

     {

             printf("%c",178);

             Sleep(120);

     }

     

}



void loadingScr2()

{

     printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

     printf("Loading");

     for(int j = 0; j < 7; j++)

     {

     for(int i = 0; i < 5;i++)

     {

             printf("%c",46);

             Sleep(120);

     }

     printf("       \r       ");

     }

}

int selection1(int column1,int row1)

{


        

            printf("%s","Please input column to match[1..4][0 to exit]: ");

			scanf("%d", &x1);

			fflush(stdin);


            printf("%s","Please input row to match[1..4][0 to exit]: ");

            scanf("%d", &y1);

			fflush(stdin);

 

        return x1;

        return y1;

}


int selection(int column,int row)

{


                printf("%s","Please input column[1..4][0 to exit]: ");

                scanf("%d", &x);

                fflush(stdin);

 

                printf("%s","Please input row[1..4][0 to exit]: ");

                scanf("%d", &y);

                fflush(stdin);


        return x;

        return y;

}


void solBoard()

{

	

	char solution[5][5] = {{5,2,1,67},{3,6,4,65},{1,65,2,5},{6,4,67,3}};

			printf("---------\n");

			printf("|%c|%c|%c|%c|\n",solution[0][0],solution[0][1],solution[0][2],solution[0][3]);

			printf("---------\n");

			printf("|%c|%c|%c|%c|\n",solution[1][0],solution[1][1],solution[1][2],solution[1][3]);

			printf("---------\n");

			printf("|%c|%c|%c|%c|\n",solution[2][0],solution[2][1],solution[2][2],solution[2][3]);

			printf("---------\n");

			printf("|%c|%c|%c|%c|\n",solution[3][0],solution[3][1],solution[3][2],solution[3][3]);

			printf("---------\n");

}


void board()

{

		char question[5][5] = {{63,63,63,63},{63,63,63,63},{63,63,63,63},{63,63,63,63}};

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

		printf("---------\n");

}

void mainMenu()

{

	for(int i = 0; i < 25;  i++)

	{

		if(i == 0)

		{

			printf(" E. Card Matching Program");

		}else if(i == 5)

        {

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t=My Cool Guide to Chain of Memories=\n");

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t====================================\n");                            

              i = i + 13;

        }

              else if(i == 21)

		{

			printf("Main Menu: \n");

			printf("1. Play Game\n");

			printf("2. Solution\n");

			printf("3. Exit\n");

			i = i + 4;

		}else

			printf("\n");

	}

}


void keyAnswer()

{

	char solution[5][5] = {{5,2,1,67},{3,6,4,65},{1,65,2,5},{6,4,67,3}};

	for(int i = 0; i < 25; i++)

	{

		if(i == 10)

		{

			printf("The solution is \n");

			solBoard();

		}else if(i == 13)

		{


			i = i + 9;

		}else

			printf("\n");

	}

}

int main()

{


	int select; 

	char solution[5][5] = {{5,2,1,67},{3,6,4,65},{1,65,2,5},{6,4,67,3}};

	char question[5][5] = {{63,63,63,63},{63,63,63,63},{63,63,63,63},{63,63,63,63}};


    loadingScr();


	do

	{

		system("cls");

		mainMenu();

		printf("%s","Please enter your selection[1..3]: ");

		scanf("%d", &select);

		fflush(stdin);


		if(select == 1)

		{

            loadingScr2();

  			int column = 0;

			int	row = 0;

			int match = 0;

			for(int i = 0; i < 25; i++)

			{

				if(i == 0)

					{

						system("cls");


						i = i + 9;

					}else if(i == 24)

					{

					int match = 0;


					char solution[5][5] = {{5,2,1,67},{3,6,4,65},{1,65,2,5},{6,4,67,3}};

					char question[5][5] = {{63,63,63,63},{63,63,63,63},{63,63,63,63},{63,63,63,63}};

					char question2[5][5] = {{63,63,63,63},{63,63,63,63},{63,63,63,63},{63,63,63,63}};

					char solution2[5][5] = {{63,63,63,63},{63,63,63,63},{63,63,63,63},{63,63,63,63}};

		

						do

						{

						system("cls");

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

						printf("---------\n");


							do

							{

                              do{

                            selection(x,y);

                            if(question[x-1][y-1] != '\0')

                            {}

                            else{

                            printf("The box already filled, please enter another box");

                            getchar();}

                            }while(question[x-1][y-1] == '\0');

                            if(x == 0 || y == 0){

                                 system("cls");

                                 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\tThank you for playing the game");

                                 printf("\n\t\t\t   Press enter to exit!");

                                 getchar();   

                                 return 0;

                                 }

                           	else if(question[x-1][y-1] != '\0' || question[x-1][y-1] != 63)     

							{

                                 question[x-1][y-1] = solution[x-1][y-1];

							     solution2[x-1][y-1] = solution[x-1][y-1];

                            }

                            

							system("cls");

							printf("---------\n");

							printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

							printf("---------\n");

							printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

							printf("---------\n");

							printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

							printf("---------\n");

							printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

							printf("---------\n");

							system("cls");



						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

						printf("---------\n");

					                                                                                          

                              do{

                            selection1(x1,y1);

                            if(question[x1-1][y1-1] != '\0')

                            {}

                            else{

                            printf("The box already filled, please enter another box");

                            getchar();}

                            }while(question[x1-1][y1-1] == '\0');                            if(x1 == 0 || y1 == 0){

                                 system("cls");

                                 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\tThank you for playing the game");

                                 printf("\n\t\t\t   Press enter to exit!");

                                 getchar();   

                                 return 0;

                                 }

                           	else if(question[x-1][y-1] != '\0')     

							{

                            	question2[x1-1][y1-1] = solution[x1-1][y1-1];

						     	question[x1-1][y1-1] = question2[x1-1][y1-1];

	                        }

                                                           

                        system("cls");

                        printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

						printf("---------\n");


							}while(x > 4 || y > 4 || x1 > 4 || y1 > 4);



					if(question[x1-1][y1-1] == solution2[x-1][y-1])

					{

						printf("match!");

						match++;

						question[x-1][y-1] = '\0';

						question[x1-1][y1-1] = '\0';

						system("cls");


		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

		printf("---------\n");


					}

					else if(question[x1-1][y1-1] != solution[x-1][y-1])

						{

							printf("did not match!");

							getchar();

							

						system("cls");


		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

		printf("---------\n");	

						question[x1-1][y1-1] = 63;

						question[x-1][y-1] = 63;

					}

							system("cls");

					}while(match < 8);					

					}	else

							printf("\n");

			}	

		

	}

		if(select == 2)

		{

			system("cls");

			keyAnswer();

			getchar();

		}

	}while(select != 3);

	

}



#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
You have a block of printf's that seems to show up all over the place. It interrupts the flow of your code. I'd use a printboard() type function for that.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#6
spkenn5

spkenn5

    Newbie

  • Members
  • Pip
  • 9 posts
I tried, but whenever i call out the board() function, it resets the value of the array to the default which is a '?' not the updated ones.. i wonder how do u call a function and keeps the array updated

#7
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
int selection(int column,int row)
{


                printf("%s","Please input column[1..4][0 to exit]: ");
                scanf("%d", &x);
                fflush(stdin);
 
                printf("%s","Please input row[1..4][0 to exit]: ");
                scanf("%d", &y);
                fflush(stdin);


        return x;
        return y;
}

Sadly, this is how it works. I'm talking about 2 return statements. When a function hits a return keyword, it returns value and ends. So when you return x, the control goes back to main function. In some other languages you could write this:
return x, y;
Not in C/C++ though. Best solution for this are pointers. When you pass a pointer to the variable, the reference (address) gets passed instead of a copy (value).
void function(int* pointer) {
    scanf("%d", pointer);  // note the lack of & operator
}

int main() {
    int number = 0;
    
    function(&number);  // passing the address ( & operator ), not the value

    printf("number = %d\n", number);
}
Lastly, in your menu function, why are you using for loop at all?
A conclusion is where you got tired of thinking.
#define class struct    // All is public.

#8
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US

Quote

        return x;

        return y;

Why not use something like this?:
int main (){ 

  int x; 

  int y; 

  myFunction (..., &x, &y); 

  ... 

} 

void myFunction (..., int * pX, int * pY){ 

  ... 

  *pX= x; 

  *pY= y; 

} 


#9
spkenn5

spkenn5

    Newbie

  • Members
  • Pip
  • 9 posts
DONE!!!

THANKS GUYS!!!

#include <stdio.h>

#include <string.h>

#include <conio.h>

#include <Windows.h>


int x,y;

int x1,y1;


void loadingScr()

{

     printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

     printf("Loading...\n");

     for(int i = 0; i < 80;i++)

     {

             printf("%c",178);

             Sleep(120);

     }

     

}



void loadingScr2()

{

     printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

     printf("Loading");

     for(int j = 0; j < 7; j++)

     {

     for(int i = 0; i < 5;i++)

     {

             printf("%c",46);

             Sleep(120);


     }            

      for(int j = 0; j < 5; j++)

             {

                     printf(" \b\b");

             }

     

     }

}

int selection1(int column1,int row1)

{


        

            printf("%s","Please input column to match[1..4][0 to exit]: ");

			scanf("%d", &x1);

			fflush(stdin);


            printf("%s","Please input row to match[1..4][0 to exit]: ");

            scanf("%d", &y1);

			fflush(stdin);

 

        return x1;

        return y1;

}


int selection(int column,int row)

{


                printf("%s","Please input column[1..4][0 to exit]: ");

                scanf("%d", &x);

                fflush(stdin);

 

                printf("%s","Please input row[1..4][0 to exit]: ");

                scanf("%d", &y);

                fflush(stdin);


        return x;

        return y;

}


void solBoard()

{

	

	char solution[5][5] = {{5,2,1,67},{3,6,4,65},{1,65,2,5},{6,4,67,3}};

			printf("---------\n");

			printf("|%c|%c|%c|%c|\n",solution[0][0],solution[0][1],solution[0][2],solution[0][3]);

			printf("---------\n");

			printf("|%c|%c|%c|%c|\n",solution[1][0],solution[1][1],solution[1][2],solution[1][3]);

			printf("---------\n");

			printf("|%c|%c|%c|%c|\n",solution[2][0],solution[2][1],solution[2][2],solution[2][3]);

			printf("---------\n");

			printf("|%c|%c|%c|%c|\n",solution[3][0],solution[3][1],solution[3][2],solution[3][3]);

			printf("---------\n");

}


void board()

{

		char question[5][5] = {{63,63,63,63},{63,63,63,63},{63,63,63,63},{63,63,63,63}};

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

		printf("---------\n");

}

void mainMenu()

{

	for(int i = 0; i < 25;  i++)

	{

		if(i == 0)

		{

			printf(" E. Card Matching Program");

		}else if(i == 5)

        {

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t=My Cool Guide to Chain of Memories=\n");

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t====================================\n");

              printf("\t====================================\n");                            

              i = i + 13;

        }

              else if(i == 21)

		{

			printf("Main Menu: \n");

			printf("1. Play Game\n");

			printf("2. Solution\n");

			printf("3. Exit\n");

			i = i + 4;

		}else

			printf("\n");

	}

}


void keyAnswer()

{

	char solution[5][5] = {{5,2,1,67},{3,6,4,65},{1,65,2,5},{6,4,67,3}};

	for(int i = 0; i < 25; i++)

	{

		if(i == 10)

		{

			printf("The solution is \n");

			solBoard();

		}else if(i == 13)

		{


			i = i + 9;

		}else

			printf("\n");

	}

}

int main()

{


	int select; 

	char solution[5][5] = {{5,2,1,67},{3,6,4,65},{1,65,2,5},{6,4,67,3}};

	char question[5][5] = {{63,63,63,63},{63,63,63,63},{63,63,63,63},{63,63,63,63}};


    loadingScr();


	do

	{

		system("cls");

		mainMenu();

		printf("%s","Please enter your selection[1..3]: ");

		scanf("%d", &select);

		fflush(stdin);


		if(select == 1)

		{

            loadingScr2();

  			int column = 0;

			int	row = 0;

			int match = 0;

			for(int i = 0; i < 25; i++)

			{

				if(i == 0)

					{

						system("cls");


						i = i + 9;

					}else if(i == 24)

					{

					int match = 0;


					char solution[5][5] = {{5,2,1,67},{3,6,4,65},{1,65,2,5},{6,4,67,3}};

					char question[5][5] = {{63,63,63,63},{63,63,63,63},{63,63,63,63},{63,63,63,63}};

					char question2[5][5] = {{63,63,63,63},{63,63,63,63},{63,63,63,63},{63,63,63,63}};

					char solution2[5][5] = {{63,63,63,63},{63,63,63,63},{63,63,63,63},{63,63,63,63}};

		

						do

						{

						system("cls");

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

						printf("---------\n");


							do

							{

                              do{

                            selection(x,y);

                            if(question[x-1][y-1] != '\0')

                            {}

                            else{

                            printf("The box already filled, please enter another box");

                            getchar();}

                            }while(question[x-1][y-1] == '\0');

                            if(x == 0 || y == 0){

                                 system("cls");

                                 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\tThank you for playing the game");

                                 printf("\n\t\t\t   Press enter to exit!");

                                 getchar();   

                                 return 0;

                                 }

                           	else if(question[x-1][y-1] != '\0' || question[x-1][y-1] != 63)     

							{

                                 question[x-1][y-1] = solution[x-1][y-1];

							     solution2[x-1][y-1] = solution[x-1][y-1];

                            }

                            

							system("cls");

							printf("---------\n");

							printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

							printf("---------\n");

							printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

							printf("---------\n");

							printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

							printf("---------\n");

							printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

							printf("---------\n");

							system("cls");



						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

						printf("---------\n");

					                                                                                          

                              do{

                            selection1(x1,y1);

                            if(question[x1-1][y1-1] != '\0')

                            {}

                            else{

                            printf("The box already filled, please enter another box");

                            getchar();}

                            }while(question[x1-1][y1-1] == '\0');                            if(x1 == 0 || y1 == 0){

                                 system("cls");

                                 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\tThank you for playing the game");

                                 printf("\n\t\t\t   Press enter to exit!");

                                 getchar();   

                                 return 0;

                                 }

                           	else if(question[x-1][y-1] != '\0')     

							{

                            	question2[x1-1][y1-1] = solution[x1-1][y1-1];

						     	question[x1-1][y1-1] = question2[x1-1][y1-1];

	                        }

                                                           

                        system("cls");

                        printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

						printf("---------\n");

						printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

						printf("---------\n");


							}while(x > 4 || y > 4 || x1 > 4 || y1 > 4);



					if(question[x1-1][y1-1] == solution2[x-1][y-1])

					{

						printf("match!");

						match++;

						question[x-1][y-1] = '\0';

						question[x1-1][y1-1] = '\0';

						system("cls");


		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

		printf("---------\n");


					}

					else if(question[x1-1][y1-1] != solution[x-1][y-1])

						{

							printf("did not match!");

							getchar();

							

						system("cls");


		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[0][0],question[0][1],question[0][2],question[0][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[1][0],question[1][1],question[1][2],question[1][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[2][0],question[2][1],question[2][2],question[2][3]);

		printf("---------\n");

		printf("|%c|%c|%c|%c|\n",question[3][0],question[3][1],question[3][2],question[3][3]);

		printf("---------\n");	

						question[x1-1][y1-1] = 63;

						question[x-1][y-1] = 63;

					}

							system("cls");

					}while(match < 8);					

					}	else

							printf("\n");

			}	

		

	}

		if(select == 2)

		{

			system("cls");

			keyAnswer();

			getchar();

		}

	}while(select != 3);

	

}



#10
alex1

alex1

    Learning Programmer

  • Members
  • PipPipPip
  • 93 posts
Nice game,sorry for bumping the thread,but why when I imput 2,2 and after that when I input again 2,2 the icon in the 2,2 is dissapearing...Isn't it supposed to stay there until I find the another icon? :)

I just wrote it,since it may be a bug.

#11
spkenn5

spkenn5

    Newbie

  • Members
  • Pip
  • 9 posts
Ahh you're right!! X_X I need to fix the validation, we're not supposed to input 2,2, twice.. haha let me fix ;)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users