Advertisement
Guest User

car

a guest
Oct 13th, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. #include<iostream>
  2. #include<graphics.h>
  3.  
  4. int car(int x, int c)
  5. {
  6. setcolor(c);
  7. line(x + 150, 100, x + 242, 100);
  8. ellipse(x + 242, 105, 0, 90, 10, 5);
  9. line(x + 150, 100, x + 120, 150);
  10. line(x + 252, 105, x + 280, 150);
  11. line(x + 100, 150, x + 320, 150);
  12. line(x + 100, 150, x + 100, 200);
  13. line(x + 320, 150, x + 320, 200);
  14. line(x + 100, 200, x + 110, 200);
  15.  
  16. void car(int x, int c)
  17. {
  18. setcolor(c);
  19. line(x + 150, 100, x + 242, 100);
  20. ellipse(x + 242, 105, 0, 90, 10, 5);
  21. line(x + 150, 100, x + 120, 150);
  22. line(x + 252, 105, x + 280, 150);
  23. line(x + 100, 150, x + 320, 150);
  24. line(x + 100, 150, x + 100, 200);
  25. line(x + 320, 150, x + 320, 200);
  26. line(x + 100, 200, x + 110, 200);
  27. line(x + 320, 200, x + 310, 200);
  28. arc(x + 130, 200, 0, 180, 20);
  29. arc(x + 290, 200, 0, 180, 20);
  30. line(x + 270, 200, x + 150, 200);
  31. circle(x + 130, 200, 17);
  32. circle(x + 290, 200, 17);
  33.  
  34. }
  35.  
  36.  
  37. void main()
  38. {
  39. int gd = DETECT, gm = DETECT, i = -200;
  40. int ch = 'g';
  41. initgraph(&gd, &gm, "");
  42.  
  43. line(0, 70, 300, 70);
  44. line(450, 70, 630, 70);
  45. line(300, 70, 300, 0);
  46. line(450, 70, 450, 0);
  47. line(0, 230, 300, 230);
  48. line(450, 230, 630, 230);
  49. line(300, 230, 300, 500);
  50. line(450, 230, 450, 500);
  51. circle(280, 50, 10);
  52. setfillstyle(SOLID_FILL, GREEN);
  53. floodfill(280, 50, 15);
  54. car(i, 15);
  55. while (1) {
  56. while (!kbhit()) {
  57. //Press 'r' to turn it to red
  58. if (ch == 'r') {
  59. setfillstyle(SOLID_FILL, RED);
  60. floodfill(280, 50, 15);
  61. do {
  62. while (!kbhit()) {
  63. if (i < -20 || i > -10) {
  64. car(i++, 0);
  65. car(i, 15);
  66. delay(50);
  67. }
  68. }
  69. ch = getch();
  70. //Press 'y' to turn it to yellow
  71. if (ch == 'y') {
  72. setfillstyle(SOLID_FILL, YELLOW);
  73. floodfill(280, 50, 15);
  74. }
  75. //Press 'g' to turn it to red
  76. if (ch == 'g') {
  77. setfillstyle(SOLID_FILL, GREEN);
  78. floodfill(280, 50, 15);
  79. }
  80. } while (ch != 'g' && ch != 13);
  81. } else {
  82. car(i++, 0);
  83. car(i, 15);
  84. delay(50);
  85. }
  86. }
  87. ch = getch();
  88. if (ch == 13)
  89. break;
  90. }
  91.  
  92.  
  93. getch();
  94. }
  95. line(x + 320, 200, x + 310, 200);
  96. arc(x + 130, 200, 0, 180, 20);
  97. arc(x + 290, 200, 0, 180, 20);
  98. line(x + 270, 200, x + 150, 200);
  99. circle(x + 130, 200, 17);
  100. circle(x + 290, 200, 17);
  101.  
  102. }
  103.  
  104.  
  105. void main()
  106. {
  107. int gd = DETECT, gm = DETECT, i = -200;
  108. int ch = 'g';
  109. initgraph(&gd, &gm, "");
  110.  
  111. line(0, 70, 300, 70);
  112. line(450, 70, 630, 70);
  113. line(300, 70, 300, 0);
  114. line(450, 70, 450, 0);
  115. line(0, 230, 300, 230);
  116. line(450, 230, 630, 230);
  117. line(300, 230, 300, 500);
  118. line(450, 230, 450, 500);
  119. circle(280, 50, 10);
  120. setfillstyle(SOLID_FILL, GREEN);
  121. floodfill(280, 50, 15);
  122. car(i, 15);
  123. while (1) {
  124. while (!kbhit()) {
  125. //Press 'r' to turn it to red
  126. if (ch == 'r') {
  127. setfillstyle(SOLID_FILL, RED);
  128. floodfill(280, 50, 15);
  129. do {
  130. while (!kbhit()) {
  131. if (i < -20 || i > -10) {
  132. car(i++, 0);
  133. car(i, 15);
  134. delay(50);
  135. }
  136. }
  137. ch = getch();
  138. //Press 'y' to turn it to yellow
  139. if (ch == 'y') {
  140. setfillstyle(SOLID_FILL, YELLOW);
  141. floodfill(280, 50, 15);
  142. }
  143. //Press 'g' to turn it to red
  144. if (ch == 'g') {
  145. setfillstyle(SOLID_FILL, GREEN);
  146. floodfill(280, 50, 15);
  147. }
  148. } while (ch != 'g' && ch != 13);
  149. } else {
  150. car(i++, 0);
  151. car(i, 15);
  152. delay(50);
  153. }
  154. }
  155. ch = getch();
  156. if (ch == 13)
  157. break;
  158. }
  159.  
  160.  
  161. getch();
  162. return 0;
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement