Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <graphics.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <ctime>
- #include <math.h>
- const int width = 800, height = 600, M = 20;
- void Draw_hero(int x_h, int y_h, int color_h, int i_color_h)
- {
- setcolor(BLACK);
- setfillstyle(1, color_h);
- ellipse(x_h, y_h, 0, 360, 30, 10);
- floodfill(x_h, y_h, BLACK);
- setfillstyle(1, i_color_h);
- ellipse(x_h, y_h - 7, 0, 360, 12, 10);
- floodfill(x_h, y_h - 7, BLACK);
- floodfill(x_h + 1, y_h - 15 , BLACK);
- }
- void Draw_money(int x_c, int y_c, int color_c, int b_color_c)
- {
- setcolor(b_color_c);
- setfillstyle(1,color_c);
- circle(x_c, y_c, 5);
- floodfill(x_c, y_c, b_color_c);
- }
- void Draw_button(int x1_b, int y1_b, int x2_b, int y2_b, int color_b)
- {
- setfillstyle(SOLID_FILL, BLACK);
- bar(x1_b-1, y1_b-1, x2_b+1, y2_b+1);
- setfillstyle(SOLID_FILL, color_b);
- bar(x1_b, y1_b, x2_b, y2_b);
- }
- void Draw_menu_bg(int color_sky, int color_ground)
- {
- setfillstyle(SOLID_FILL, color_sky);
- bar(0, 0, width, height);
- setfillstyle(SOLID_FILL, color_ground);
- bar(0, 400, width, height);
- }
- int main()
- {
- srand(time(0));
- int x_m = 0, y_m = 0, rezhim;
- int color_s = BLUE, color_g = GREEN;
- int color_ufo = GREEN, i_color_ufo = LIGHTBLUE;
- initwindow(width,height, "UFO", 150, 150, true);
- while(1)
- {
- cleardevice();
- Draw_menu_bg(color_s,color_g);
- Draw_hero(200, 300, color_ufo, i_color_ufo);
- setcolor(YELLOW);
- line(190, 310, 150, 500);
- line(210, 310, 260, 500);
- ellipse(205, 500, 0, 360, 55, 20);
- Draw_button(500, 25, 750, 175, WHITE);
- setcolor(BLACK);
- setbkcolor(WHITE);
- settextjustify(1,1);
- settextstyle(GOTHIC_FONT, 0, 5);
- outtextxy(625, 110, "Play");
- Draw_button(500, 200, 750, 350, WHITE);
- setcolor(BLACK);
- setbkcolor(WHITE);
- settextjustify(1,1);
- settextstyle(GOTHIC_FONT, 0, 5);
- outtextxy(625, 285, "Auto");
- Draw_button(522, 425, 722, 550, RED);
- setcolor(BLACK);
- setlinestyle(SOLID_LINE, 0, THICK_WIDTH);
- arc(622, 490, 120, 60,40);
- line(622, 440, 622, 480);
- setbkcolor(BLACK);
- swapbuffers();
- while (!ismouseclick(WM_LBUTTONUP))
- {
- delay(20);
- if(kbhit())
- {
- if(getch() == 27)
- {
- return 0;
- }
- }
- }
- getmouseclick(WM_LBUTTONUP, x_m, y_m);
- if (x_m > 500 and y_m > 25 and x_m < 750 and y_m < 175)
- {
- rezhim = 1;
- break;
- }
- else if (x_m > 500 and y_m > 200 and x_m < 750 and y_m < 350)
- {
- rezhim = 2;
- break;
- }
- else if (x_m > 522 and y_m > 425 and x_m < 722 and y_m < 550)
- {
- return 0;
- }
- else if (x_m > 170 and y_m > 290 and x_m < 240 and y_m < 310)
- {
- color_ufo = 1 + rand()%16;
- i_color_ufo = 1 + rand()%16;
- }
- else
- {
- color_s = 1 + rand()%16;
- color_g = 1 + rand()%16;
- while(color_s == color_ufo or color_s == i_color_ufo)
- {
- color_s = 1 + rand()%16;
- }
- while(color_s == color_g or color_g == 14 or color_g == color_ufo or color_g == i_color_ufo)
- {
- color_g = rand()%16;
- }
- }
- }
- setbkcolor(color_g);
- setlinestyle(SOLID_LINE, 0, 1);
- int x_h = width/2, y_h = height/2, color_h = 2, i_color_h = 1, harv = 0;
- int min = 700, p, x_coin, y_coin, sravn, poisk = 1;
- int x_c[M], y_c[M], color_c = YELLOW, b_color_c = BLACK, c_time = 0, i = 0, kol_vo = 0;
- for (i = 0; i < M; i++)
- {
- x_c[i] = -500;
- y_c[i] = -500;
- }
- while(1)
- {
- cleardevice();
- setcolor(color_s);
- moveto(0, 500);
- lineto(width,500);
- Draw_hero(50, 550, color_ufo, i_color_ufo);
- setcolor(color_s);
- moveto(100,500);
- lineto(100, height);
- Draw_hero(x_h, y_h, color_ufo, i_color_ufo);
- switch(rezhim)
- {
- case 1:
- {
- if (kbhit())
- {
- switch(getch())
- {
- case 'w':
- {
- if(y_h > 30)
- {
- y_h-=2;
- }
- break;
- }
- case 's':
- {
- if (y_h < 480)
- {
- y_h+=2;
- }
- break;
- }
- case 'd':
- {
- if (x_h < width - 30)
- {
- x_h+=2;
- }
- break;
- }
- case 'a':
- {
- if (x_h > 30)
- {
- x_h -= 2;
- }
- break;
- }
- case VK_ESCAPE:
- {
- return 0;
- }
- }
- for(int p = 0; p < M; p++)
- {
- if(40 >= sqrt((pow((x_h - x_c[p]), 2)) + pow((y_h - y_c[p]), 2)))
- {
- kol_vo--;
- x_c[p] = 0;
- y_c[p] = 0;
- i = p;
- harv++;
- }
- }
- }
- break;
- }
- case 2:
- {
- if(kol_vo >= 1)
- {
- if(poisk == 1)
- {
- for(p = 0; p < M; p++)
- {
- sravn = sqrt((pow((x_h - x_c[p]), 2)) + pow((y_h - y_c[p]), 2));
- if(min >= sravn)
- {
- min = sravn;
- x_coin = x_c[p];
- y_coin = y_c[p];
- }
- }
- poisk = 0;
- }
- if (40 < sqrt((pow((x_h - x_coin), 2)) + pow((y_h - y_coin), 2)))
- {
- if(x_coin > x_h and x_h < width -30)
- {
- x_h += 2;
- }
- if (x_coin < x_h and x_h > 30)
- {
- x_h -= 2;
- }
- if (y_coin > y_h and y_h < 550 )
- {
- y_h += 2;
- }
- if (y_coin < y_h and y_h > 30 )
- {
- y_h -= 2;
- }
- for(p = 0; p < M; p++)
- {
- if(40 >= sqrt((pow((x_h - x_c[p]), 2)) + pow((y_h - y_c[p]), 2)))
- {
- kol_vo--;
- x_c[p] = -500;
- y_c[p] = -500;
- i = p;
- harv++;
- poisk = 1;
- min = 700;
- }
- }
- }
- }
- break;
- }
- }
- delay(2);
- if (harv >= 20)
- {
- break;
- }
- if (c_time == 50)
- {
- c_time = 0;
- if (kol_vo < M and x_c[i] == -500 and y_c[i] == -500)
- {
- x_c[i] = 10 + (rand() % 780);
- y_c[i] = 10 + (rand() % 480);
- while (40 >= sqrt((pow((x_h - x_c[i]), 2)) + pow((y_h - y_c[i]), 2)))
- {
- x_c[i] = 10 + (rand() % 780);
- y_c[i] = 10 + (rand() % 480);
- }
- kol_vo++;
- }
- for (i = 0; i <= M; i++)
- {
- if (x_c[i] == -500 and y_c[i] == -500)
- {
- break;
- }
- }
- }
- for(int i = 0; i < M; i++)
- {
- if(x_c[i] != -500 and y_c[i] != -500)
- {
- Draw_money(x_c[i], y_c[i], color_c, b_color_c);
- }
- }
- for (int i = 0; i < harv; i++ )
- {
- Draw_money(200 + i * 10, 550, color_c, b_color_c);
- }
- c_time++;
- swapbuffers();
- }
- cleardevice();
- setcolor(BLACK);
- settextjustify(1,1);
- if (rezhim == 1)
- {
- settextstyle(TRIPLEX_FONT, 0, 6);
- outtextxy(width/2,height/2, "Well! You can win.");
- }
- else
- {
- settextstyle(TRIPLEX_FONT, 0, 4);
- outtextxy(width/2,height/2, "Razrab krasava, a Tbl lenivec.");
- }
- swapbuffers();
- delay(2000);
- getch();
- closegraph();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement