Guest User

Array Issue Program

a guest
Feb 16th, 2014
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <conio.h>
  4. #include <windows.h>
  5. #include <time.h>
  6.  
  7. using namespace std;
  8.  
  9. ifstream screenInput;
  10.  
  11. void createScreen();
  12. void printScreen();
  13. void input();
  14. void createTeams();
  15. void updateAllianceSelect();
  16. void updateTeamSelect();
  17. void updateMode();
  18. void updatePassAssist();
  19. void updateGoal();
  20. void updateCaughtBall();
  21. void updateDroveForward();
  22.  
  23. static char screen[20][69];
  24. static char droveForwardString[13] = {'D', 'R', 'O', 'V', 'E', ' ', 'F', 'O', 'R', 'W', 'A', 'R', 'D'};
  25. static char ballCatchString[13] = {'C', 'A', 'T', 'C', 'H', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '};
  26.  
  27. static char blueTeamOneName[4];
  28. static char blueTeamTwoName[4];
  29. static char blueTeamThreeName[4];
  30. static char redTeamOneName[4];
  31. static char redTeamTwoName[4];
  32. static char redTeamThreeName[4];
  33.  
  34. static int blueTeam;
  35. static int blueTeamOne;
  36. static int blueTeamTwo;
  37. static int blueTeamThree;
  38.  
  39. static int redTeam;
  40. static int redTeamOne;
  41. static int redTeamTwo;
  42. static int redTeamThree;
  43.  
  44. static int teamSelect = 1; // 1 | 2 | 3
  45.  
  46. static int passAssist = 0; // 0 | 1 | 2 | 3
  47.  
  48. static bool gameMode = false; // false = autonomous | true = teleop
  49. static bool goal = true; // false = low | true = high
  50. static bool ballCatch = false; // false = no | true = yes
  51. static bool droveForward = false; // false = no | true = yes
  52.  
  53. static bool allianceSelect = false; // false = red | true = blue
  54.  
  55. int main()
  56. {
  57. bool runTime = true;
  58. bool runCommand = false;
  59.  
  60. createScreen();
  61. createTeams();
  62.  
  63. while (runTime)
  64. {
  65. printScreen();
  66. input();
  67. }
  68. return 0;
  69. }
  70.  
  71. void createScreen()
  72. {
  73. screenInput.open("screen.txt");
  74. for (int x = 0; x != 20; x++)
  75. {
  76. for (int y = 0; y != 69; y++)
  77. {
  78. screenInput >> screen[x][y];
  79. if (screen[x][y] == '.')
  80. screen[x][y] = ' ';
  81. if (screen[x][y] == 'x')
  82. screen[x][y] = (char)219;
  83. }
  84. }
  85. screenInput.close();
  86. }
  87.  
  88. void printScreen()
  89. {
  90. COORD set{ 0, 0 };
  91. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), set);
  92. for (int x = 0; x != 20; x++)
  93. {
  94. for (int y = 0; y != 69; y++)
  95. {
  96. cout << screen[x][y];
  97. }
  98. cout << endl;
  99. }
  100. }
  101.  
  102. void input()
  103. {
  104. int command = _getch();
  105. if (command == 77 || command == 109) // m key | changes auto and tele
  106. {
  107. if (gameMode)
  108. gameMode = false;
  109. else if (!gameMode)
  110. gameMode = true;
  111. updateMode();
  112. }
  113. if (command == 74 || command == 106) // j key | high or low goal selection
  114. {
  115. if (goal)
  116. goal = false;
  117. else if (!goal)
  118. goal = true;
  119. updateGoal();
  120. }
  121. if (command == 75 || command == 107) // k key | pass assist counter
  122. {
  123. if (passAssist >= 0 && passAssist <= 2)
  124. passAssist++;
  125. else if (passAssist == 3)
  126. passAssist = 0;
  127. updatePassAssist();
  128. }
  129. if (command == 76 || command == 108) // l key | caught a ball or not | drove forward or not
  130. {
  131. if (gameMode)
  132. {
  133. if (ballCatch)
  134. ballCatch = false;
  135. else if (!ballCatch)
  136. ballCatch = true;
  137. updateCaughtBall();
  138. }
  139. else if (!gameMode)
  140. {
  141. if (droveForward)
  142. droveForward = false;
  143. else if (!droveForward)
  144. droveForward = true;
  145. updateDroveForward();
  146. }
  147. }
  148.  
  149. if (command == 65 || command == 68 || command == 97 || command == 100) // a and d key | alliance select
  150. {
  151. if (allianceSelect)
  152. allianceSelect = false;
  153. else if (!allianceSelect)
  154. allianceSelect = true;
  155. updateAllianceSelect();
  156. }
  157.  
  158. if (command == 83 || command == 87 || command == 115 || command == 119) // w and s key | team select
  159. {
  160. if (teamSelect == 1 || teamSelect == 2)
  161. teamSelect++;
  162. else if (teamSelect == 3)
  163. teamSelect = 1;
  164. updateTeamSelect();
  165. }
  166. }
  167.  
  168. void createTeams()
  169. {
  170. cout << "ENTER THE TEAM NUMBER FOR EACH TEAM\nRED TEAM 1: ";
  171. cin.getline(redTeamOneName, 5);
  172. cout << "RED TEAM 2: ";
  173. cin.getline(redTeamTwoName, 5);
  174. cout << "RED TEAM 3: ";
  175. cin.getline(redTeamThreeName, 5);
  176. cout << "\nBLUE TEAM 1: ";
  177. cin.getline(blueTeamOneName, 5);
  178. cout << "BLUE TEAM 2: ";
  179. cin.getline(blueTeamTwoName, 5);
  180. cout << "BLUE TEAM 3: ";
  181. cin.getline(blueTeamThreeName, 5);
  182.  
  183. for (int i = 4; i != 10; i += 2)
  184. {
  185. for (int x = 0; x != 4; x++)
  186. {
  187. if (i == 4)
  188. screen[i][11 + x] = redTeamOneName[x];
  189. else if (i == 6)
  190. screen[i][11 + x] = redTeamTwoName[x];
  191. else if (i == 8)
  192. screen[i][11 + x] = redTeamThreeName[x];
  193. }
  194. }
  195.  
  196. for (int i = 4; i != 10; i += 2)
  197. {
  198. for (int x = 0; x != 4; x++)
  199. {
  200. if (i == 4)
  201. screen[i][45 + x] = blueTeamOneName[x];
  202. else if (i == 6)
  203. screen[i][45 + x] = blueTeamTwoName[x];
  204. else if (i == 8)
  205. screen[i][45 + x] = blueTeamThreeName[x];
  206. }
  207. }
  208. }
  209.  
  210. void updateAllianceSelect()
  211. {
  212. if (allianceSelect)
  213. {
  214. screen[2][39] = '[';
  215. screen[2][53] = ']';
  216. screen[2][5] = ' ';
  217. screen[2][18] = ' ';
  218. if (teamSelect == 1)
  219. {
  220. screen[4][39] = '[';
  221. screen[4][49] = ']';
  222. screen[4][5] = ' ';
  223. screen[4][15] = ' ';
  224. }
  225. else if (teamSelect == 2)
  226. {
  227. screen[6][39] = '[';
  228. screen[6][49] = ']';
  229. screen[6][5] = ' ';
  230. screen[6][15] = ' ';
  231. }
  232. else if (teamSelect == 3)
  233. {
  234. screen[8][39] = '[';
  235. screen[8][49] = ']';
  236. screen[8][5] = ' ';
  237. screen[8][15] = ' ';
  238. }
  239. }
  240. else if (!allianceSelect)
  241. {
  242. screen[2][5] = '[';
  243. screen[2][18] = ']';
  244. screen[2][39] = ' ';
  245. screen[2][53] = ' ';
  246. if (teamSelect == 1)
  247. {
  248. screen[4][5] = '[';
  249. screen[4][15] = ']';
  250. screen[4][39] = ' ';
  251. screen[4][49] = ' ';
  252. }
  253. else if (teamSelect == 2)
  254. {
  255. screen[6][5] = '[';
  256. screen[6][15] = ']';
  257. screen[6][39] = ' ';
  258. screen[6][49] = ' ';
  259. }
  260. else if (teamSelect == 3)
  261. {
  262. screen[8][5] = '[';
  263. screen[8][15] = ']';
  264. screen[8][39] = ' ';
  265. screen[8][49] = ' ';
  266. }
  267. }
  268. }
  269.  
  270. void updateTeamSelect()
  271. {
  272. if (!allianceSelect)
  273. {
  274. if (teamSelect == 1)
  275. {
  276. screen[4][5] = '[';
  277. screen[4][15] = ']';
  278. screen[8][5] = ' ';
  279. screen[8][15] = ' ';
  280. }
  281. else if (teamSelect == 2)
  282. {
  283. screen[6][5] = '[';
  284. screen[6][15] = ']';
  285. screen[4][5] = ' ';
  286. screen[4][15] = ' ';
  287. }
  288. else if (teamSelect == 3)
  289. {
  290. screen[8][5] = '[';
  291. screen[8][15] = ']';
  292. screen[6][5] = ' ';
  293. screen[6][15] = ' ';
  294. }
  295. }
  296. else if (allianceSelect)
  297. {
  298. if (teamSelect == 1)
  299. {
  300. screen[4][39] = '[';
  301. screen[4][49] = ']';
  302. screen[8][39] = ' ';
  303. screen[8][49] = ' ';
  304. }
  305. else if (teamSelect == 2)
  306. {
  307. screen[6][39] = '[';
  308. screen[6][49] = ']';
  309. screen[4][39] = ' ';
  310. screen[4][49] = ' ';
  311. }
  312. else if (teamSelect == 3)
  313. {
  314. screen[8][39] = '[';
  315. screen[8][49] = ']';
  316. screen[6][39] = ' ';
  317. screen[6][49] = ' ';
  318. }
  319. }
  320. }
  321.  
  322. void updateMode()
  323. {
  324. if (!gameMode)
  325. {
  326. screen[17][62] = '[';
  327. screen[17][67] = ']';
  328. screen[18][62] = ' ';
  329. screen[18][67] = ' ';
  330. for (int x = 0; x != 13; x++)
  331. screen[12][38 + x] = droveForwardString[x];
  332. }
  333. else if (gameMode)
  334. {
  335. screen[18][62] = '[';
  336. screen[18][67] = ']';
  337. screen[17][62] = ' ';
  338. screen[17][67] = ' ';
  339. for (int x = 0; x != 13; x++)
  340. screen[12][38 + x] = ballCatchString[x];
  341. }
  342. }
  343.  
  344. void updatePassAssist()
  345. {
  346. if (passAssist == 1)
  347. {
  348. screen[12][19] = '[';
  349. screen[12][33] = ']';
  350. }
  351. else if (passAssist == 2)
  352. {
  353. screen[14][19] = '[';
  354. screen[14][33] = ']';
  355. screen[12][19] = ' ';
  356. screen[12][33] = ' ';
  357. }
  358. else if (passAssist == 3)
  359. {
  360. screen[16][19] = '[';
  361. screen[16][33] = ']';
  362. screen[14][19] = ' ';
  363. screen[14][33] = ' ';
  364. }
  365. else if (passAssist == 0)
  366. {
  367. screen[16][19] = ' ';
  368. screen[16][33] = ' ';
  369. }
  370. }
  371.  
  372. void updateGoal()
  373. {
  374. if (goal)
  375. {
  376. screen[12][5] = '[';
  377. screen[12][15] = ']';
  378. screen[14][5] = ' ';
  379. screen[14][14] = ' ';
  380. }
  381. else if (!goal)
  382. {
  383. screen[14][5] = '[';
  384. screen[14][14] = ']';
  385. screen[12][5] = ' ';
  386. screen[12][15] = ' ';
  387. }
  388. }
  389.  
  390. void updateCaughtBall()
  391. {
  392. if (ballCatch)
  393. {
  394. screen[12][37] = '[';
  395. screen[12][43] = ']';
  396. }
  397. else if (!ballCatch)
  398. {
  399. screen[12][37] = ' ';
  400. screen[12][43] = ' ';
  401. }
  402. }
  403.  
  404. void updateDroveForward()
  405. {
  406. if (droveForward)
  407. {
  408. screen[12][37] = '[';
  409. screen[12][51] = ']';
  410. }
  411. else if (!droveForward)
  412. {
  413. screen[12][37] = ' ';
  414. screen[12][51] = ' ';
  415. }
  416. }
Advertisement
Add Comment
Please, Sign In to add comment