Advertisement
HoangAnh_GaToVi

Racing Game xD

Sep 4th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.70 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<ctype.h>
  3. #include<conio.h>
  4. #include<stdlib.h>
  5. #include<dos.h>
  6. void lines()
  7. {
  8. textbackground(1);
  9. clrscr();
  10. textcolor(11);
  11. window(19,1,51,24);
  12. for(int x=0;x<24;x++)
  13. cprintf("³ ³ ");
  14. cprintf("³ ³");
  15. window(55,6,77,19);
  16. cprintf(" Instructions \n");
  17. cprintf("Press Left and Right ");
  18. cprintf("arrow keys to turn/move\n");
  19. cprintf("Press P to Pause \n");
  20. cprintf("Press X to exit");
  21. window(55,18,79,20);
  22. cprintf("SCORE 10000");
  23. window(55,20,79,24);
  24. cprintf("GAME OVER");
  25. }
  26. int strt[3],dwn[3],end[3];
  27. int cars[3],go=0,speed;
  28. void score(int s=1)
  29. {
  30. static unsigned int scr=0;
  31. if (s==0)
  32. {
  33. scr=0;
  34. return;
  35. }
  36. textcolor(WHITE);
  37. window(61,18,70,23);
  38. cprintf(" ");
  39. window(61,18,70,23);
  40. cprintf("%d",++scr);
  41. textcolor(11);
  42. for (int x=1;x<=10;x++)
  43. if(scr>=x*100 && speed>20)
  44. speed--;
  45.  
  46. }
  47. void status(int s)
  48. {
  49. textcolor(WHITE);
  50. window(55,20,65,21);
  51. switch(s)
  52. {
  53. case 1 : cprintf("Playing..."); break;
  54. case 2 : cprintf("Paused "); break;
  55. case 3 : cprintf("Game Over ");
  56. }
  57. textcolor(11);
  58. }
  59. void myc(int x)
  60. {
  61. int i;
  62. textcolor(10);
  63. window(20+(x*10),21,29+(x*10),25);
  64. cprintf(" ²²²²²² ");
  65. cprintf("Þ²²²²²²²²Ý");
  66. cprintf(" ²²Ý²²Þ²² ");
  67. cprintf("Þ²²Ý²²Þ²²Ý");
  68. textcolor(WHITE);
  69. delay(10);
  70. if (x==0 || x==2)
  71. {
  72. x=1;
  73. window(20+(x*10),21,29+(x*10),25);
  74. for(i=0;i<4;i++)
  75. cprintf(" ");
  76. }
  77. else
  78. {
  79. x=0;
  80. window(20+(x*10),21,29+(x*10),25);
  81. for(i=0;i<4;i++)
  82. cprintf(" ");
  83. x=2;
  84. window(20+(x*10),21,29+(x*10),25);
  85. for(i=0;i<4;i++)
  86. cprintf(" ");
  87. }
  88.  
  89. }
  90. void dc(int x, int car)
  91. {
  92.  
  93. if(strt[x]==25)
  94. {
  95. strt[x]=1;
  96. dwn[x]=1;
  97. end[x]=1;
  98. }
  99. if(strt[x]<10)
  100. window(20+(x*10),1,29+(x*10),5);
  101.  
  102. textcolor(12);
  103. if(end[x]>0)
  104. {
  105. window(20+(x*10),end[x]+20,29+(x*10),25);
  106. if(end[x]==1){
  107. cprintf(" ");
  108. cprintf("Þ²²²²²²²²Ý");
  109. cprintf(" ²²²²²²²² ");
  110. cprintf("Þ²²²²²²²²Ý");
  111. }
  112. else if(end[x]==2)
  113. {
  114. cprintf(" ");
  115. cprintf("Þ²²²²²²²²Ý");
  116. cprintf(" ²²²²²²²² ");
  117. }
  118. else if(end[x]==3)
  119. {
  120. cprintf(" ");
  121. cprintf("Þ²²²²²²²²Ý");
  122. }
  123. else
  124. {
  125. cprintf(" ");
  126. end[x]=-1;
  127. strt[x]=0;
  128. cars[x]=0;
  129. }
  130. end[x]++;
  131. }
  132. else
  133. if(strt[x]>=5)
  134. {
  135. window(20+(x*10),dwn[x],29+(x*10),dwn[x]+5);
  136. cprintf(" ");
  137. cprintf("Þ²²²²²²²²Ý");
  138. cprintf(" ²²²²²²²² ");
  139. cprintf("Þ²²²²²²²²Ý");
  140. cprintf(" ²²²²²² ");
  141. dwn[x]++;
  142. }
  143. else if(strt[x]==1)
  144. cprintf(" ²²²²²² ");
  145. else if(strt[x]==2)
  146. {
  147. cprintf("Þ²²²²²²²²Ý");
  148. cprintf(" ²²²²²² ");
  149. } else if(strt[x]==3)
  150. {
  151. cprintf(" ²²²²²²²² ");
  152. cprintf("Þ²²²²²²²²Ý");
  153. cprintf(" ²²²²²² ");
  154. }else if(strt[x]==4)
  155. {
  156. cprintf("Þ²²²²²²²²Ý");
  157. cprintf(" ²²²²²²²² ");
  158. cprintf("Þ²²²²²²²²Ý");
  159. cprintf(" ²²²²²² ");
  160. }
  161. strt[x]++;
  162. if(strt[x]==21 && x==car)
  163. {
  164. status(3);
  165. speed=30;
  166. score(0);
  167. sound(60);
  168. delay(110);
  169. nosound();
  170. sound(80);
  171. delay(150);
  172. nosound();
  173. sound(120);
  174. delay(210);
  175. nosound();
  176. go=1;
  177. getch();
  178. }
  179. textcolor(YELLOW);
  180. //
  181. }
  182. void main()
  183. {
  184. clrscr();
  185. randomize();
  186. _setcursortype(_NOCURSOR);
  187. char c,ch;
  188. int i,x;
  189. while(1){
  190. for(x=0;x<3;x++)
  191. {
  192. strt[x]=1;
  193. dwn[x]=1;
  194. end[x]=0;
  195. cars[x]=0;
  196. }
  197. lines();
  198. status(1);
  199. speed=30; // 30-20
  200. x=1;
  201. myc(x);
  202. go=0;
  203. while(!go)
  204. {
  205. while(!kbhit())
  206. {
  207.  
  208. if(random(speed)==5 && cars[0]==0 && (cars[1]==0 || cars[2]==0))
  209. cars[0]=1;
  210. else if(random(speed)==5 && cars[1]==0 && (cars[0]==0 || cars[2]==0))
  211. cars[1]=1;
  212. else if(random(speed)==5 && cars[2]==0 && (cars[1]==0 || cars[0]==0))
  213. cars[2]=1;
  214. for(i=0;i<3;i++)
  215. if(cars[i]!=0)
  216. dc(i,x);
  217.  
  218. sound(100);
  219. delay(speed*2);
  220. nosound();
  221. score();
  222. }
  223. c=getch();
  224. switch(tolower(c))
  225. {
  226. case 'p' : status(2);
  227. sound(1500);
  228. delay(210);
  229. nosound();
  230. sound(350);
  231. delay(150);
  232. nosound();
  233. sound(1000);
  234. delay(300);
  235. nosound();
  236. getch();
  237. status(1);
  238. break;
  239. case 0 : ch=getch();
  240. if(ch==75 && x>0)
  241. {
  242. x--;
  243. myc(x);
  244. sound(1200);
  245. delay(20);
  246. }
  247. else if(ch==77 && x<2)
  248. {
  249. x++;
  250. myc(x);
  251. sound(1200);
  252. delay(20);
  253. }
  254. break;
  255. case 'x': return;
  256. }
  257. }
  258. }//outer while
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement