Advertisement
Guest User

rgr13

a guest
Dec 15th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <iostream>
  4. #include <graphics.h>
  5. #include <math.h>
  6. #include <time.h>
  7.  
  8. void Face(){
  9. moveto(0,0);
  10. initwindow(800,800);
  11. setcolor(15);
  12. rectangle (50, 50, 750, 750);
  13.  
  14. }
  15.  
  16.  
  17. int Fi(int x,int y, int color) {
  18. setfillstyle (1,4);
  19. setcolor(color);
  20. line(x-25,y-10,x+20,y-10);
  21. line(x-25,y+10,x+20,y+10);
  22. line(x-25,y-10,x-25,y+10);
  23. line(x+20,y-10,x+35,y);
  24. line(x+20,y+10,x+35,y);
  25. line(x-25,y-10,x-35,y-25);
  26. line(x-25,y+10,x-35,y+25);
  27. line(x,y-10,x-35,y-25);
  28. line(x,y+10,x-35,y+25);
  29.  
  30.  
  31. circle(x+5,y,5);
  32. }
  33.  
  34.  
  35.  
  36. int KeyMoving(int x,int y,int xOld, int yOld, int color) {
  37. int code;
  38. Face();
  39. outtextxy (0,0,"E-up D-rigth");
  40. outtextxy (0,20,"S-left X-down");
  41.  
  42. while(1){
  43.  
  44. Fi(xOld,yOld,0);
  45. Fi(x,y,color);
  46. delay(1);
  47.  
  48. if (kbhit()) {
  49. code=getch();
  50. switch(code) {
  51. case 75: {xOld=x; yOld=y; x-=5;}; break; // âëåâî S
  52. case 77: {xOld=x; yOld=y; x+=5;}; break; // âïðàâî D
  53. case 72: {yOld=y; xOld=x; y-=5;}; break; // ââåðõ E
  54. case 80: {yOld=y; xOld=x; y+=5;}; break; // âíèç X
  55. case 27: closegraph(); return 0;
  56. }
  57.  
  58. }
  59.  
  60. if ((x>=715)||(x<=85)||(y>=725)||(y<=75))
  61. while(1)
  62. {
  63. delay(1);
  64. if(kbhit())
  65. if(getch()==27)
  66. {
  67. closegraph();
  68. return 0;
  69. }
  70. }
  71.  
  72. }
  73. }
  74.  
  75.  
  76. int FreeMoving(int x, int y, int xOld, int yOld, int color) {
  77.  
  78. Face();
  79. int code=0;
  80.  
  81. while(1) {
  82.  
  83. while( (x<715) && (y<725) ) {
  84.  
  85. delay(1);
  86. xOld=x; x+=1;
  87. yOld=y; y+=1;
  88. Fi(xOld,yOld,0);
  89. Fi(x,y,color);
  90.  
  91. if(kbhit()){
  92. code=getch();
  93. if(code==27) {
  94. closegraph();
  95. return 0;
  96. }
  97. }
  98.  
  99. }
  100. while( (x!=400) && (y!=400) ) {
  101.  
  102. delay(1);
  103. xOld=x; x-=1;
  104. yOld=y; y-=1;
  105. Fi(xOld,yOld,0);
  106. Fi(x,y,color);
  107.  
  108. if(kbhit()){
  109. code=getch();
  110. if(code==27) {
  111. closegraph();
  112. return 0;
  113. }
  114. }
  115.  
  116. }
  117. while( (x<715) && (y>75) ) {
  118.  
  119. delay(1);
  120. xOld=x; x+=1;
  121. yOld=y; y-=1;
  122. Fi(xOld,yOld,0);
  123. Fi(x,y,color);
  124.  
  125. if(kbhit()){
  126. code=getch();
  127. if(code==27) {
  128. closegraph();
  129. return 0;
  130. }
  131. }
  132.  
  133. }
  134. while( (x!=400) && (y!=400) ) {
  135.  
  136. delay(1);
  137. xOld=x; x-=1;
  138. yOld=y; y+=1;
  139. Fi(xOld,yOld,0);
  140. Fi(x,y,color);
  141.  
  142. if(kbhit()){
  143. code=getch();
  144. if(code==27) {
  145. closegraph();
  146. return 0;
  147. }
  148. }
  149.  
  150. }
  151. while( (x>85) && (y>75) ) {
  152.  
  153. delay(1);
  154. xOld=x; x-=1;
  155. yOld=y; y-=1;
  156. Fi(xOld,yOld,0);
  157. Fi(x,y,color);
  158.  
  159. if(kbhit()){
  160. code=getch();
  161. if(code==27) {
  162. closegraph();
  163. return 0;
  164. }
  165. }
  166.  
  167. }
  168. while( (x!=400) && (y!=400) ) {
  169.  
  170. delay(1);
  171. xOld=x; x+=1;
  172. yOld=y; y+=1;
  173. Fi(xOld,yOld,0);
  174. Fi(x,y,color);
  175.  
  176. if(kbhit()){
  177. code=getch();
  178. if(code==27) {
  179. closegraph();
  180. return 0;
  181. }
  182. }
  183.  
  184. }
  185. while( (x>85) && (y<725) ) {
  186.  
  187. delay(1);
  188. xOld=x; x-=1;
  189. yOld=y; y+=1;
  190. Fi(xOld,yOld,0);
  191. Fi(x,y,color);
  192.  
  193. if(kbhit()){
  194. code=getch();
  195. if(code==27) {
  196. closegraph();
  197. return 0;
  198. }
  199. }
  200.  
  201. }
  202. while( (x!=400) && (y!=400) ) {
  203.  
  204. delay(1);
  205. xOld=x; x+=1;
  206. yOld=y; y-=1;
  207. Fi(xOld,yOld,0);
  208. Fi(x,y,color);
  209.  
  210. if(kbhit()){
  211. code=getch();
  212. if(code==27) {
  213. closegraph();
  214. return 0;
  215. }
  216. }
  217.  
  218. }
  219. }
  220.  
  221. }
  222.  
  223. int main()
  224. {
  225. printf("Hello\n");
  226. srand(time(NULL));
  227.  
  228. int x=400,y=400;
  229. int xOld=400,yOld=400;
  230. int color=2,code,num;
  231.  
  232. printf("Press number for choice \n1. Free Move\n2. Key Move\n3. Exit\n\n\n");
  233. while(1){
  234.  
  235. check:
  236.  
  237. scanf("%d",&num);
  238.  
  239. switch(num) {
  240.  
  241. case 1: FreeMoving(x,y,xOld,yOld,color); break;
  242. case 2: KeyMoving(x,y,xOld,yOld,color); break;
  243. case 3: system("CLS"); return 0;
  244. default: printf("Error!\nRepeat:\n"); goto check;
  245. }
  246. printf("Lets go again?\n");
  247. }
  248. getch();
  249. closegraph();
  250. system("PAUSE");
  251. return 0;
  252. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement