Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.09 KB | None | 0 0
  1. #include <graphics.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <ctime>
  5. #include <math.h>
  6.  
  7. const int width = 800, height = 600, M = 20;
  8. void Draw_hero(int x_h, int y_h, int color_h, int i_color_h)
  9. {
  10. setcolor(BLACK);
  11. setfillstyle(1, color_h);
  12. ellipse(x_h, y_h, 0, 360, 30, 10);
  13. floodfill(x_h, y_h, BLACK);
  14.  
  15. setfillstyle(1, i_color_h);
  16. ellipse(x_h, y_h - 7, 0, 360, 12, 10);
  17. floodfill(x_h, y_h - 7, BLACK);
  18. floodfill(x_h + 1, y_h - 15 , BLACK);
  19. }
  20.  
  21. void Draw_money(int x_c, int y_c, int color_c, int b_color_c)
  22. {
  23. setcolor(b_color_c);
  24. setfillstyle(1,color_c);
  25. circle(x_c, y_c, 5);
  26. floodfill(x_c, y_c, b_color_c);
  27. }
  28.  
  29. void Draw_button(int x1_b, int y1_b, int x2_b, int y2_b, int color_b)
  30. {
  31. setfillstyle(SOLID_FILL, BLACK);
  32. bar(x1_b-1, y1_b-1, x2_b+1, y2_b+1);
  33. setfillstyle(SOLID_FILL, color_b);
  34. bar(x1_b, y1_b, x2_b, y2_b);
  35. }
  36.  
  37. void Draw_menu_bg(int color_sky, int color_ground)
  38. {
  39. setfillstyle(SOLID_FILL, color_sky);
  40. bar(0, 0, width, height);
  41. setfillstyle(SOLID_FILL, color_ground);
  42. bar(0, 400, width, height);
  43. }
  44.  
  45.  
  46. int main()
  47. {
  48. srand(time(0));
  49. int x_m = 0, y_m = 0, rezhim;
  50. int color_s = BLUE, color_g = GREEN;
  51. int color_ufo = GREEN, i_color_ufo = LIGHTBLUE;
  52. initwindow(width,height, "UFO", 150, 150, true);
  53.  
  54. while(1)
  55. {
  56.  
  57. cleardevice();
  58. Draw_menu_bg(color_s,color_g);
  59. Draw_hero(200, 300, color_ufo, i_color_ufo);
  60. setcolor(YELLOW);
  61. line(190, 310, 150, 500);
  62. line(210, 310, 260, 500);
  63. ellipse(205, 500, 0, 360, 55, 20);
  64.  
  65. Draw_button(500, 25, 750, 175, WHITE);
  66. setcolor(BLACK);
  67. setbkcolor(WHITE);
  68. settextjustify(1,1);
  69. settextstyle(GOTHIC_FONT, 0, 5);
  70. outtextxy(625, 110, "Play");
  71.  
  72. Draw_button(500, 200, 750, 350, WHITE);
  73. setcolor(BLACK);
  74. setbkcolor(WHITE);
  75. settextjustify(1,1);
  76. settextstyle(GOTHIC_FONT, 0, 5);
  77. outtextxy(625, 285, "Auto");
  78.  
  79. Draw_button(522, 425, 722, 550, RED);
  80. setcolor(BLACK);
  81. setlinestyle(SOLID_LINE, 0, THICK_WIDTH);
  82. arc(622, 490, 120, 60,40);
  83. line(622, 440, 622, 480);
  84.  
  85. setbkcolor(BLACK);
  86. swapbuffers();
  87.  
  88. while (!ismouseclick(WM_LBUTTONUP))
  89. {
  90. delay(20);
  91. if(kbhit())
  92. {
  93. if(getch() == 27)
  94. {
  95. return 0;
  96. }
  97. }
  98. }
  99.  
  100. getmouseclick(WM_LBUTTONUP, x_m, y_m);
  101.  
  102. if (x_m > 500 and y_m > 25 and x_m < 750 and y_m < 175)
  103. {
  104. rezhim = 1;
  105. break;
  106. }
  107.  
  108. else if (x_m > 500 and y_m > 200 and x_m < 750 and y_m < 350)
  109. {
  110. rezhim = 2;
  111. break;
  112. }
  113.  
  114. else if (x_m > 522 and y_m > 425 and x_m < 722 and y_m < 550)
  115. {
  116. return 0;
  117. }
  118. else if (x_m > 170 and y_m > 290 and x_m < 240 and y_m < 310)
  119. {
  120. color_ufo = 1 + rand()%16;
  121. i_color_ufo = 1 + rand()%16;
  122.  
  123. }
  124.  
  125. else
  126. {
  127. color_s = 1 + rand()%16;
  128. color_g = 1 + rand()%16;
  129. while(color_s == color_ufo or color_s == i_color_ufo)
  130. {
  131. color_s = 1 + rand()%16;
  132. }
  133. while(color_s == color_g or color_g == 14 or color_g == color_ufo or color_g == i_color_ufo)
  134. {
  135. color_g = rand()%16;
  136. }
  137. }
  138.  
  139.  
  140. }
  141.  
  142.  
  143. setbkcolor(color_g);
  144. setlinestyle(SOLID_LINE, 0, 1);
  145.  
  146. int x_h = width/2, y_h = height/2, color_h = 2, i_color_h = 1, harv = 0;
  147. int min = 700, p, x_coin, y_coin, sravn, poisk = 1;
  148. int x_c[M], y_c[M], color_c = YELLOW, b_color_c = BLACK, c_time = 0, i = 0, kol_vo = 0;
  149. for (i = 0; i < M; i++)
  150. {
  151. x_c[i] = -500;
  152. y_c[i] = -500;
  153. }
  154.  
  155. while(1)
  156. {
  157. cleardevice();
  158.  
  159. setcolor(color_s);
  160. moveto(0, 500);
  161. lineto(width,500);
  162.  
  163. Draw_hero(50, 550, color_ufo, i_color_ufo);
  164.  
  165. setcolor(color_s);
  166. moveto(100,500);
  167. lineto(100, height);
  168.  
  169.  
  170. Draw_hero(x_h, y_h, color_ufo, i_color_ufo);
  171.  
  172. switch(rezhim)
  173. {
  174. case 1:
  175. {
  176.  
  177. if (kbhit())
  178. {
  179. switch(getch())
  180. {
  181. case 'w':
  182. {
  183. if(y_h > 30)
  184. {
  185. y_h-=2;
  186. }
  187. break;
  188. }
  189.  
  190. case 's':
  191. {
  192. if (y_h < 480)
  193. {
  194. y_h+=2;
  195.  
  196. }
  197.  
  198. break;
  199.  
  200. }
  201.  
  202.  
  203.  
  204. case 'd':
  205. {
  206. if (x_h < width - 30)
  207. {
  208. x_h+=2;
  209. }
  210. break;
  211. }
  212.  
  213. case 'a':
  214. {
  215. if (x_h > 30)
  216. {
  217. x_h -= 2;
  218. }
  219. break;
  220. }
  221. case VK_ESCAPE:
  222. {
  223. return 0;
  224. }
  225.  
  226. }
  227.  
  228. for(int p = 0; p < M; p++)
  229. {
  230.  
  231. if(40 >= sqrt((pow((x_h - x_c[p]), 2)) + pow((y_h - y_c[p]), 2)))
  232. {
  233. kol_vo--;
  234. x_c[p] = 0;
  235. y_c[p] = 0;
  236. i = p;
  237. harv++;
  238.  
  239. }
  240. }
  241.  
  242. }
  243. break;
  244. }
  245. case 2:
  246. {
  247. if(kol_vo >= 1)
  248. {
  249. if(poisk == 1)
  250. {
  251. for(p = 0; p < M; p++)
  252. {
  253. sravn = sqrt((pow((x_h - x_c[p]), 2)) + pow((y_h - y_c[p]), 2));
  254. if(min >= sravn)
  255. {
  256. min = sravn;
  257. x_coin = x_c[p];
  258.  
  259. y_coin = y_c[p];
  260.  
  261. }
  262.  
  263. }
  264. poisk = 0;
  265. }
  266.  
  267.  
  268.  
  269. if (40 < sqrt((pow((x_h - x_coin), 2)) + pow((y_h - y_coin), 2)))
  270. {
  271. if(x_coin > x_h and x_h < width -30)
  272. {
  273. x_h += 2;
  274. }
  275. if (x_coin < x_h and x_h > 30)
  276. {
  277. x_h -= 2;
  278. }
  279. if (y_coin > y_h and y_h < 550 )
  280. {
  281. y_h += 2;
  282. }
  283. if (y_coin < y_h and y_h > 30 )
  284. {
  285. y_h -= 2;
  286. }
  287. for(p = 0; p < M; p++)
  288. {
  289.  
  290. if(40 >= sqrt((pow((x_h - x_c[p]), 2)) + pow((y_h - y_c[p]), 2)))
  291. {
  292.  
  293.  
  294. kol_vo--;
  295. x_c[p] = -500;
  296. y_c[p] = -500;
  297. i = p;
  298. harv++;
  299.  
  300. poisk = 1;
  301. min = 700;
  302. }
  303. }
  304. }
  305. }
  306. break;
  307. }
  308. }
  309. delay(2);
  310.  
  311. if (harv >= 20)
  312. {
  313. break;
  314. }
  315.  
  316.  
  317.  
  318. if (c_time == 50)
  319. {
  320. c_time = 0;
  321.  
  322. if (kol_vo < M and x_c[i] == -500 and y_c[i] == -500)
  323. {
  324. x_c[i] = 10 + (rand() % 780);
  325. y_c[i] = 10 + (rand() % 480);
  326.  
  327. while (40 >= sqrt((pow((x_h - x_c[i]), 2)) + pow((y_h - y_c[i]), 2)))
  328. {
  329.  
  330. x_c[i] = 10 + (rand() % 780);
  331. y_c[i] = 10 + (rand() % 480);
  332. }
  333.  
  334. kol_vo++;
  335. }
  336.  
  337. for (i = 0; i <= M; i++)
  338. {
  339. if (x_c[i] == -500 and y_c[i] == -500)
  340. {
  341. break;
  342. }
  343. }
  344. }
  345. for(int i = 0; i < M; i++)
  346. {
  347. if(x_c[i] != -500 and y_c[i] != -500)
  348. {
  349. Draw_money(x_c[i], y_c[i], color_c, b_color_c);
  350. }
  351.  
  352. }
  353. for (int i = 0; i < harv; i++ )
  354. {
  355. Draw_money(200 + i * 10, 550, color_c, b_color_c);
  356. }
  357. c_time++;
  358. swapbuffers();
  359. }
  360.  
  361.  
  362. cleardevice();
  363. setcolor(BLACK);
  364. settextjustify(1,1);
  365.  
  366. if (rezhim == 1)
  367. {
  368. settextstyle(TRIPLEX_FONT, 0, 6);
  369. outtextxy(width/2,height/2, "Well! You can win.");
  370. }
  371. else
  372. {
  373. settextstyle(TRIPLEX_FONT, 0, 4);
  374. outtextxy(width/2,height/2, "Razrab krasava, a Tbl lenivec.");
  375. }
  376. swapbuffers();
  377. delay(2000);
  378.  
  379. getch();
  380. closegraph();
  381.  
  382. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement