Word Game


SUBMITTED BY: amnesia

DATE: Aug. 12, 2019, 5:27 p.m.

FORMAT: Text only

SIZE: 9.5 kB

HITS: 417

  1. #include <iostream.h>
  2. #include <conio.h>
  3. #include <iomanip.h>
  4. #include <string.h>
  5. #include <dos.h>
  6. #include <process.h>
  7. void display()
  8. {
  9. cout << "--------------------------------------------------------------------------------";
  10. cout << "-------------------------------WORD GUESSING GAME-------------------------------";
  11. cout << "--------------------------------------------------------------------------------";
  12. cout << "\n\n Start Game";
  13. cout << "\n\n How to Play";
  14. cout << "\n\n Credits";
  15. cout << "\n\n Quit";
  16. gotoxy(22,25);
  17. cout<<"Press \'W\' to go up and \'S\' to go down";
  18. gotoxy(29,24);
  19. cout<<"Press <ENTER> to select";
  20. }
  21. struct coordinate
  22. { int x,y;};
  23. struct level
  24. {
  25. char hint[5][11];
  26. char answer[10];
  27. };
  28. void youwin(int points)
  29. {
  30. clrscr();
  31. gotoxy(1,1);
  32. cout<<" .\n";
  33. cout<<" J:L (\"\"\")\n";
  34. cout<<" |:| III\n";
  35. cout<<" |:| III\n";
  36. cout<<" |:| III\n" ;
  37. cout<<" |:| __III__\n";
  38. cout<<" |:| /:-.___,-:\\\n";
  39. cout<<" |:| \\] |:| [/\n" ;
  40. cout<<" |:| |:|\n" ;
  41. cout<<" |:| |:|\n" ;
  42. cout<<" |:| |:|\n" ;
  43. cout<<"/] |:| [\\ |:|\n" ;
  44. cout<<"\\:-'\"\"\"`-:/ |:|\n" ;
  45. cout<<" \"\"III\"\" |:|\n";
  46. cout<<" III |:|\n" ;
  47. cout<<" III |:|\n" ;
  48. cout<<" III |:|\n" ;
  49. cout<<" (___) J:F \n" ;
  50. cout<<" \"" ;
  51. gotoxy(35,8);
  52. cout<<"__ __ _ \n";
  53. gotoxy(35,9);
  54. cout<<"\\ \\/ /___ __ __ _ __(_)___ \n";
  55. gotoxy(35,10);
  56. cout<<" \\ / __ \\/ / / / | | /| / / / __ \\\n";
  57. gotoxy(35,11);
  58. cout<<" / / /_/ / /_/ / | |/ |/ / / / / /\n";
  59. gotoxy(35,12);
  60. cout<<"/_/\\____/\\__,_/ |__/|__/_/_/ /_/ \n";
  61. gotoxy(43,15);
  62. cout<<"Your points are "<< points;
  63. }
  64. void prtchar(char x,int length)
  65. {
  66. for (int i = 1; i <=length; i++)
  67. {
  68. cout << x;
  69. }
  70. }
  71. void prtbox(coordinate &a,coordinate &b)
  72. {
  73. gotoxy(a.x,a.y);
  74. prtchar('-',((b.x)-(a.x)+1));
  75. gotoxy(a.x,b.y);
  76. prtchar('-',((b.x)-(a.x)+1));
  77. int x;
  78. for(x=((a.y)+1);x<b.y;x++)
  79. {
  80. gotoxy(a.x,x);
  81. cout<<'|';
  82. gotoxy(b.x,x);
  83. cout<<'|';
  84. }
  85. }
  86. void select(int selection)
  87. {
  88. coordinate a,b;
  89. if (selection==0)
  90. {
  91. a.x= 35;
  92. a.y= 5;
  93. b.x= 46;
  94. b.y= 7;
  95. }
  96. else if (selection ==1)
  97. {
  98. a.x=34;
  99. a.y=7;
  100. b.x=46;
  101. b.y=9;
  102. }
  103. else if (selection == 2)
  104. {
  105. a.x=36;
  106. a.y=9;
  107. b.x=44;
  108. b.y=11;
  109. }
  110. else if (selection== 3)
  111. {
  112. a.x=37;
  113. a.y=11;
  114. b.x=42;
  115. b.y=13;
  116. }
  117. prtbox(a,b);
  118. }
  119. void assignlevel(level &a,int select)
  120. {
  121. if(select==1)
  122. {
  123. strcpy(a.hint[0],"dough");
  124. strcpy(a.hint[1],"wheat");
  125. strcpy(a.hint[2],"5 lettered");
  126. strcpy(a.hint[3],"bun");
  127. strcpy(a.hint[4],"bakery");
  128. strcpy(a.answer,"bread");
  129. }
  130. else if(select==2)
  131. {
  132. strcpy(a.hint[0],"jackpot");
  133. strcpy(a.hint[1],"luck");
  134. strcpy(a.hint[2],"lotto");
  135. strcpy(a.hint[3],"win");
  136. strcpy(a.hint[4],"bingo");
  137. strcpy(a.answer,"lottery");
  138. }
  139. else if(select==3)
  140. {
  141. strcpy(a.hint[0],"egypt");
  142. strcpy(a.hint[1],"pharoh");
  143. strcpy(a.hint[2],"triangle");
  144. strcpy(a.hint[3],"tomb");
  145. strcpy(a.hint[4],"sphinx");
  146. strcpy(a.answer,"pyramid");
  147. }
  148. else if(select==4)
  149. {
  150. strcpy(a.hint[0],"device");
  151. strcpy(a.hint[1],"electronic");
  152. strcpy(a.hint[2],"widget");
  153. strcpy(a.hint[3],"inspector");
  154. strcpy(a.hint[4],"gizmo");
  155. strcpy(a.answer,"gadget");
  156. }
  157. else if(select==5)
  158. {
  159. strcpy(a.hint[0],"fish");
  160. strcpy(a.hint[1],"rice");
  161. strcpy(a.hint[2],"japanese");
  162. strcpy(a.hint[3],"roll");
  163. strcpy(a.hint[4],"dish");
  164. strcpy(a.answer,"sushi");
  165. }
  166. else if(select==6)
  167. {
  168. strcpy(a.hint[0],"fog");
  169. strcpy(a.hint[1],"air");
  170. strcpy(a.hint[2],"london");
  171. strcpy(a.hint[3],"pollution");
  172. strcpy(a.hint[4],"fumes");
  173. strcpy(a.answer,"smog");
  174. }
  175. else if(select==7)
  176. {
  177. strcpy(a.hint[0],"event");
  178. strcpy(a.hint[1],"gregorian");
  179. strcpy(a.hint[2],"date");
  180. strcpy(a.hint[3],"month");
  181. strcpy(a.hint[4],"year");
  182. strcpy(a.answer,"calendar");
  183. }
  184. else if(select==8)
  185. {
  186. strcpy(a.hint[0],"snack");
  187. strcpy(a.hint[1],"pastry");
  188. strcpy(a.hint[2],"cookie");
  189. strcpy(a.hint[3],"dough");
  190. strcpy(a.hint[4],"crispy");
  191. strcpy(a.answer,"biscuit");
  192. }
  193. else if(select==9)
  194. {
  195. strcpy(a.hint[0],"wall");
  196. strcpy(a.hint[1],"stone");
  197. strcpy(a.hint[2],"block");
  198. strcpy(a.hint[3],"house");
  199. strcpy(a.hint[4],"red");
  200. strcpy(a.answer,"brick");
  201. }
  202. else if(select==10)
  203. {
  204. strcpy(a.hint[0],"racket");
  205. strcpy(a.hint[1],"set");
  206. strcpy(a.hint[2],"ball");
  207. strcpy(a.hint[3],"table");
  208. strcpy(a.hint[4],"court");
  209. strcpy(a.answer,"tennis");
  210. }
  211. else
  212. {
  213. strcpy(a.hint[0],"Level not designed");
  214. strcpy(a.hint[1],"???");
  215. strcpy(a.hint[2],"???");
  216. strcpy(a.hint[3],"???");
  217. strcpy(a.hint[4],"???");
  218. strcpy(a.answer,"???");
  219. }
  220. }
  221. int levels(int select)
  222. {
  223. level a;
  224. char inp; //for accepting commands
  225. char input[10]; //for accepting answer
  226. coordinate b,c;
  227. int i,loopvar=0; //loop variable
  228. int hint =0;
  229. while(1)
  230. {
  231. gotoxy(36,3);
  232. cout<< "LEVEL "<<select;
  233. assignlevel(a,select);
  234. gotoxy(1,2);
  235. cout << "Points for winning "<< (100 - (20*hint));
  236. b.x=20;
  237. b.y=1;
  238. c.y=3;
  239. if (hint ==0)
  240. {
  241. c.x=24;
  242. }
  243. else
  244. {
  245. c.x=23;
  246. }
  247. gotoxy(60,2);
  248. cout<<"Press \'+\' for hint";
  249. prtbox(b,c);
  250. for(i=0;i<=hint;i++) // example "dough", 80/2 = 40(middle), 40+-2=range
  251. {
  252. gotoxy((40-(strlen(a.hint[i])/2)),(6+(i*2)));
  253. cout << a.hint[i];
  254. }
  255. b.y=17;
  256. c.y=19;
  257. b.x=(39.5-(0.5*(double(loopvar)))); //print answer box
  258. c.x=(41.5+(0.5*(double(loopvar))));
  259. prtbox(b,c);
  260. gotoxy(((39.5-(0.5*(double(loopvar))))+1),(18));
  261. for(i=0;i<loopvar;i++)
  262. {
  263. cout<<input[i];
  264. }
  265. cout<<' ';
  266. for(i=0;a.answer!='\0';i++)
  267. {
  268. if(input[i]!=a.answer[i])
  269. break;
  270. if((strlen(a.answer)-1)==i)
  271. {
  272. clrscr();
  273. youwin(100 - (20*hint));
  274. getch();
  275. clrscr();
  276. return 0;
  277. }
  278. }
  279. inp=getch();
  280. clrscr();
  281. if(inp=='+')
  282. {
  283. if(hint!=4)
  284. {
  285. hint++;
  286. }
  287. }
  288. else if(inp==8) //backspace for clearing characters of answer[10]
  289. {
  290. if(loopvar!=0)
  291. {
  292. loopvar--;
  293. }
  294. }
  295. else if( ((inp>='a')&&(inp<='z'))||((inp>='A')&&(inp<='Z')))
  296. {
  297. if(loopvar!=8)
  298. {
  299. input[loopvar]=inp;
  300. loopvar++;
  301. }
  302. }
  303. else if(inp=='-') //'-' for going back
  304. {
  305. break;
  306. }
  307. }
  308. clrscr();
  309. return 0;
  310. }
  311. void startgame()
  312. {
  313. int select=1;
  314. char c;
  315. while(1)
  316. { gotoxy(28,1);
  317. cout<<" __ __ __";
  318. gotoxy(28,2);
  319. cout<<"| | | | | | |";
  320. gotoxy(28,3);
  321. cout<<"| |-- | | |-- | --";
  322. gotoxy(28,4);
  323. cout<<"|__ |__ \\/ |__ |__ __|";
  324. int x;
  325. coordinate a,b;
  326. for(x=1;x<10;x++)
  327. {
  328. gotoxy(((x*7)+2),8);
  329. cout<<x;
  330. a.x=((x*7)+1);
  331. b.x=((x*7)+3);
  332. a.y=7;
  333. b.y=9;
  334. prtbox(a,b);
  335. }
  336. a.x=71;
  337. b.x=74;
  338. a.y=7;
  339. b.y=9;
  340. gotoxy(72,8);
  341. cout<<10;
  342. prtbox(a,b);//box 10 printed
  343. if(select!=10)
  344. {
  345. a.x=(7*select);
  346. b.x=((7*select)+4);
  347. a.y=6;
  348. b.y=10;
  349. }
  350. else
  351. {
  352. a.x=70;
  353. b.x=75;
  354. a.y=6;
  355. b.y=10;
  356. }
  357. prtbox(a,b);
  358. c=getch();
  359. clrscr();
  360. if ((c=='a')||(c=='A'))
  361. {
  362. if(select!=1)
  363. {
  364. select--;
  365. }
  366. }
  367. else if ((c=='d')||(c=='D'))
  368. {
  369. if(select!=10)
  370. {
  371. select++;
  372. }
  373. }
  374. else if (c=='-')//'-' for going back to main page
  375. {
  376. break;
  377. }
  378. else if (c==13)
  379. {
  380. levels(select);
  381. }
  382. }
  383. }
  384. void howtoplay()
  385. {
  386. gotoxy(35,3);
  387. cout<<"HOW TO PLAY";
  388. gotoxy(1,5);
  389. cout<<"\nPress \'W\' and \'S\' to go up and down\n";
  390. cout<<"Press \'A\' and \'D\' to go left and right\n";
  391. cout<<"Press <Enter> to select\n";
  392. cout<<"Press \'-\' to go back\n";
  393. cout<<"For each hint 20 points will be reduced";
  394. cout<<"\n\nPRESS ANY KEY TO GO BACK";
  395. getch();
  396. }
  397. void credits()
  398. {
  399. int i=25;
  400. for(;i>=-8;i--)
  401. {
  402. clrscr();
  403. if((i>0)&&(i<=25))
  404. {
  405. gotoxy(37,i);
  406. cout<<"CREDITS";
  407. }
  408. if(((i+3)>0)&&((i+3)<=25))
  409. {
  410. gotoxy(34,(i+3));
  411. cout<<"Deepak Prasad";
  412. }
  413. if(((i+5)>0)&&((i+5)<=25))
  414. {
  415. gotoxy(35,(i+5));
  416. cout<<"Vikas Kumar";
  417. }
  418. if(((i+7)>0)&&((i+7)<=25))
  419. {
  420. gotoxy(30,(i+7));
  421. cout<<"Abhishek Kumar Mahato";
  422. }
  423. if(((i+9)>0)&&((i+9)<=25))
  424. {
  425. gotoxy(35,(i+9));
  426. cout<<"Sumit Kumar";
  427. }
  428. delay(200);
  429. }
  430. }
  431. void quit()
  432. {
  433. clrscr();
  434. retry:
  435. gotoxy(27,12);
  436. cout<<"Do you really want to quit?";
  437. gotoxy(38,13);
  438. cout<<"Y/N";
  439. char c;
  440. c= getch();
  441. if((c=='y')||(c=='Y'))
  442. exit(0);
  443. else if(!((c=='n')||(c=='N')))
  444. goto retry;
  445. }
  446. void main()
  447. {
  448. char c='w';
  449. int selec=0;
  450. while(1)
  451. {
  452. clrscr();
  453. display();
  454. select(selec);
  455. c=getch();
  456. if((c=='w')||(c=='W'))//up
  457. {
  458. if(selec!=0)
  459. selec--;
  460. }
  461. else if((c=='s')||(c=='S'))//down
  462. {
  463. if(selec!=3)
  464. selec++;
  465. }
  466. else if (c=='-')
  467. break;
  468. else if(c==13) //enter for selection(ASCII value 13)
  469. {
  470. clrscr();
  471. if(selec==0)
  472. startgame();
  473. else if(selec==1)
  474. howtoplay();
  475. else if(selec==2)
  476. credits();
  477. else if(selec==3)
  478. quit();
  479. }
  480. }
  481. }

comments powered by Disqus