Memory game with c++ console applicaton

Reply

Join Date: Jan 2006
Posts: 8
Reputation: gladiator1919 is an unknown quantity at this point 
Solved Threads: 0
gladiator1919 gladiator1919 is offline Offline
Newbie Poster

Memory game with c++ console applicaton

 
0
  #1
May 16th, 2006
HI members;
This is a memory game with c++ concole application.
This is the code:


  1. #include<iostream.h> //MEMORY GAME.
  2. #include <algorithm> //DESIGNED BY GLADIATOR1919.
  3. #include<ctype.h> //GLADIATOR1919@GMAIL.COM.
  4. #include<time.h> //ALL RIGHTS RESERVED.
  5. #include<windows.h>
  6. int e,i,j,q,m,n,x=0,row_1,column_1,row_2,column_2,score=0;
  7. char rand_1[16]={'a','g','h','j','k','a','s','d','f','g','s','d','f','h','j','k'};
  8. struct mem_char
  9. {
  10. char ch[5][5];
  11. };
  12. char re_play;
  13. mem_char char_1[2];
  14. void end_game();
  15. void input_first_point();
  16. void input_second_point();
  17. void delay(long seconds) ;
  18. void gotoxy(int x, int y);
  19. void score_1();
  20. void new_line(int y);
  21. void output_1();
  22. void num_1();
  23. void num_2();
  24. void main_1();
  25. void intro();
  26. void slide_horz_right( int x ,int y , char ch[]);
  27. void sleep(unsigned int mseconds);
  28. /***********************************************************************************************/
  29. void main()
  30. {
  31. srand((unsigned)time(0));
  32. using std::random_shuffle;
  33. random_shuffle(rand_1,rand_1+16);
  34. for( m=1 ; m<5 ; m++)
  35. {
  36. for ( n=1 ; n<5 ; n++)
  37. {
  38. do
  39. {
  40. char_1[1].ch[m][n]=*(rand_1+x);
  41. x++;
  42. break;
  43. }while(x<16);
  44. }
  45. }
  46. char_1[0].ch[0][0]=' ';
  47. for ( int u=1 ; u<5 ; u++)
  48. {
  49. char_1[0].ch[0][u]=48+u;
  50. char_1[0].ch[u][0]=48+u;
  51. for(int y=1 ; y<5 ; y++)
  52. {
  53. char_1[0].ch[u][y]='*';
  54. }
  55. }
  56. intro();
  57. delay(700);
  58. {
  59. cout<<" \t"<<" 1 2 3 4"<<endl<<endl<<endl;
  60. for( i=1 ; i<5 ; i++)
  61. {
  62. cout<<" \t\t\t";
  63. for ( j=0 ; j<5 ; j++)
  64. {
  65. cout<<char_1[0].ch[i][j]<<" ";
  66. }
  67. cout<<endl<<endl<<endl;
  68. }
  69. }
  70. new_line(3);
  71. main_1();
  72. new_line(4);
  73. }
  74. /***********************************************************************************************/
  75. void num_1()
  76. {
  77. input_first_point();
  78. system("cls");
  79. output_1();
  80. score_1();
  81. new_line(1);
  82. num_2();
  83. }
  84. /***********************************************************************************************/
  85. void num_2()
  86. {
  87. input_second_point();
  88. system("cls");
  89. if(row_1==row_2&&column_1==column_2)
  90. {
  91. char_1[0].ch[row_1][column_1]='*';
  92. output_1();
  93. score_1();
  94. new_line(3);
  95. cout<<"Error\n\n#Don't Enter the co-ordinates of the same point\n\nYour score will be decreased by 5"<<endl<<endl<<endl;
  96. delay(3000);
  97. system("cls");
  98. output_1();
  99. score_1();
  100. new_line(3);
  101. num_1();
  102. system("cls");
  103. score-=5;
  104. }
  105. }
  106. /***********************************************************************************************/
  107. void input_first_point() //to input the first point
  108. {
  109. cout<<"# Enter the Co-ordinates of the selected point to show \n";
  110. cout<<"#Row ";
  111. cin>>row_1;
  112. cout<<"#Column ";
  113. cin>>column_1;
  114. if(column_1>4||row_1>4)
  115. {
  116. cout<<"\nThere's no point here with this co-ordinates\n\nEnter the co-ordinates between 1 and 4\n\n";
  117. input_first_point();
  118. }
  119. cout<<endl<<endl;
  120. if(char_1[0].ch[row_1][column_1]==' ')
  121. {
  122. system("cls");
  123. output_1();
  124. cout<<"Error\n\nThis point have been hidden by you\n\n";
  125. input_first_point();
  126. }
  127. cout<<endl<<endl;
  128. char_1[0].ch[row_1][column_1]=char_1[1].ch[row_1][column_1];
  129. }
  130. /***********************************************************************************************/
  131. void input_second_point() //to input the second point
  132. {
  133. new_line(2);
  134. cout<<"# Enter the Co-ordinates of the second selected point to show \n\n";
  135. cout<<"#Row ";
  136. cin>>row_2;
  137. cout<<"#Column ";
  138. cin>>column_2;
  139. if(column_2>4||row_2>4)
  140. {
  141. cout<<"\nThere's no point here with this co-ordinates\n\nEnter the co-ordinates between 1 and 4\n\n";
  142. input_second_point();
  143. }
  144. cout<<endl<<endl;
  145. if(char_1[0].ch[row_2][column_2]==' ')
  146. {
  147. system("cls");
  148. output_1();
  149. cout<<"Error\n\nThis point have been hidden by you\n\n";
  150. input_second_point();
  151. }
  152. cout<<endl<<endl;
  153. char_1[0].ch[row_2][column_2]=char_1[1].ch[row_2][column_2];
  154. }
  155. /***********************************************************************************************/
  156. void output_1() //To display the main screen of
  157. { //the game
  158. for( e=0 ; e<5 ; e++)
  159. {
  160. cout<<" \t\t\t";
  161. for(q=0 ; q<5 ; q++)
  162. {
  163. cout<<char_1[0].ch[e][q]<<" ";
  164. }
  165. cout<<endl<<endl<<endl;
  166. }
  167. }
  168. /***********************************************************************************************/
  169. void main_1()
  170. {
  171. score_1();
  172. gotoxy(1,20);
  173. num_1();
  174. output_1();
  175. score_1();
  176. if(char_1[1].ch[row_1][column_1]==char_1[1].ch[row_2][column_2])
  177. {
  178. gotoxy(1,20);
  179. cout<<"Good Man"<<endl;
  180. char_1[0].ch[row_1][column_1]=' ';
  181. char_1[0].ch[row_2][column_2]=' ';
  182. score+=10;
  183. }
  184. else
  185. {
  186. gotoxy(1,20);
  187. cout<<"Try Again";
  188. new_line(5);
  189. score-=4;
  190. }
  191. if(char_1[1].ch[row_1][column_1]!=char_1[1].ch[row_2][column_2])
  192. {
  193. char_1[0].ch[row_1][column_1]='*','*';
  194. char_1[0].ch[row_2][column_2]='*','*';
  195. }
  196. sleep(1600);
  197. system("cls");
  198. output_1();
  199. score_1();
  200. for (i=1 ; i<2 ; i++)
  201. {
  202. for ( j=1 ; j<2 ; j++)
  203. {
  204. if (char_1[0].ch[i][j]==' '&&char_1[0].ch[i][j+1]==' '&&char_1[0].ch[i][j+2]==' '&&char_1[0].ch[i][j+3]==' '&&char_1[0].ch[i+1][j]==' '&&char_1[0].ch[i+1][j+1]==' '&&char_1[0].ch[i+1][j+2]==' '&&char_1[0].ch[i+1][j+3]==' '&&char_1[0].ch[i+2][j]==' '&&char_1[0].ch[i+2][j+1]==' '&&char_1[0].ch[i+2][j+2]==' '&&char_1[0].ch[i+2][j+3]==' '&&char_1[0].ch[i+3][j]==' '&&char_1[0].ch[i+3][j+1]==' '&&char_1[0].ch[i+3][j+2]==' '&&char_1[0].ch[i+3][j+3]==' ')
  205. {
  206. cout<<"\n\nYou have finished with score "<<score<<endl<<endl;
  207. cout<<"Do you want to play again?(y/n)";
  208. cin>>re_play;
  209. re_play=tolower(re_play);
  210. while(isdigit(re_play))
  211. {
  212. cout<<"Please enter a character";
  213. cin>>re_play;
  214. }
  215. if (re_play=='y')
  216. {
  217. score=0;
  218. x=0;
  219. system("cls");
  220. main();
  221. }
  222. if (re_play=='n')
  223. {
  224. cout<<"Thank you for playing memory";
  225. exit(0);
  226. }
  227. else
  228. {
  229. exit(0);
  230. }
  231. }
  232. }
  233. }
  234. main_1();
  235. }
  236. /***********************************************************************************************/
  237. void new_line(int y) //Make a number of new lines
  238. {
  239. for (e=0 ; e<y ; e++)
  240. cout<<endl;
  241. }
  242. /***********************************************************************************************/
  243. void delay(long seconds) //This function is to make a
  244. { //delay on the screen
  245. clock_t time1 = clock(); // use clock time
  246. clock_t time2 = time1 + seconds;
  247. while(time1 < time2)
  248. time1 = clock();
  249. return;
  250. }
  251. /***********************************************************************************************/
  252. void score_1(){ //This function is to move the
  253. gotoxy(64,17); //cursor to a specified place
  254. cout<<"Score = "<<score<<endl; //and write the score
  255. }
  256. /***********************************************************************************************/
  257. void sleep(unsigned int mseconds) //This function is to make a
  258. { //delay on the screen
  259. clock_t goal = mseconds + clock();
  260. while (goal > clock());
  261. }
  262. /***********************************************************************************************/
  263. void gotoxy(int x, int y)
  264. {
  265. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); //This function is to set
  266. COORD point; //the cursor to a specified
  267. point.X = x-1; //place on the screen
  268. point.Y = y-1;
  269. SetConsoleCursorPosition(hConsole, point);
  270. }
  271. /***********************************************************************************************/
  272. void intro()
  273. {
  274. system("cls");
  275. slide_horz_right(40,25,"Sayed");
  276. slide_horz_right(32,25,"Mohamed");
  277. slide_horz_right(28,25,"Eng");
  278. slide_horz_right(25,25,"By");
  279. slide_horz_right(16,25,"Designed");
  280. delay(500);
  281. system("cls");
  282. }
  283. /***********************************************************************************************/
  284. void slide_horz_right( int x ,int y , char ch[]) //This function is to move text
  285. { //on the screen
  286. for ( int i=1 ; i<x ; i++)
  287. {
  288. gotoxy(i,y);
  289. {
  290. cout<<ch<<endl;
  291. cout<<" ";
  292. delay(25);
  293. }
  294. gotoxy(64,47);
  295. }
  296. }
  297. /***********************************************************************************************/
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: Memory game with c++ console applicaton

 
0
  #2
May 19th, 2006
There's a code snippet section. Try to contribute there.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 8
Reputation: gladiator1919 is an unknown quantity at this point 
Solved Threads: 0
gladiator1919 gladiator1919 is offline Offline
Newbie Poster

Re: Memory game with c++ console applicaton

 
0
  #3
May 20th, 2006
but why do you say this?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: Memory game with c++ console applicaton

 
0
  #4
May 20th, 2006
Originally Posted by gladiator1919
but why do you say this?
Because you didn't ask any question regarding code. It appears you are trying to share your knowledge. So, it's better to put it in right place.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 8
Reputation: gladiator1919 is an unknown quantity at this point 
Solved Threads: 0
gladiator1919 gladiator1919 is offline Offline
Newbie Poster

Re: Memory game with c++ console applicaton

 
0
  #5
May 20th, 2006
where is this snippet?
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 8
Reputation: gladiator1919 is an unknown quantity at this point 
Solved Threads: 0
gladiator1919 gladiator1919 is offline Offline
Newbie Poster

Re: Memory game with c++ console applicaton

 
0
  #6
May 20th, 2006
and where's the right place?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: Memory game with c++ console applicaton

 
0
  #7
May 20th, 2006
Originally Posted by gladiator1919
and where's the right place?
Here's the Code Snippet Section.
Before you contribute there make sure you take opinion on it.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 8
Reputation: gladiator1919 is an unknown quantity at this point 
Solved Threads: 0
gladiator1919 gladiator1919 is offline Offline
Newbie Poster

Re: Memory game with c++ console applicaton

 
0
  #8
May 20th, 2006
i've taken my opinion about this game
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: Memory game with c++ console applicaton

 
0
  #9
May 20th, 2006
Originally Posted by gladiator1919
i've taken my opinion about this game
Many people won't read further after reading 1st line.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC