Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <fstream>
  4. #include <ctime>
  5. #include <cstdlib>
  6. #include <stdio.h>
  7. #include <conio.h>
  8. using namespace std;
  9. char znak;
  10. string a;
  11. string wyrazy[6];
  12. string haslo="";
  13. string uzyte=" ";
  14. string uzywane="";
  15. string zagadka="";
  16. string ukryte="";
  17. string kategoria;
  18. int losuj;
  19. int i=0;
  20. int szanse=8;
  21. int wybor;
  22. char wybrac;
  23. int skucha=0;
  24. int dlugosc=0;
  25. int logika=0;
  26. int wyjscie=0;
  27. char Wybor;
  28. void informatyka()
  29. { ifstream wej("informatyka.txt");
  30. srand(time(NULL));
  31. while(!wej.eof())
  32. { wej>>a;
  33. wyrazy[i]=a;
  34. i++;
  35. }
  36. losuj=rand()%6;
  37. haslo=wyrazy[losuj];
  38. kategoria="Informatyka";
  39.  
  40. }
  41. void zwierzeta()
  42. { ifstream wej("zwierzeta.txt");
  43. srand(time(NULL));
  44. while(!wej.eof())
  45. { wej>>a;
  46. wyrazy[i]=a;
  47. i++;
  48. }
  49. losuj=rand()%6;
  50. haslo=wyrazy[losuj];
  51. kategoria="Zwierzeta";
  52.  
  53. }
  54. void inne()
  55. { ifstream wej("inne.txt");
  56. srand(time(NULL));
  57. while(!wej.eof())
  58. { wej>>a;
  59. wyrazy[i]=a;
  60. i++;
  61. }
  62. losuj=rand()%6;
  63. haslo=wyrazy[losuj];
  64. kategoria="Inne";
  65.  
  66. }
  67. void lato()
  68. { ifstream wej("lato.txt");
  69. srand(time(NULL));
  70. while(!wej.eof())
  71. { wej>>a;
  72. wyrazy[i]=a;
  73. i++;
  74. }
  75. losuj=rand()%6;
  76. haslo=wyrazy[losuj];
  77. kategoria="Lato";
  78.  
  79. }
  80. void rosliny()
  81. { ifstream wej("rosliny.txt");
  82. srand(time(NULL));
  83. while(!wej.eof())
  84. { wej>>a;
  85. wyrazy[i]=a;
  86. i++;
  87. }
  88. losuj=rand()%6;
  89. haslo=wyrazy[losuj];
  90. kategoria="Rosliny";
  91.  
  92. }
  93. void zima()
  94. { ifstream wej("zima.txt");
  95. srand(time(NULL));
  96. while(!wej.eof())
  97. { wej>>a;
  98. wyrazy[i]=a;
  99. i++;
  100. }
  101. losuj=rand()%6;
  102. haslo=wyrazy[losuj];
  103. kategoria="Zima";
  104.  
  105. }
  106. int menu()
  107. { cout<<"Witaj w menu gry Wisielec."<<endl<<"Wybierz kategorie z ktorej postarasz sie odgadnac haslo."<<endl;
  108. cout<<"1.Informatyka"<<endl;
  109. cout<<"2.zwierzeta"<<endl;
  110. cout<<"3.Inne"<<endl;
  111. cout<<"4.Lato"<<endl;
  112. cout<<"5.Rosliny"<<endl;
  113. cout<<"6.Zima"<<endl<<endl<<endl;
  114. cout<<"9. Wyjsice z gry"<<endl;
  115. cout<<" By: Tomasz Siemieniuk"<<endl;
  116.  
  117. wybrac=getch();
  118. switch(wybrac)
  119. {
  120. case '1':
  121. wybor=1;
  122. break;
  123.  
  124. case '2':
  125. wybor=2;
  126. break;
  127.  
  128. case '3':
  129. wybor=3;
  130. break;
  131.  
  132. case '4':
  133. wybor=4;
  134. break;
  135.  
  136. case '5':
  137. wybor=5;
  138. break;
  139.  
  140. case '6':
  141. wybor=6;
  142. break;
  143.  
  144. case '9':
  145. exit(0);
  146. break;
  147. }
  148. }
  149.  
  150.  
  151.  
  152. void PrzejscieDoHasel()
  153. { int pomocnicza=0;
  154. system("cls");
  155. while(pomocnicza<7)
  156. { cout<<endl;
  157. pomocnicza++;
  158. }
  159. cout<<" ";
  160.  
  161. if(wybor==1)
  162. {
  163. informatyka();
  164.  
  165. for(int dlugosc=0;dlugosc<haslo.size();dlugosc++)
  166. { ukryte[dlugosc]='_';
  167. cout<<ukryte[dlugosc]<<" ";
  168. }
  169.  
  170.  
  171. }
  172. if(wybor==2)
  173. {
  174. zwierzeta();
  175.  
  176. for(int dlugosc=0;dlugosc<haslo.size();dlugosc++)
  177. { ukryte[dlugosc]='_';
  178. cout<<ukryte[dlugosc]<<" ";
  179. }
  180.  
  181.  
  182. }
  183. if(wybor==3)
  184. {
  185. inne();
  186.  
  187. for(int dlugosc=0;dlugosc<haslo.size();dlugosc++)
  188. { ukryte[dlugosc]='_';
  189. cout<<ukryte[dlugosc]<<" ";
  190. }
  191.  
  192.  
  193. }
  194. if(wybor==4)
  195. {
  196. lato();
  197.  
  198. for(int dlugosc=0;dlugosc<haslo.size();dlugosc++)
  199. { ukryte[dlugosc]='_';
  200. cout<<ukryte[dlugosc]<<" ";
  201.  
  202. }
  203.  
  204.  
  205. }
  206. if(wybor==5)
  207. {
  208. rosliny();
  209.  
  210. for(int dlugosc=0;dlugosc<haslo.size();dlugosc++)
  211. { ukryte[dlugosc]='_';
  212. cout<<ukryte[dlugosc]<<" ";
  213. }
  214.  
  215. }
  216. if(wybor==6)
  217. {
  218. zima();
  219.  
  220. for(int dlugosc=0;dlugosc<haslo.size();dlugosc++)
  221. { ukryte[dlugosc]='_';
  222. cout<<ukryte[dlugosc]<<" ";
  223. }
  224.  
  225.  
  226.  
  227. }
  228. while(pomocnicza<7)
  229. { cout<<endl;
  230. pomocnicza++;
  231. }
  232.  
  233. cout<<endl;
  234. cout<<endl;
  235. }
  236. void wisielec()
  237. { cout<<endl;
  238. if(skucha==1)
  239. {cout<<endl;
  240. cout<<" "<<"|"<<endl;
  241. cout<<" "<<"|"<<endl<<endl<<endl<<endl;
  242. }
  243. if(skucha==2)
  244. {
  245. cout<<" "<<"|"<<endl;
  246. cout<<" "<<"|"<<endl;
  247. cout<<" "<<"|"<<endl;
  248. cout<<" "<<"|"<<endl<<endl<<endl;
  249. }
  250. if(skucha==3)
  251. { cout<<" "<<" __"<<endl;
  252. cout<<" "<<"|"<<endl;
  253. cout<<" "<<"|"<<endl;
  254. cout<<" "<<"|"<<endl;
  255. cout<<" "<<"|"<<endl<<endl;
  256. }
  257. if(skucha==4)
  258. { cout<<" "<<" ____"<<endl;
  259. cout<<" "<<"|"<<endl;
  260. cout<<" "<<"|"<<endl;
  261. cout<<" "<<"|"<<endl;
  262. cout<<" "<<"|"<<endl<<endl;
  263. }
  264. if(skucha==5)
  265. { cout<<" "<<" ____"<<endl;
  266. cout<<" "<<"| :"<<endl;
  267. cout<<" "<<"|"<<endl;
  268. cout<<" "<<"|"<<endl;
  269. cout<<" "<<"|"<<endl<<endl;
  270. }
  271. if(skucha==6)
  272. { cout<<" "<<" ____"<<endl;
  273. cout<<" "<<"| :"<<endl;
  274. cout<<" "<<"| O"<<endl;
  275. cout<<" "<<"|"<<endl;
  276. cout<<" "<<"|"<<endl<<endl;
  277. }
  278. if(skucha==7)
  279. { cout<<" "<<" ____"<<endl;
  280. cout<<" "<<"| :"<<endl;
  281. cout<<" "<<"| O"<<endl;
  282. cout<<" "<<"| +"<<endl;
  283. cout<<" "<<"|"<<endl<<endl;
  284. }
  285. if(skucha==8)
  286. { cout<<" "<<" ____"<<endl;
  287. cout<<" "<<"| :"<<endl;
  288. cout<<" "<<"| O"<<endl;
  289. cout<<" "<<"| +"<<endl;
  290. cout<<" "<<"| ^"<<endl<<endl;
  291. }
  292. }
  293. void zgadywanka()
  294. { int zliczaj=0;
  295. int test=0;
  296.  
  297. cout<<endl<<endl;
  298. cout<<"Kategoria: "<<kategoria<<endl;
  299. cout<<"Zachowane szanse:"<<szanse<<endl;
  300. cout<<"Uzyte litery to:"<<uzywane<<endl;
  301.  
  302. cout<<"Prosimy o podanie literek: ";
  303. cin>>znak;
  304. for(int sprawdz=0;sprawdz<uzyte.size();sprawdz++)
  305. {
  306. if(znak!=uzyte[sprawdz]) zliczaj++;
  307.  
  308. if(zliczaj==uzyte.size()) uzyte=uzyte+znak;
  309. else test++;
  310. uzywane=uzyte+" ";
  311.  
  312. }
  313. int liczy=0;
  314. for(int c=0;c<haslo.size();c++)
  315. { if(znak==haslo[c])
  316. {
  317. ukryte[c]=znak;
  318. liczy++;
  319.  
  320. }
  321. logika=0;
  322.  
  323. }
  324. for(int d=0;d<haslo.size();d++) if(ukryte[d]!='_') logika++;
  325.  
  326. if(liczy==0 && test!=uzyte.size()) //-xxxfgff
  327. {
  328. skucha++;
  329. szanse--;
  330. }
  331. liczy=0;
  332. zliczaj=0;
  333.  
  334.  
  335. }
  336. void rysowanie()
  337. { int pomocnicza=0;
  338.  
  339. while(pomocnicza<6)
  340. { cout<<endl;
  341. pomocnicza++;
  342. }
  343. cout<<" ";
  344.  
  345. for(int dlugosc=0;dlugosc<haslo.size();dlugosc++)
  346. {
  347. cout<<ukryte[dlugosc]<<" ";
  348. }
  349. }
  350.  
  351. int main()
  352. {
  353. while(1)
  354. {
  355. menu();
  356. PrzejscieDoHasel();
  357. if(wyjscie==1) return 0;
  358.  
  359. while(1)
  360. {
  361. zgadywanka();
  362. system("cls");
  363. wisielec();
  364. rysowanie();
  365.  
  366.  
  367. if(logika==haslo.size())
  368. { cout<<endl<<endl<<"Wygrana!!!"<<endl;
  369. break; }
  370. if(skucha==8)
  371. {cout<<endl<<endl<<endl<<"O nie!!! Przegrana :("<<endl;
  372. cout<<"Haslem bylo: "<<haslo<<endl;
  373. break;}
  374.  
  375. }
  376. cout<<endl<<endl<<"Czy chcesz zagrac ponownie? ([t]ak/[n]ie): ";
  377. while(Wybor!='t' || Wybor!='n')
  378. { cin>>Wybor;
  379. if(Wybor=='n') return 0;
  380. if(Wybor=='t')
  381. {
  382. string haslo="";
  383. string zagadka="";
  384. string ukryte=" ";
  385. i=0;
  386. skucha=0;
  387. dlugosc=0;
  388. szanse=8;
  389.  
  390. uzyte=" ";
  391. uzywane="";
  392.  
  393.  
  394. logika=0;
  395. system("cls");
  396. break;
  397. }
  398. }
  399. }
  400. return 0;
  401. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement