Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.82 KB | None | 0 0
  1. #include <iostream>
  2. #include "windows.h"
  3. #include <conio.h>
  4. #include <fstream>
  5. #include <string>
  6. #include <cstdlib>
  7.  
  8. using namespace std;
  9.  
  10.  
  11.  
  12. struct game_properties {
  13. int score;
  14. int level;
  15. int dela;
  16. } ;
  17.  
  18. struct game_controllers {
  19. int g;
  20. int bul;
  21. int l;
  22. int r;
  23. int key;
  24. } ;
  25.  
  26. int mat[6][16];
  27.  
  28. game_controllers controllers;
  29. controllers.g=0;
  30. controllers.bul=1;
  31. controllers.l=0;
  32.  
  33. game_properties options;
  34. options.score = 1;
  35. optionslevel = 1;
  36. options.dela = 100;
  37.  
  38. int i=0;
  39. void gotoxy(int x, int y)
  40. {
  41. COORD coord;
  42. coord.X = x;
  43. coord.Y = y;
  44. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  45. }
  46. void logo()
  47. {
  48. int enter;
  49. gotoxy(0, 0);
  50. cout << "";
  51. gotoxy(1, 1);
  52. cout << " O))))))) O) O)) O)))))))" << endl;
  53. cout << " O)) O)) O) )) O)) O)) O)) " << endl;
  54. cout << " O)) O)) O) O)) O)) O)) " << endl;
  55. cout << " O) O)) O)) O)) O)) O)))))) " << endl;
  56. cout << " O)) O)) O)))))) O)) O)) O)) " << endl;
  57. cout << " O)) O)) O)) O)) O)) O)) O)) " << endl;
  58. cout << " O)) O)) O)) O)) O)))) O))))))))" << endl;
  59.  
  60. Sleep(1000);
  61. for (int i = 25; i > 0; i--)
  62. {
  63.  
  64. gotoxy(1, i);
  65. cout << " ";
  66. Sleep(100);
  67. //system("cls");
  68.  
  69. }
  70. }
  71.  
  72.  
  73.  
  74.  
  75. void resetb()
  76. {
  77. for(int j=0;j<16;j++){
  78. for(int i=0;i<6;i++){mat[i][j]=0;}
  79.  
  80. }
  81. }
  82.  
  83. void drawp(int x,int y)
  84. {
  85. if(x>=0&x<6&y>=0&y<16){mat[x][y]=1;}
  86. }
  87.  
  88. void drawc(int x,int y)
  89. {
  90. drawp(1+x,0+y);
  91. drawp(0+x,1+y);drawp(1+x,1+y);drawp(2+x,1+y);
  92. drawp(1+x,2+y);
  93. drawp(0+x,3+y);drawp(1+x,3+y);drawp(2+x,3+y);
  94. }
  95.  
  96. int getr()
  97. {
  98. int n;
  99. if(rand()%2==0){n=0;}else{n=3;}
  100. return n;
  101. }
  102.  
  103. HANDLE hstdout = GetStdHandle( STD_OUTPUT_HANDLE );
  104. int index=1;
  105. void colorit(int col){;
  106. SetConsoleTextAttribute( hstdout, col );
  107. }
  108.  
  109.  
  110. int showMenu();
  111.  
  112. DWORD WINAPI ThreadFn(LPVOID vpParam)
  113. {
  114. while (1) {
  115. for(int i=8;i<=190;i++)
  116. {
  117. if(GetAsyncKeyState(i)==-32767){
  118. if(i==37){controllers.l=0;}else if(i==39){controllers.l=3;}
  119. }
  120. }
  121. }
  122. return 0;
  123. }
  124.  
  125. DWORD qThreadID;
  126. HANDLE hThread;
  127. void startInput(){
  128. hThread = CreateThread(0, 0, ThreadFn, 0, 0, &qThreadID);
  129. }
  130.  
  131. void startGame(){
  132. system("cls");
  133. gotoxy(7,2);cout<<" CONTROLS";
  134. gotoxy(7,3);cout<<" ========";
  135. gotoxy(7,4);cout<<"<<== [LEFT ARROW]";
  136. gotoxy(7,5);cout<<"==>> [RIGHT ARROW]";
  137.  
  138. for(int i=3;i>=0;i--){
  139. gotoxy(7,7);cout<<i;
  140. gotoxy(14,14);
  141. Sleep(1000);
  142. }
  143. system("cls");
  144.  
  145. while(controllers.bul){
  146. gotoxy(14,4);cout<<"SCORE:"<<options.score;
  147. gotoxy(14,5);cout<<"LEVEL:"<<options.level;
  148. resetb();
  149. drawc(controllers.r,controllers.g);
  150. drawc(controllers.l,12);
  151. for(int j=0;j<16;j++){
  152. gotoxy(4,j+1);cout<<"8";
  153. gotoxy(5,j+1);
  154. for(int i=0;i<6;i++){if(mat[i][j]==1){cout <<"O";}else{cout<<" ";}}gotoxy(11,j+1);cout<<"8";
  155. if(controllers.g>=12&controllers.l==controllers.r){controllers.bul=0;}
  156. }
  157. controllers.g++;
  158. if(controllers.g==15){controllers.g=-4;controllers.r=getr();;options.score=options.score+1;}
  159. if(options.score%5==0&(controllers.g==15|controllers.g==-4)){options.level++;options.dela=options.dela-1;}
  160. if(options.dela<0){gotoxy(14,4);cout<<"YOU WIN!"<<endl;controllers.bul=0;}
  161. Sleep(options.dela);
  162. }
  163.  
  164. if(options.dela>0){ gotoxy(14,4);colorit(12);
  165. cout<<"GAME OVER"<<endl;colorit(15);
  166.  
  167. }
  168.  
  169. Sleep(1000);
  170. system("cls");
  171. gotoxy(14,5);colorit(12);cout<<"YOUR SCORE: "<< options.score <<endl;colorit(15);;
  172.  
  173. fstream plik1("D:plik.txt", ios::out|ios::app);
  174.  
  175.  
  176. plik1 << options.score << endl;
  177. for (int tab[i],int n)
  178. {
  179. for(int i=0;i<n;i++)
  180. for(int j=1;j<n-i;j++)
  181. if(tab[j-1]>tab[j])
  182.  
  183. swap(tab[j-1], tab[j]);
  184. }
  185.  
  186.  
  187.  
  188.  
  189. plik1.close();
  190.  
  191. gotoxy(14,4);colorit(12);cout<<"GAME OVER"<<endl;colorit(15);
  192.  
  193.  
  194. Sleep(1500);
  195. controllers.g=0,controllers.bul=1,controllers.l=0,controllers.r;
  196. options.score=1,options.level=1,options.dela=100;
  197. showMenu();
  198.  
  199. }
  200.  
  201. void exitGame(){
  202. CloseHandle(hThread);
  203. system("cls");
  204. gotoxy(3,3);cout<<"GOOD BYE!";
  205. colorit(15);
  206. Sleep(2500);
  207. }
  208.  
  209.  
  210. int showMenu(){
  211. int ret=1;
  212. system("cls");
  213.  
  214. controllers.key=0;
  215. system("cls");
  216. while(controllers.key!=13){
  217. gotoxy(3,3);
  218. colorit(15);
  219. cout<<"CAR GAME CONSOLE";
  220. gotoxy(3,4);
  221. cout<<"================";
  222. gotoxy(3,5);
  223. colorit(15);
  224. if(index==1){colorit(12);}
  225. cout<<"START GAME";
  226. gotoxy(3,6);
  227. colorit(15);
  228. if(index==2){colorit(12);}
  229. cout<<"BEST SCORES";
  230. gotoxy(3,7);
  231. colorit(15);
  232. if(index==3){colorit(12);}
  233. cout<<"EXIT";
  234.  
  235. controllers.key=getch();
  236. if(controllers.key==80){index++;}
  237. else if(controllers.key==72){index--;}
  238. if(index==5){index=1;}
  239. if(index==0){index=4;}
  240. }
  241. if(index==1){
  242. startGame();
  243.  
  244.  
  245. }
  246. else if (index==2){
  247. system("cls");
  248. int zmienna;
  249.  
  250. FILE* plik1;
  251.  
  252. plik1 = fopen("D:plik.txt", "rb");
  253.  
  254. int liczba;
  255.  
  256. fread(&liczba, sizeof(int), 10, plik1);
  257. cout << liczba << endl;
  258.  
  259. fclose(plik1);
  260.  
  261.  
  262.  
  263. Sleep(5000);
  264. showMenu();
  265. }
  266.  
  267. else if (index==3){
  268. ret=1;
  269. exitGame();
  270. }
  271. return ret;
  272. }
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279. int main()
  280. {
  281.  
  282. logo();
  283. startInput();
  284. showMenu();
  285.  
  286.  
  287. return 0;
  288. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement