Advertisement
rexinsteroids

bkup-mswp

Apr 8th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. string outLettersUp = "ABCDEFGHIJKLMNOPQRSTUVWXY", outLettersLow = "abcdefghijklmnopqrstuvwxy";
  10. string BoutLettersUp = "ABCDEFGHIJKLMNOPQRSTUVWXY", BoutLettersLow = "abcdefghijklmnopqrstuvwxy";
  11. string intLettersUp = outLettersUp;
  12. string guess;
  13. int loop = 1;
  14. char guessChar;
  15. int bombCount[25] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  16. srand(time(0));
  17. cout<<"MINESWEEPER"<<endl;
  18.  
  19. for (int a = 0; a < 5; a++)
  20. {
  21. int b = rand()% 25;
  22. intLettersUp.replace(b, 1, "Z");
  23. intLettersLow.replace(b, 1, "Z");
  24. }
  25.  
  26. //special case 1: position 0
  27. for (int i = 0; i < 3; i++)
  28. {
  29. if (i == 0)
  30. {
  31. if (intLettersUp.substr(1, 1) == "Z")
  32. {
  33. bombCount[0] += 1;
  34. }
  35. }
  36. if (i == 1)
  37. {
  38. if (intLettersUp.substr(5, 1) == "Z")
  39. {
  40. bombCount[0] += 1;
  41. }
  42. }
  43. if (i == 2)
  44. {
  45. if (intLettersUp.substr(6, 1) == "Z")
  46. {
  47. bombCount[0] += 1;
  48. }
  49. }
  50. }
  51. //special case 2: position 20
  52. for (int j = 0; j < 3; j++)
  53. {
  54. if (j == 0)
  55. {
  56. if (intLettersUp.substr(15, 1) == "Z")
  57. {
  58. bombCount[20] += 1;
  59. }
  60. }
  61. if (j == 1)
  62. {
  63. if (intLettersUp.substr(16, 1) == "Z")
  64. {
  65. bombCount[20] += 1;
  66. }
  67. }
  68. if (j == 2)
  69. {
  70. if (intLettersUp.substr(21, 1) == "Z")
  71. {
  72. bombCount[20] += 1;
  73. }
  74. }
  75. }
  76.  
  77. // special case: position 4
  78. for (int k = 0; k < 3; k++)
  79. {
  80. if (k == 0)
  81. {
  82. if (intLettersUp.substr(3, 1) == "Z")
  83. {
  84. bombCount[4] += 1;
  85. }
  86. }
  87. if (k == 1)
  88. {
  89. if (intLettersUp.substr(9, 1) == "Z")
  90. {
  91. bombCount[4] += 1;
  92. }
  93. }
  94. if (k == 2)
  95. {
  96. if (intLettersUp.substr(8, 1) == "Z")
  97. {
  98. bombCount[4] += 1;
  99. }
  100. }
  101. }
  102. // special case: position 24
  103. for (int l = 0; l < 3; l++)
  104. {
  105. if (l == 0)
  106. {
  107. if (intLettersUp.substr(23, 1) == "Z")
  108. {
  109. bombCount[24] += 1;
  110. }
  111. }
  112. if (l == 1)
  113. {
  114. if (intLettersUp.substr(19, 1) == "Z")
  115. {
  116. bombCount[24] += 1;
  117. }
  118. }
  119. if (l == 2)
  120. {
  121. if (intLettersUp.substr(18, 1) == "Z")
  122. {
  123. bombCount[24] += 1;
  124. }
  125. }
  126. }
  127. // case left; positions 5, 10, 15
  128. for (int m = 5; m < 16; m += 5)
  129. {
  130. for (int n = 0; n < 5; n++)
  131. {
  132. if (n == 0)
  133. {
  134. if (intLettersUp.substr(m-5, 1) == "Z")
  135. {
  136. bombCount[m] += 1;
  137. }
  138. }
  139. if (n == 1)
  140. {
  141. if (intLettersUp.substr((m-4), 1) == "Z")
  142. {
  143. bombCount[m] += 1;
  144. }
  145. }
  146. if (n == 2)
  147. {
  148. if (intLettersUp.substr((m+1), 1) == "Z")
  149. {
  150. bombCount[m] += 1;
  151. }
  152. }
  153. if (n == 3)
  154. {
  155. if (intLettersUp.substr((m+5), 1) == "Z")
  156. {
  157. bombCount[m] += 1;
  158. }
  159. }
  160. if (n == 4)
  161. {
  162. if (intLettersUp.substr((m+6), 1) == "Z")
  163. {
  164. bombCount[m] += 1;
  165. }
  166. }
  167. }
  168.  
  169. }
  170.  
  171. // case right; positions 9, 14, 19
  172. for (int o = 9; o < 20; o = o + 5)
  173. {
  174. for (int p = 0; p < 5; p++)
  175. {
  176. if (p == 0)
  177. {
  178. if (intLettersUp.substr(o-6, 1) == "Z")
  179. {
  180. bombCount[o] += 1;
  181. }
  182. }
  183. if (p == 1)
  184. {
  185. if (intLettersUp.substr(o-5, 1) == "Z")
  186. {
  187. bombCount[o] += 1;
  188. }
  189. }
  190. if (p == 2)
  191. {
  192. if (intLettersUp.substr(o-1, 1) == "Z")
  193. {
  194. bombCount[o] += 1;
  195. }
  196. }
  197. if (p == 3)
  198. {
  199. if (intLettersUp.substr(o+4, 1) == "Z")
  200. {
  201. bombCount[o] += 1;
  202. }
  203. }
  204. if (p == 4)
  205. {
  206. if (intLettersUp.substr(o+5, 1) == "Z")
  207. {
  208. bombCount[o] += 1;
  209. }
  210. }
  211. }
  212. }
  213.  
  214. // case up; positions 9, 14, 19
  215. for (int q = 1; q < 4; q++)
  216. {
  217. for (int r = 0; r < 5; r++)
  218. {
  219. if (r == 0)
  220. {
  221. if (intLettersUp.substr(q-1, 1) == "Z")
  222. {
  223. bombCount[q] += 1;
  224. }
  225. }
  226. if (r == 1)
  227. {
  228. if (intLettersUp.substr(q+1, 1) == "Z")
  229. {
  230. bombCount[q] += 1;
  231. }
  232. }
  233. if (r == 2)
  234. {
  235. if (intLettersUp.substr(q+4, 1) == "Z")
  236. {
  237. bombCount[q] += 1;
  238. }
  239. }
  240. if (r == 3)
  241. {
  242. if (intLettersUp.substr(q+5, 1) == "Z")
  243. {
  244. bombCount[q] += 1;
  245. }
  246. }
  247. if (r == 4)
  248. {
  249. if (intLettersUp.substr(q+6, 1) == "Z")
  250. {
  251. bombCount[q] += 1;
  252. }
  253. }
  254. }
  255. }
  256.  
  257. // case down; positions 21, 22, 23
  258. for (int s = 21; s < 24; s++)
  259. {
  260. for (int t = 0; t < 5; t++)
  261. {
  262. if (t == 0)
  263. {
  264. if (intLettersUp.substr(s-6, 1) == "Z")
  265. {
  266. bombCount[s] += 1;
  267. }
  268. }
  269. if (t == 1)
  270. {
  271. if (intLettersUp.substr(s-5, 1) == "Z")
  272. {
  273. bombCount[s] += 1;
  274. }
  275. }
  276. if (t == 2)
  277. {
  278. if (intLettersUp.substr(s-4, 1) == "Z")
  279. {
  280. bombCount[s] += 1;
  281. }
  282. }
  283. if (t == 3)
  284. {
  285. if (intLettersUp.substr(s-1, 1) == "Z")
  286. {
  287. bombCount[s] += 1;
  288. }
  289. }
  290. if (t == 4)
  291. {
  292. if (intLettersUp.substr(s+1, 1) == "Z")
  293. {
  294. bombCount[s] += 1;
  295. }
  296. }
  297. }
  298. }
  299.  
  300. // case middle; positions 6, 7, 8, 11, 12, 13, 16, 17, 18
  301. for (int u = 6; u < 19; u++)
  302. {
  303. if (u == 9)
  304. {
  305. u = 11;
  306. }
  307. if (u == 14)
  308. {
  309. u = 16;
  310. }
  311.  
  312. for (int v = 0; v < 9; v++)
  313. {
  314. if (v == 0)
  315. {
  316. if (intLettersUp.substr(u-6, 1) == "Z")
  317. {
  318. bombCount[u] += 1;
  319. }
  320. }
  321. if (v == 1)
  322. {
  323. if (intLettersUp.substr(u-5, 1) == "Z")
  324. {
  325. bombCount[u] += 1;
  326. }
  327. }
  328. if (v == 2)
  329. {
  330. if (intLettersUp.substr(u-4, 1) == "Z")
  331. {
  332. bombCount[u] += 1;
  333. }
  334. }
  335. if (v == 3)
  336. {
  337. if (intLettersUp.substr(u-1, 1) == "Z")
  338. {
  339. bombCount[u] += 1;
  340. }
  341. }
  342. if (v == 4)
  343. {
  344. if (intLettersUp.substr(u+1, 1) == "Z")
  345. {
  346. bombCount[u] += 1;
  347. }
  348. }
  349. if (v == 5)
  350. {
  351. if (intLettersUp.substr(u+4, 1) == "Z")
  352. {
  353. bombCount[u] += 1;
  354. }
  355. }
  356. if (v == 6)
  357. {
  358. if (intLettersUp.substr(u+5, 1) == "Z")
  359. {
  360. bombCount[u] += 1;
  361. }
  362. }
  363. if (v == 7)
  364. {
  365. if (intLettersUp.substr(u+6, 1) == "Z")
  366. {
  367. bombCount[u] += 1;
  368. }
  369. }
  370. }
  371. }
  372.  
  373. for (int w = 0; w < 25; w++)
  374. {
  375. if (bombCount[w] == 0)
  376. {
  377. if (intLettersUp.substr(w, 1) != "Z")
  378. {
  379. intLettersUp.replace(w, 1, "0");
  380. }
  381. }
  382. if (bombCount[w] == 1)
  383. {
  384. if (intLettersUp.substr(w, 1) != "Z")
  385. {
  386. intLettersUp.replace(w, 1, "1");
  387. }
  388. }
  389. if (bombCount[w] == 2)
  390. {
  391. if (intLettersUp.substr(w, 1) != "Z")
  392. {
  393. intLettersUp.replace(w, 1, "2");
  394. }
  395. }
  396. if (bombCount[w] == 3)
  397. {
  398. if (intLettersUp.substr(w, 1) != "Z")
  399. {
  400. intLettersUp.replace(w, 1, "3");
  401. }
  402. }
  403. if (bombCount[w] == 4)
  404. {
  405. if (intLettersUp.substr(w, 1) != "Z")
  406. {
  407. intLettersUp.replace(w, 1, "4");
  408. }
  409. }
  410. if (bombCount[w] == 5)
  411. {
  412. if (intLettersUp.substr(w, 1) != "Z")
  413. {
  414. intLettersUp.replace(w, 1, "5");
  415. }
  416. }
  417. }
  418.  
  419. // for checking
  420. for (int d=0; d<5; d++)
  421. {
  422. cout<<intLettersUp.substr(d, 1)<<" ";
  423. }
  424. cout<<endl;
  425. for (int e=5; e<10; e++)
  426. {
  427. cout<<intLettersUp.substr(e, 1)<<" ";
  428. }
  429. cout<<endl;
  430. for (int f=10; f<15; f++)
  431. {
  432. cout<<intLettersUp.substr(f, 1)<<" ";
  433. }
  434. cout<<endl;
  435. for (int g=15; g<20; g++)
  436. {
  437. cout<<intLettersUp.substr(g, 1)<<" ";
  438. }
  439. cout<<endl;
  440. for (int h=20; h<25; h++)
  441. {
  442. cout<<intLettersUp.substr(h, 1)<<" ";
  443. }
  444. cout<<endl;
  445.  
  446. Start:
  447. while (loop == 1)
  448. {
  449. for (int d=0; d<5; d++)
  450. {
  451. cout<<outLettersUp.substr(d, 1)<<" ";
  452. }
  453. cout<<endl;
  454. for (int e=5; e<10; e++)
  455. {
  456. cout<<outLettersUp.substr(e, 1)<<" ";
  457. }
  458. cout<<endl;
  459. for (int f=10; f<15; f++)
  460. {
  461. cout<<outLettersUp.substr(f, 1)<<" ";
  462. }
  463. cout<<endl;
  464. for (int g=15; g<20; g++)
  465. {
  466. cout<<outLettersUp.substr(g, 1)<<" ";
  467. }
  468. cout<<endl;
  469. for (int h=20; h<25; h++)
  470. {
  471. cout<<outLettersUp.substr(h, 1)<<" ";
  472. }
  473. cout<<endl;
  474. cout<<endl<<"Choose a letter."<<endl;
  475. guessChar = getch();
  476. guess += guessChar;
  477.  
  478. for (int x = 0; x < 25; x++)
  479. {
  480. if ((guess.substr(0, 1) == BoutLettersUp.substr(x, 1)) || (guess.substr(0,1) == BoutLettersLow.substr(x, 1))
  481. {
  482. goto GuessMark;
  483. }
  484. else {
  485. cout<<"The character you pressed should be within the grid only.";
  486. guess.clear();
  487. guessChar = '';
  488. goto Start;
  489. }
  490. }
  491.  
  492. GuessMark:
  493. cout<<endl<<"Your guess is: "<<guess<<endl;
  494. system("pause");
  495.  
  496. for
  497. }
  498.  
  499.  
  500. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement