Advertisement
Guest User

c++ kod gra

a guest
Nov 18th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <time.h>
  5. #include <stdio.h>
  6. #include <windows.h>
  7. #include <time.h>
  8. #include <conio.h>
  9.  
  10. using namespace std;
  11.  
  12. int liczba, strzal, ile_prob=0;
  13. int monety, XP, poziom=1;
  14. int wybor, wybor_sklep;
  15. int podpowiedz;
  16. bool ulepszenie[3];
  17. string linia;
  18. int nr_linii=1;
  19.  
  20. void zapisz()
  21. {
  22. fstream plik;
  23. plik.open("save.txt",ios::out);
  24.  
  25. plik<<monety<<endl;
  26. plik<<XP<<endl;
  27. plik<<poziom<<endl;
  28. plik<<ulepszenie[1]<<endl;
  29. plik<<ulepszenie[2]<<endl;
  30. plik<<ulepszenie[3]<<endl;
  31.  
  32. plik.close();
  33. }
  34.  
  35. void wczytaj()
  36. {
  37.  
  38. fstream plik;
  39. plik.open("save.txt", ios::in);
  40.  
  41. if(plik.good()==false) cout<<"Nie mozna otworzyc pliku!";
  42.  
  43. while (getline(plik, linia))
  44. {
  45. switch (nr_linii)
  46. {
  47. case 1:
  48. monety=atoi(linia.c_str());
  49. break;
  50. case 2:
  51. XP=atoi(linia.c_str());
  52. break;
  53. case 3:
  54. poziom=atoi(linia.c_str());
  55. break;
  56. case 4:
  57. ulepszenie[1]=atoi(linia.c_str());
  58. break;
  59. case 5:
  60. ulepszenie[2]=atoi(linia.c_str());
  61. break;
  62. case 6:
  63. ulepszenie[3]=atoi(linia.c_str());
  64. break;
  65.  
  66. }
  67. nr_linii++;
  68. }
  69.  
  70. plik.close();
  71.  
  72. }
  73.  
  74.  
  75. int main()
  76. {
  77. HANDLE hOut;
  78. hOut = GetStdHandle( STD_OUTPUT_HANDLE );
  79. while(true)
  80. {
  81. if(XP>=1000)
  82. {
  83. system("cls");
  84. poziom++;
  85. SetConsoleTextAttribute( hOut, 0x0030 );
  86. cout<<"BRAWO! Zdobywasz "<<poziom<<" poziom"<<endl;
  87. cout<<"Dostajesz +150 monet!"<<endl;
  88. monety = monety + 150;
  89. XP = XP - 1000;
  90.  
  91. Sleep(1500);
  92.  
  93. }
  94. wczytaj();
  95. SetConsoleTextAttribute( hOut, 0x0003 );
  96. cout<<"----Menu----"<<endl;
  97. SetConsoleTextAttribute( hOut, 0x0009 );
  98. cout<<"1.Graj"<<endl;
  99. cout<<"2.Wyzwania"<<endl;
  100. cout<<"3.Sklep"<<endl;
  101. cout<<"4.Wyjdz z gry"<<endl;
  102. SetConsoleTextAttribute( hOut, 0x0006 );
  103. cout<<"-------"<<endl;
  104. SetConsoleTextAttribute( hOut, 0x0004 );
  105. cout<<"Monety: "<<monety<<endl;
  106. cout<<"XP: "<<XP<<endl;
  107. cout<<"Poziom: "<<poziom<<endl;
  108. SetConsoleTextAttribute( hOut, 0x0006 );
  109. cout<<"-------"<<endl;
  110. SetConsoleTextAttribute( hOut, 0x0002 );
  111. cout << "Ulepszenie 1: " <<boolalpha << ulepszenie[1] << endl;
  112. cout << "Ulepszenie 2: " <<boolalpha << ulepszenie[2] << endl;
  113. cout << "Ulepszenie 3: " <<boolalpha << ulepszenie[3] << endl;
  114. SetConsoleTextAttribute( hOut, 0x0006 );
  115. cout<<"Twoj wybor: ";
  116. cin>>wybor;
  117.  
  118. zapisz();
  119.  
  120.  
  121.  
  122.  
  123. switch(wybor)
  124. {
  125. //kody
  126. case 12321:
  127. monety = monety + 50000;
  128. XP = XP + 999;
  129. zapisz();
  130. system("cls");
  131.  
  132. break;
  133. case 32123:
  134. monety=0;
  135. XP=0;
  136. poziom=1;
  137. ulepszenie[1]=false;
  138. ulepszenie[2]=false;
  139. ulepszenie[3]=false;
  140.  
  141. zapisz();
  142.  
  143. system("cls");
  144.  
  145. break;
  146.  
  147. case 4:
  148.  
  149. zapisz();
  150. cout<<"Zapisywanie..."<<endl;
  151. Sleep(700);
  152. cout<<"Zapisywanie.."<<endl;
  153. Sleep(600);
  154. cout<<"Zapisywanie."<<endl;
  155.  
  156. exit(0);
  157.  
  158. break;
  159. case 1:
  160. system("cls");
  161. SetConsoleTextAttribute( hOut, 0x0003 );
  162. cout<<"Witaj! Pomyslalem sobie liczbe 1..100"<<endl;
  163. srand(time(NULL));
  164. liczba = rand()%100+1;
  165.  
  166. ile_prob=0;
  167. while(strzal!=liczba)
  168. {
  169. ile_prob++;
  170. SetConsoleTextAttribute( hOut, 0x0001 );
  171. cout<<"Zgadnij jaka (to Twoja "<<ile_prob<<" proba): ";
  172. cout<<liczba<<endl;
  173. cin>>strzal;
  174.  
  175. SetConsoleTextAttribute( hOut, 0x0044 );
  176. if(strzal>99)
  177. cout<<"Liczba to max 100!"<<endl;
  178.  
  179. if(strzal==liczba)
  180. {
  181. SetConsoleTextAttribute( hOut, 0x0003 );
  182. cout<<"Udalo sie! Wygrywasz w "<<ile_prob<<" probie"<<endl;
  183. cout<<"+15 monet!"<<endl;
  184. cout<<"+300 XP!"<<endl;
  185.  
  186. if(ile_prob==1)
  187. {
  188. SetConsoleTextAttribute( hOut, 0x0001 );
  189. cout<<"Brawo! Wygrales w pierwszej probie! Zdobywasz 30 dodatkowych monet"<<endl;
  190. monety = monety + 30;
  191. }
  192.  
  193. if(ile_prob<5 && ile_prob>1)
  194. {
  195. SetConsoleTextAttribute( hOut, 0x0002 );
  196. cout<<"Wygrales w mniej niz 5 probach! Zdobywasz 20 dodatkowych monet" << endl;
  197. monety = monety + 20;
  198. }
  199.  
  200. if(ile_prob<7 && ile_prob>5)
  201. {
  202. SetConsoleTextAttribute( hOut, 0x0004 );
  203. cout<<"Wygrales w mniej niz 7 probach! Zdobywasz 10 dodatkowych monet" << endl;
  204. monety = monety + 10;
  205. }
  206.  
  207.  
  208. if(ulepszenie[1]==true)
  209. {
  210. SetConsoleTextAttribute( hOut, 0x0006 );
  211. cout<<"Masz kupione ulepszenie! Dostajesz 300 XP wiecej"<<endl;
  212. XP = XP + 300;
  213. }
  214.  
  215. if(ulepszenie[2]==true)
  216. {
  217. SetConsoleTextAttribute( hOut, 0x0006 );
  218. cout<<"Masz kupione ulepszenie! Dostajesz 15 monet wiecej"<<endl;
  219. XP = XP + 300;
  220. }
  221. monety = monety + 15;
  222. XP = XP + 300;
  223. SetConsoleTextAttribute( hOut, 0x0005 );
  224. zapisz();
  225. cout<<"Kliknij dowolny klawisz i poczekaj 3 sekundy";
  226. Sleep(3000);
  227. system("cls");
  228. }
  229.  
  230. if(strzal<liczba)
  231. {
  232. SetConsoleTextAttribute( hOut, 0x0006 );
  233. if(ulepszenie[3]==true)
  234. {
  235. if(strzal<liczba)
  236. {
  237. podpowiedz = liczba - strzal;
  238. if(podpowiedz<=25)
  239. cout<<"Liczba jest o "<< podpowiedz << " wieksza!"<<endl;
  240. }
  241. }
  242. SetConsoleTextAttribute( hOut, 0x0004 );
  243. cout<<"To za malo"<<endl;
  244. }
  245.  
  246. if(strzal>liczba)
  247. {
  248. SetConsoleTextAttribute( hOut, 0x0006 );
  249. if(ulepszenie[3]==true)
  250. {
  251. if(strzal>liczba)
  252. {
  253. podpowiedz = strzal - liczba;
  254.  
  255. if(podpowiedz<=25)
  256. cout<<"Liczba jest o "<< podpowiedz << " mniejsza!"<<endl;
  257. }
  258. }
  259. SetConsoleTextAttribute( hOut, 0x0002 );
  260. cout<<"To za duzo"<<endl;
  261. }
  262. }
  263.  
  264. getchar();
  265. getchar(); //dla pewnosci 2 razy
  266. break;
  267.  
  268. case 3:
  269. SetConsoleTextAttribute( hOut, 0x0004 );
  270. cout<<"Ulepszenia zapisuj¹ siê! Ulepszenia nie dzia³aj¹ w trybie challange" << endl;
  271. SetConsoleTextAttribute( hOut, 0x0003 );
  272. cout<<"1.Dodatkowy exp! 120$"<<endl;
  273. cout<<"2.Dodatkowe monety! 150$"<<endl;
  274. cout<<"3.Podpowiedz z dokladnoscia do 25! 250$"<<endl;
  275. cin>>wybor_sklep;
  276.  
  277. switch(wybor_sklep)
  278. {
  279. case 1:
  280. if(monety>=120)
  281. {
  282. ulepszenie[1]=true;
  283. monety = monety - 120;
  284. SetConsoleTextAttribute( hOut, 0x0002 );
  285. cout << "Ulepszenie kupione!" <<endl;
  286. zapisz();
  287. }
  288.  
  289. SetConsoleTextAttribute( hOut, 0x0004 );
  290. if(monety<120)
  291. cout<<"Nie stac Cie!" <<endl;
  292.  
  293. Sleep(1000);
  294. system("cls");
  295.  
  296.  
  297. break;
  298.  
  299.  
  300. case 3:
  301. if(monety>=250)
  302. {
  303. ulepszenie[3]=true;
  304. SetConsoleTextAttribute( hOut, 0x0002 );
  305. monety = monety - 250;
  306. cout << "Ulepszenie kupione!" <<endl;
  307. zapisz();
  308. }
  309.  
  310. SetConsoleTextAttribute( hOut, 0x0004 );
  311. if(monety<250)
  312. cout<<"Nie stac Cie!" <<endl;
  313. Sleep(1000);
  314. system("cls");
  315. break;
  316.  
  317.  
  318. case 2:
  319. if(monety>=150)
  320. {
  321. ulepszenie[2]=true;
  322. monety = monety - 150;
  323. SetConsoleTextAttribute( hOut, 0x0002 );
  324. cout << "Ulepszenie kupione!" <<endl;
  325. zapisz();
  326. }
  327.  
  328. SetConsoleTextAttribute( hOut, 0x0002 );
  329. if(monety<150)
  330. cout<<"Nie stac Cie!" <<endl;
  331. Sleep(1000);
  332. system("cls");
  333.  
  334.  
  335. break;
  336.  
  337.  
  338. }
  339.  
  340.  
  341. }
  342. }
  343. return 0;
  344.  
  345. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement