Guest User

Untitled

a guest
Jul 16th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.19 KB | None | 0 0
  1. /* Vanna Quon
  2. ENGR101: Section 305
  3. Date: 3.28.12
  4. Project 6.1
  5. GSI: Jeff
  6. hwk6.cpp
  7. */
  8.  
  9. #include <iostream>
  10. using namespace std;
  11.  
  12. const int NROWS = 52;
  13. const int NCOLS = 72;
  14.  
  15. void printrace(const char a[][NCOLS])
  16. {
  17. for (int i = 0; i < NROWS; i++)
  18. {
  19. for (int j = 0; j < NCOLS; j++)
  20. {
  21. cout << a[i][j];
  22. }
  23. cout << endl;
  24. }
  25. return;
  26. }
  27.  
  28. void initrace(char b[][NCOLS])
  29. {
  30.  
  31. for (int i = 0; i < NROWS; i++)
  32. {
  33. for (int j = 0; j < NCOLS; j++)
  34. {
  35. b[1][1] = 'O'; //car
  36. if(j==0) b[i][j] = 'X'; //first left column
  37. else if(j==71) b[i][j] = 'X'; // last right column
  38. else if ((j>=10 && j<=29)&& (i >=0 && i <=34)) b[i][j] = 'X'; //first block
  39. else if ((j>=40 && j<=64)&& (i >=18 && i <=51)) b[i][j] = 'X'; //second block
  40. else if ((i==0)&& j<=(NCOLS-1)) b[i][j] = 'X'; //top row
  41. else if ((i==(NROWS-1))&&(j>=0 && j<=40)) b[i][j] = 'X'; //bottom row
  42. else if ((i==(NROWS-1))&&(j>=55 && j<=(NCOLS-2))) b[i][j] = 'F'; //finish line
  43. else b[i][j] = ' ';
  44. }
  45. }
  46.  
  47. return;
  48. }
  49.  
  50. int main(void)
  51. {
  52. //initrace sets up the grid
  53. //print race prints out the grid
  54.  
  55.  
  56. char grid[NROWS][NCOLS];
  57.  
  58.  
  59. //grid[1][1] = 'O';
  60. //printrace(grid);
  61. //initrace(grid);
  62.  
  63. int xAcceleration = 0;
  64. int yAcceleration = 0;
  65. bool ask = true;
  66.  
  67. //int scoretime = 0;
  68. //int currentPlayer = 1;
  69. initrace(grid);
  70.  
  71. int xPosition = 1;
  72. int yPosition = 1;
  73. int xVelocity = 0;
  74. int yVelocity = 0;
  75. int count = 0;
  76.  
  77. while(ask)
  78. {
  79. printrace(grid);
  80. cout << "Horizontal and vertical acceleration (-1,0,1): ";
  81. cin >> xAcceleration >> yAcceleration;
  82. cout << endl;
  83. count = count + 1;
  84.  
  85. if(xAcceleration > 1 || yAcceleration > 1)
  86. {
  87. cout << "Crashed after " << count << " secs\n";
  88. ask = false;
  89. }
  90. else if (xAcceleration < -1 || yAcceleration < -1)
  91. {
  92. cout << "Crashed after " << count << " secs\n";
  93. ask =false;
  94. }
  95.  
  96. xVelocity = xVelocity + xAcceleration;
  97. yVelocity = yVelocity + yAcceleration;
  98. xPosition = xPosition + xVelocity;
  99. yPosition = yPosition + yVelocity;
  100.  
  101. if ((xPosition <= 0) || (xPosition >= 72))
  102. {
  103. cout << "Crashed after " << count << " secs\n";
  104. ask = false;
  105. }
  106.  
  107. else if ((yPosition <=0) || (yPosition >= 52))
  108. {
  109. cout << "Crashed after " << count << " secs\n";
  110. ask = false;
  111. }
  112. else if ((xPosition >= 10 && xPosition <= 29) && (yPosition < 34))
  113. {
  114. cout << "Crashed after " << count << " secs\n";
  115. ask = false;
  116. }
  117. else if ((xPosition >= 40 && xPosition <= 64) && (yPosition >= 35))
  118. {
  119. cout << "Crashed after " << count << " secs\n";
  120. ask = false;
  121. }
  122. else if ((xPosition >= 65) && (xPosition <= 70))
  123. {
  124. cout << "You won! You just crossed the finish line!\n";
  125. ask = false;
  126. }
  127.  
  128. grid[yPosition][xPosition] = '0';
  129.  
  130. //manipulate grid array
  131. //then the loop will continue which calls the printrace
  132. //which will display your new changes to grid array
  133.  
  134.  
  135. //############## - 2 PLAYER - #########################################//
  136. //when player crosses finish line
  137. // store time in scoretime
  138. // maybe put this into an array and
  139. //also store currentPlayer
  140. //after that happens reset scoretime to 0 and set currentPlayer to next player
  141. //then for a two player game
  142. //if player 1 or 2 crashes whoever crashes loses and display winner
  143. // if both players didn't crash
  144. //then loop thru array and see who has smalles scoretime
  145. //lowest score time and associated currentPlayer value is your winner
  146. //display those
  147. //############## - 2 PLAYER - #########################################//
  148. }
  149.  
  150.  
  151.  
  152.  
  153. return 0;
  154.  
  155. }
  156.  
  157.  
  158.  
  159. /* Vanna Quon
  160. ENGR101: Section 305
  161. Date: 3.28.12
  162. Project 6.1
  163. GSI: Jeff
  164. hwk6.cpp
  165. */
  166.  
  167. #include <iostream>
  168. using namespace std;
  169.  
  170. const int NROWS = 52;
  171. const int NCOLS = 72;
  172.  
  173. void printrace(const char a[][NCOLS])
  174. {
  175. for (int i = 0; i < NROWS; i++)
  176. {
  177. for (int j = 0; j < NCOLS; j++)
  178. {
  179. cout << a[i][j];
  180. }
  181. cout << endl;
  182. }
  183. return;
  184. }
  185.  
  186. void initrace(char b[][NCOLS])
  187. {
  188.  
  189. for (int i = 0; i < NROWS; i++)
  190. {
  191. for (int j = 0; j < NCOLS; j++)
  192. {
  193. b[1][1] = 'O'; //car
  194. if(j==0) b[i][j] = 'X'; //first left column
  195. else if(j==71) b[i][j] = 'X'; // last right column
  196. else if ((j>=10 && j<=29)&& (i >=0 && i <=34)) b[i][j] = 'X'; //first block
  197. else if ((j>=40 && j<=64)&& (i >=18 && i <=51)) b[i][j] = 'X'; //second block
  198. else if ((i==0)&& j<=(NCOLS-1)) b[i][j] = 'X'; //top row
  199. else if ((i==(NROWS-1))&&(j>=0 && j<=40)) b[i][j] = 'X'; //bottom row
  200. else if ((i==(NROWS-1))&&(j>=55 && j<=(NCOLS-2))) b[i][j] = 'F'; //finish line
  201. else b[i][j] = ' ';
  202. }
  203. }
  204.  
  205. return;
  206. }
  207.  
  208. int main(void)
  209. {
  210. //initrace sets up the grid
  211. //print race prints out the grid
  212.  
  213.  
  214. char grid[NROWS][NCOLS];
  215.  
  216.  
  217. //grid[1][1] = 'O';
  218. //printrace(grid);
  219. //initrace(grid);
  220.  
  221. int xAcceleration = 0;
  222. int yAcceleration = 0;
  223. bool ask = true;
  224.  
  225. //int scoretime = 0;
  226. //int currentPlayer = 1;
  227. initrace(grid);
  228.  
  229. int xPosition = 1;
  230. int yPosition = 1;
  231. int xVelocity = 0;
  232. int yVelocity = 0;
  233. int count = 0;
  234.  
  235. while(ask)
  236. {
  237. printrace(grid);
  238. cout << "Horizontal and vertical acceleration (-1,0,1): ";
  239. cin >> xAcceleration >> yAcceleration;
  240. cout << endl;
  241. count = count + 1;
  242.  
  243. if(xAcceleration > 1 || yAcceleration > 1)
  244. {
  245. cout << "Crashed after " << count << " secs\n";
  246. ask = false;
  247. }
  248. else if (xAcceleration < -1 || yAcceleration < -1)
  249. {
  250. cout << "Crashed after " << count << " secs\n";
  251. ask =false;
  252. }
  253.  
  254. xVelocity = xVelocity + xAcceleration;
  255. yVelocity = yVelocity + yAcceleration;
  256. xPosition = xPosition + xVelocity;
  257. yPosition = yPosition + yVelocity;
  258.  
  259. if ((xPosition <= 0) || (xPosition >= 72))
  260. {
  261. cout << "Crashed after " << count << " secs\n";
  262. ask = false;
  263. }
  264.  
  265. else if ((yPosition <=0) || (yPosition >= 52))
  266. {
  267. cout << "Crashed after " << count << " secs\n";
  268. ask = false;
  269. }
  270. else if ((xPosition >= 10 && xPosition <= 29) && (yPosition < 34))
  271. {
  272. cout << "Crashed after " << count << " secs\n";
  273. ask = false;
  274. }
  275. else if ((xPosition >= 40 && xPosition <= 64) && (yPosition >= 35))
  276. {
  277. cout << "Crashed after " << count << " secs\n";
  278. ask = false;
  279. }
  280. else if ((xPosition >= 65) && (xPosition <= 70))
  281. {
  282. cout << "You won! You just crossed the finish line!\n";
  283. ask = false;
  284. }
  285.  
  286. grid[yPosition][xPosition] = '0';
  287.  
  288. //manipulate grid array
  289. //then the loop will continue which calls the printrace
  290. //which will display your new changes to grid array
  291.  
  292.  
  293. //############## - 2 PLAYER - #########################################//
  294. //when player crosses finish line
  295. // store time in scoretime
  296. // maybe put this into an array and
  297. //also store currentPlayer
  298. //after that happens reset scoretime to 0 and set currentPlayer to next player
  299. //then for a two player game
  300. //if player 1 or 2 crashes whoever crashes loses and display winner
  301. // if both players didn't crash
  302. //then loop thru array and see who has smalles scoretime
  303. //lowest score time and associated currentPlayer value is your winner
  304. //display those
  305. //############## - 2 PLAYER - #########################################//
  306. }
  307.  
  308.  
  309.  
  310.  
  311. return 0;
  312.  
  313. }
Add Comment
Please, Sign In to add comment