Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.46 KB | None | 0 0
  1.  
  2. #include <graphics.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <windows.h>
  6. #include <iostream>
  7. #include <cmath>
  8. #include <time.h>
  9. #define SIZE 40
  10.  
  11. DWORD screenWidth = GetSystemMetrics(SM_CXSCREEN);
  12. DWORD screenHeight = GetSystemMetrics(SM_CYSCREEN);
  13.  
  14. const char *sfondo = "Immagini/Sfondo.jpg";
  15. const char *testa = "Immagini/Testa.bmp";
  16. const char *locomotiva = "Immagini/Locomotiva.jpg";
  17. const char *start_btn = "Immagini/Start_btn.jpg";
  18.  
  19. using namespace std;
  20.  
  21. void isEnd();
  22. bool controllo(int xMouse, int yMouse, bool check);
  23. void stampaGriglia(int matrice[SIZE][SIZE]);
  24.  
  25. int main()
  26. {
  27. srand(time(NULL));
  28. initwindow(screenWidth, screenHeight, "", -3, -3);
  29. int xMouse = 0, yMouse = 0, xBuffer = 0, yBuffer = 0, x = 0, y = 0, snake;
  30. bool check = 0;
  31. int griglia[SIZE][SIZE] = {0};
  32. readimagefile(sfondo, 0, 0, 1920, 1080);
  33. //initializeMatrix(griglia);
  34. readimagefile(testa, 0, 0, 320, 320);
  35. while(!check){
  36. xMouse = mousex();
  37. yMouse = mousey();
  38. //cout << xMouse << " " << yMouse << endl;
  39. check = controllo(xMouse, yMouse, check);
  40. }
  41. closegraph();
  42. initwindow(screenWidth, screenHeight, "Snake", -3, -3);
  43. rectangle(0, 0, 25, 25);
  44. int l = 3, posX, posY, tempX, tempY;
  45. posX = rand() % 20 + 10;
  46. posY = rand() % 20 + 10;
  47. griglia[posX][posY] = 2;
  48. griglia[posX-1][posY] = 1;
  49. griglia[posX-2][posY] = 1;
  50. int buffer[25][25];
  51. int W, A, S, D;
  52. while(1){ // game loop
  53. buffer[25][25];
  54. delay(10);
  55. stampaGriglia(griglia);
  56. if(GetKeyState('W') & 0x8000){
  57.  
  58. cout << "bananaW ";
  59. }
  60. if(GetKeyState('A') & 0x8000){
  61. tempX = posX;
  62. tempY = posy;
  63. posX = griglia[posX - 1][posY];
  64. if(griglia[posX][posY] == 0){
  65. griglia[posX][posY] = 1;
  66. for(int i = l; i > 0; i--){
  67. griglia[posX + i - l][posY];
  68. }
  69. }
  70. if(griglia[posX][posY] == -1){ // -1 è il cibo
  71. l++;
  72. //sposti altri pezzi
  73. }
  74. if(posX < 0){
  75. //pop up hai perso
  76. }
  77.  
  78. }
  79. if(GetKeyState('S') & 0x8000){
  80. cout << "bananaS ";
  81. }
  82. if(GetKeyState('D') & 0x8000){
  83. cout << "bananaD ";
  84. }
  85. }
  86.  
  87. getch();
  88. return 0;
  89. }
  90.  
  91.  
  92. void stampaGriglia(int matrice[SIZE][SIZE]){
  93. int i, j;
  94. for(i= 0; i < 40; i++){
  95. for(j = 0; j < 40; j++){
  96. if(matrice[j][i] == 0){
  97. cout << '-';
  98. }else{
  99. cout << matrice[j][i];
  100. }
  101. }
  102. cout << endl;
  103. }
  104. Sleep(1000);
  105. system("cls");
  106. }
  107.  
  108.  
  109. void isEnd(){
  110. exit(0);
  111. }
  112.  
  113. bool controllo(int xMouse, int yMouse, bool check){
  114. //start
  115. if(xMouse > 400 && xMouse < 600 && yMouse > 365 && yMouse < 465){
  116. if(ismouseclick(WM_LBUTTONUP)){
  117. clearmouseclick(WM_LBUTTONUP);
  118. check = 1;
  119. return check;
  120. }
  121. }
  122. // exit
  123. if(ismouseclick(WM_LBUTTONUP) && ((xMouse > 400 && xMouse < 600) && (yMouse > 665 && yMouse < 765)))
  124. {
  125. clearmouseclick(WM_LBUTTONUP);
  126. isEnd();
  127. }
  128. }
  129.  
  130. /*
  131. #include <iostream>
  132. #include <graphics.h>
  133. #include <time.h>
  134.  
  135. using namespace std;
  136.  
  137. int main()
  138. {
  139. initwindow(700,700,"snake");
  140. int cx=400; int cy=200;
  141. int x1[701][701]={0};
  142. int rx,ry,sx;
  143. char ch;
  144.  
  145. srand(time(NULL));
  146.  
  147. rx=rand()%(500-100+1)+100;
  148. ry=rand()%(500-100+1)+100;
  149. x1[rx][ry]=1;
  150.  
  151. setfillstyle(1,15);
  152. circle(rx,ry,2);
  153. floodfill(rx,ry,15);
  154.  
  155. for ( ; ; )
  156. {
  157. delay(10);
  158.  
  159. setcolor(0);
  160. setfillstyle(1,0);
  161. circle(cx-11,cy,10);
  162. floodfill(cx-11,cy,0);
  163. x1[cx-11][cy]=0;
  164. cx++;
  165.  
  166. setcolor(15);
  167. setfillstyle(1,15);
  168. circle(cx-10,cy,10);
  169. floodfill(cx-10,cy,15);
  170. x1[cx-10][cy]=2;
  171. for (int i=1 ; i<=10 ;i++)
  172. {
  173. setcolor(15);
  174. setfillstyle(1,15);
  175. circle(cx-i,cy,10);
  176. floodfill(cx-i,cy,15);
  177. x1[cx-i][cy]=2;
  178. }
  179.  
  180. if (kbhit())
  181. {
  182. for( ; ; )
  183. {
  184. if(kbhit())
  185. {
  186. ch=getch();
  187. }
  188.  
  189. if (ch=='s')
  190. {
  191. cy++;
  192. sx=1;
  193.  
  194. }
  195. else if (ch=='d')
  196. {
  197. cx++;
  198. sx=2;
  199.  
  200. }
  201. else if (ch=='w')
  202. {
  203. cy--;
  204. sx=3;
  205.  
  206. }
  207. else if (ch=='a')
  208. {
  209. cx--;
  210. sx=4;
  211.  
  212. }
  213.  
  214.  
  215.  
  216. if ( sx==1 )
  217. {
  218. delay(10);
  219. setcolor(0);
  220. setfillstyle(1,0);
  221. circle(cx,cy-11,10);
  222. floodfill(cx,cy-11,0);
  223. x1[cx][cy-11]=0;
  224. cy++;
  225.  
  226. setcolor(15);
  227. setfillstyle(1,15);
  228. circle(cx,cy-10,10);
  229. floodfill(cx,cy-10,15);
  230. x1[cx][cy-10]=2;
  231. for (int i=1 ; i<=10 ;i++)
  232. {
  233. setcolor(15);
  234. setfillstyle(1,15);
  235. circle(cx,cy-i,10);
  236. floodfill(cx,cy-i,15);
  237. x1[cx][cy-i]=2;
  238. }
  239. }
  240.  
  241. else if ( sx==2 )
  242. {
  243. delay(10);
  244. setcolor(0);
  245. setfillstyle(1,0);
  246. circle(cx-11,cy,10);
  247. floodfill(cx-11,cy,0);
  248. x1[cx-11][cy]=0;
  249. cx++;
  250.  
  251. setcolor(15);
  252. setfillstyle(1,15);
  253. circle(cx-10,cy,10);
  254. floodfill(cx-10,cy,15);
  255. x1[cx-10][cy]=2;
  256. for (int i=1 ; i<=10 ;i++)
  257. {
  258. setcolor(15);
  259. setfillstyle(1,15);
  260. circle(cx-i,cy,10);
  261. floodfill(cx-i,cy,15);
  262. x1[cx-i][cy]=2;
  263. }
  264. }
  265.  
  266. else if ( sx==3 )
  267. {
  268. delay(10);
  269. setcolor(0);
  270. setfillstyle(1,0);
  271. circle(cx,cy+11,10);
  272. floodfill(cx,cy+11,0);
  273. x1[cx][cy+11]=0;
  274. cy--;
  275.  
  276. setcolor(15);
  277. setfillstyle(1,15);
  278. circle(cx,cy+10,10);
  279. floodfill(cx,cy+10,15);
  280. x1[cx][cy+10]=2;
  281. for (int i=1 ; i<=10 ;i++)
  282. {
  283. setcolor(15);
  284. setfillstyle(1,15);
  285. circle(cx,cy+i,10);
  286. floodfill(cx,cy+i,15);
  287. x1[cx][cy+i]=2;
  288. }
  289. }
  290.  
  291. else if ( sx==4 )
  292. {
  293. delay(10);
  294. setcolor(0);
  295. setfillstyle(1,0);
  296. circle(cx+11,cy,10);
  297. floodfill(cx+11,cy,0);
  298. x1[cx+11][cy]=0;
  299. cx--;
  300.  
  301. setcolor(15);
  302. setfillstyle(1,15);
  303. circle(cx+10,cy,10);
  304. floodfill(cx+10,cy,15);
  305. x1[cx+10][cy]=2;
  306. for (int i=1 ; i<=10 ;i++)
  307. {
  308. setcolor(15);
  309. setfillstyle(1,15);
  310. circle(cx+i,cy,10);
  311. floodfill(cx+i,cy,15);
  312. x1[cx+i][cy]=2;
  313. }
  314. }
  315.  
  316.  
  317.  
  318. }
  319. }
  320. }
  321. getch();
  322. return 0;
  323. }
  324. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement