Advertisement
Guest User

Untitled

a guest
May 19th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. #include <Windows.h>
  5.  
  6. using namespace std;
  7.  
  8. bool pataikei;
  9.  
  10. int const eilutes = 10;
  11.  
  12. int const stulpeliai = 10;
  13.  
  14. char lenteleZm[11][11];
  15. char lenteleCpu[11][11];
  16. char NujaLentCpu[11][11];
  17. int laivaicpu = 20;
  18. int laivaizm = 20;
  19.  
  20. int xpoz=11, ypoz=11;
  21.  
  22. void pradzia()
  23. {
  24. for(int i=0; i<stulpeliai; i++)
  25. {
  26. for(int j=0; j<eilutes; j++)
  27. {
  28. lenteleZm[j][i]='O';
  29. }
  30. }
  31.  
  32. for(int i=0; i<stulpeliai; i++)
  33. {
  34. for(int j=0; j<eilutes; j++)
  35. {
  36. lenteleCpu[j][i]='O';
  37. NujaLentCpu[j][i]='O';
  38. }
  39. }
  40. }
  41.  
  42. void spam()
  43. {
  44. srand(time(NULL));
  45. for(int i=0; i<20; i++)
  46. {
  47. int x = rand() %9+0;
  48. int y = rand() %9+0;
  49.  
  50. if(lenteleZm[x][y]=='1')
  51. {
  52. while(lenteleZm[x][y]=='1')
  53. {
  54. x = rand() %9+0;
  55. y = rand() %9+0;
  56. }
  57. lenteleZm[x][y]='1';
  58. }
  59. else
  60. lenteleZm[x][y]='1';
  61. }
  62.  
  63. for(int i=0; i<20; i++)
  64. {
  65. int x = rand() %9+0;
  66. int y = rand() %9+0;
  67.  
  68. if(lenteleCpu[x][y]=='1')
  69. {
  70. while(lenteleCpu[x][y]=='1')
  71. {
  72. x = rand() %9+0;
  73. y = rand() %9+0;
  74. }
  75. lenteleCpu[x][y]='1';
  76. }
  77. else
  78. lenteleCpu[x][y]='1';
  79. }
  80.  
  81.  
  82. }
  83.  
  84. void saudymas()
  85. {
  86. cout << " " << endl;
  87. cout << "Iveskite x ir y pozicijas:" << endl;
  88. cin >> xpoz >> ypoz;
  89.  
  90. while (cin.fail())
  91. {
  92. cin.clear();
  93. cin.ignore();
  94. cout << "Blogas ivedimas, iveskite skaicius ";
  95. cin >> xpoz >> ypoz;
  96. }
  97.  
  98. if (xpoz > eilutes || xpoz < 1)
  99. {
  100. while (true)
  101. {
  102. cout << "Bloga koordinate x, bandykite dar karta: ";
  103. cin >> xpoz;
  104. if (xpoz <= eilutes && xpoz >= 1)
  105. {
  106. break;
  107. }
  108. }
  109. }
  110.  
  111. if (ypoz > eilutes || ypoz < 1)
  112. {
  113. while (true)
  114. {
  115. cout << "Bloga koordinate y, bandykite dar karta: ";
  116. cin >> ypoz;
  117. if (ypoz <= eilutes && ypoz >= 1)
  118. {
  119. break;
  120. }
  121. }
  122. }
  123.  
  124. bool vienodi=true;
  125.  
  126. if(lenteleCpu[xpoz][ypoz]!='X' && lenteleCpu[xpoz][ypoz]!='N')
  127. {
  128. if(lenteleCpu[xpoz][ypoz]=='1')
  129. {
  130. lenteleCpu[xpoz][ypoz]='X';
  131. NujaLentCpu[xpoz][ypoz]='X';
  132. laivaicpu--;
  133. }
  134. else
  135. {
  136. lenteleCpu[xpoz][ypoz]='N';
  137. NujaLentCpu[xpoz][ypoz]='N';
  138. }
  139. }
  140. else
  141. while(vienodi)
  142. {
  143. cout << "Cia jau sovei" << endl;
  144. cout << "Iveskite x ir y pozicijas:" << endl;
  145. cin >> xpoz >> ypoz;
  146.  
  147. if(lenteleCpu[xpoz][ypoz]!='X' && lenteleCpu[xpoz][ypoz]!='N')
  148. {
  149. vienodi=false;
  150. if(lenteleCpu[xpoz][ypoz]=='1')
  151. {
  152. lenteleCpu[xpoz][ypoz]='X';
  153. NujaLentCpu[xpoz][ypoz]='X';
  154. laivaicpu--;
  155. }
  156. else
  157. lenteleCpu[xpoz][ypoz]='N';
  158. NujaLentCpu[xpoz][ypoz]='N';
  159. }
  160. }
  161.  
  162. system("CLS");
  163. }
  164.  
  165. void saudymascpu()
  166. {
  167. srand(time(NULL));
  168. bool vienodi=true;
  169. int xp = rand() %9+0;
  170. int yp = rand() %9+0;
  171.  
  172. if(lenteleZm[xp][yp]!='X' && lenteleZm[xp][yp]!='N')
  173. {
  174. if(lenteleZm[xp][yp]=='1')
  175. {
  176. lenteleZm[xp][yp]='X';
  177. laivaizm--;
  178. }
  179. else
  180. lenteleZm[xp][yp]='N';
  181. }
  182. else
  183. while(vienodi)
  184. {
  185. xp = rand() %9+0;
  186. yp = rand() %9+0;
  187.  
  188. if(lenteleZm[xp][yp]!='X' && lenteleZm[xp][yp]!='N')
  189. {
  190. vienodi=false;
  191. if(lenteleZm[xp][yp]=='1')
  192. {
  193. lenteleZm[xp][yp]='X';
  194. laivaizm--;
  195. }
  196. else
  197. lenteleZm[xp][yp]='N';
  198. }
  199. }
  200.  
  201. system("CLS");
  202. }
  203.  
  204. void spausdinti()
  205. {
  206. cout << " Tavo lenta" << endl;
  207. cout << " Turi laivu " << laivaizm << endl;
  208. cout << " 0 1 2 3 4 5 6 7 8 9" << endl;
  209. cout << " --------------------" << endl;
  210. for(int i=0; i<stulpeliai; i++)
  211. {
  212. cout << i << "| ";
  213. for(int j=0; j<eilutes; j++)
  214. {
  215. cout <<lenteleZm[j][i] << " ";
  216. }
  217. cout << endl;
  218. }
  219.  
  220. cout << " " << endl;
  221. cout << " CPU lenta" << endl;
  222. cout << " Cpu laivai " << laivaicpu << endl;
  223. cout << " 0 1 2 3 4 5 6 7 8 9" << endl;
  224. cout << " --------------------" << endl;
  225. for(int i=0; i<stulpeliai; i++)
  226. {
  227. cout << i << "| ";
  228. for(int j=0; j<eilutes; j++)
  229. {
  230. cout <<NujaLentCpu[j][i] << " ";
  231. }
  232. cout << endl;
  233. }
  234.  
  235. }
  236.  
  237.  
  238.  
  239. int main()
  240. {
  241. pradzia();
  242.  
  243. spam();
  244. bool pabaiga=true;
  245. while(pabaiga)
  246. {
  247. spausdinti();
  248. saudymas();
  249. saudymascpu();
  250. if(laivaicpu==0 || laivaizm==0)
  251. pabaiga=false;
  252. }
  253. if(laivaicpu==0)
  254. {
  255. cout << "Laimejo cpu" << endl;
  256. }
  257. else
  258. cout << "Laimejai!" << endl;
  259.  
  260. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement