Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
97
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 <stdio.h>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. void help ()
  8. {
  9. int c=0;
  10. c=getchar();
  11. if (c == '?')
  12. {
  13. cout<<"Dostepne operacje:"<<endl;
  14. cout<<"ESC-wyjscie z gry"<<endl;
  15. cout<<"'?' - pomoc"<<endl;
  16. }
  17.  
  18. }
  19.  
  20.  
  21. void plansza (char t[30][30], int szer, int wys)
  22. {
  23. for(int a=1; a<=szer; a++)
  24. {
  25. cout<<a<<" ";
  26. }
  27. cout<<endl;
  28. for (int i=1; i<=wys; i++)
  29. {
  30. for(int j=1; j<=szer; j++)
  31. {
  32. cout<<t[i][j]<<"|";
  33. }
  34. cout<<endl;
  35. }
  36. }
  37.  
  38. void ruch (char t[30][30], int szer, int wys, char gracz)
  39. {
  40. plansza(t, szer, wys);
  41. int r=0;
  42. if (gracz=='O')
  43. {
  44. cout<<"Ruch gracza O"<<" ";
  45. }
  46. else
  47. {
  48. cout<<"Ruch gracza X"<<" ";
  49. }
  50.  
  51.  
  52.  
  53. cin>>r;
  54. if((r>=1)&&(r<=szer)&&(t[1][r]!='X')&&(t[1][r]!='O'))
  55. {
  56. for(int j=wys; j>0; j--)
  57. {
  58. if (t[j][r]==' ')
  59. {
  60. t[j][r] = gracz;
  61. break;
  62. }
  63. }
  64. }
  65.  
  66.  
  67. else
  68. {
  69. cout<<"Zly ruch"<<endl;
  70. ruch(t, szer, wys, gracz);
  71. }
  72.  
  73. cout<<endl<<endl;
  74.  
  75. }
  76.  
  77. bool winPozX(char t[30][30], int lp, int szer, int wys)
  78. {
  79. int a=0;
  80. for (int i=1; i<=wys; i++)
  81. {
  82. for(int j=1; j<=szer; j++)
  83. {
  84. for(int b=1; b<lp; b++)
  85. {
  86. if ((t[i][j]=='X')&&(t[i][j+b]=='X'))
  87. {
  88. a++;
  89. }
  90. else
  91. {
  92. break;
  93. }
  94. }
  95. }
  96. }
  97. if (a>=lp)
  98. {
  99. cout<<"Zwyciestwo gracza X!"<<endl;
  100. return true;
  101. }
  102. return false;
  103. }
  104.  
  105. bool winPozO(char t[30][30], int lp, int szer, int wys)
  106. {
  107. int a=0;
  108.  
  109. for (int i=1; i<=wys; i++)
  110. {
  111. for(int j=1; j<=szer; j++)
  112. {
  113. for(int b=1; b<lp; b++)
  114. {
  115. if ((t[i][j]=='O')&&(t[i][j+b]=='O'))
  116. {
  117. a++;
  118. }
  119. else
  120. {
  121. break;
  122. }
  123. }
  124. }
  125.  
  126. }
  127. if (a>=lp)
  128. {
  129. cout<<"Zwyciestwo gracza O!"<<endl;
  130. return true;
  131. }
  132. return false;
  133. }
  134.  
  135. bool winPionX(char t[30][30], int lp, int szer, int wys)
  136. {
  137. int a=0;
  138. for (int i=0; i<wys; i++)
  139. {
  140.  
  141. for(int j=0; j<szer; j++)
  142. {
  143. for(int b=1; b<lp; b++)
  144. {
  145. if ((t[i][j]=='X')&&(t[i+b][j]=='X'))
  146. {
  147. a++;
  148. }
  149. else break;
  150. }
  151. }
  152.  
  153. }
  154. if (a>=lp)
  155. {
  156. cout<<"Zwyciestwo gracza X!"<<endl;
  157. return true;
  158. }
  159. return false;
  160. }
  161.  
  162. bool winPionO(char t[30][30], int lp, int szer, int wys)
  163. {
  164. int a=0;
  165. for (int i=0; i<wys; i++)
  166. {
  167. for(int j=0; j<szer; j++)
  168. {
  169. for(int b=1; b<lp; b++)
  170.  
  171. if ((t[i][j]=='O')&&(t[i+b][j]=='O'))
  172. {
  173.  
  174. a++;
  175.  
  176. }
  177. else break;
  178. }
  179. }
  180.  
  181.  
  182. if (a>=lp)
  183. {
  184. cout<<"Zwyciestwo gracza O!"<<endl;
  185. return true;
  186. }
  187. return false;
  188. }
  189. bool winSkosDolX(char t[30][30], int lp, int szer, int wys)
  190. {
  191. int a=0;
  192. for (int i=0; i<wys; i++)
  193. {
  194.  
  195. for(int j=0; j<szer; j++)
  196. {
  197. for(int b=1; b<lp; b++)
  198. {
  199. if ((t[i][j]=='X')&&(t[i+b][j+b]=='X'))
  200. {
  201. a++;
  202. }
  203. else break;
  204. }
  205. }
  206. }
  207.  
  208.  
  209. if (a>=lp)
  210. {
  211. cout<<"Zwyciestwo gracza X!"<<endl;
  212. return true;
  213. }
  214. return false;
  215. }
  216.  
  217. bool winSkosDolO(char t[30][30], int lp, int szer, int wys)
  218. {
  219. int a=0;
  220. for (int i=0; i<wys; i++)
  221. {
  222.  
  223. for(int j=0; j<szer; j++)
  224. {
  225. for(int b=1; b<lp; b++)
  226. {
  227. if ((t[i][j]=='O')&&(t[i+b][j+b]=='O'))
  228. {
  229. a++;
  230. }
  231. else break;
  232. }
  233. }
  234.  
  235. }
  236. if (a>=lp)
  237. {
  238. cout<<"Zwyciestwo gracza O!"<<endl;
  239. return true;
  240. }
  241. return false;
  242. }
  243.  
  244. bool winSkosGoraX(char t[30][30], int lp, int szer, int wys)
  245. {
  246. int a=0;
  247. for (int i=0; i<wys; i++)
  248. {
  249.  
  250. for(int j=0; j<szer; j++)
  251. {
  252. for(int b=1; b<lp; b++)
  253. {
  254. if ((t[i][j]=='X')&&(t[i-b][j+b]=='X'))
  255. {
  256. a++;
  257. }
  258. else break;
  259. }
  260. }
  261.  
  262. }
  263. if (a>=lp)
  264. {
  265. cout<<"Zwyciestwo gracza X!"<<endl;
  266. return true;
  267. }
  268. return false;
  269. }
  270.  
  271. bool winSkosGoraO(char t[30][30], int lp, int szer, int wys)
  272. {
  273. int a=0;
  274.  
  275. for (int i=0; i<wys; i++)
  276. {
  277.  
  278. for(int j=0; j<szer; j++)
  279. {
  280. for(int b=1; b<lp; b++)
  281. {
  282. if ((t[i][j]=='O')&&(t[i-b][j+b]=='O'))
  283. {
  284. a++;
  285. }
  286. else break;
  287. }
  288. }
  289.  
  290. }
  291. if (a>=lp)
  292. {
  293. cout<<"Zwyciestwo gracza O!"<<endl;
  294. return true;
  295. }
  296. return false;
  297. }
  298.  
  299. bool remis (char t[30][30], int lp, int szer, int wys)
  300. {
  301. if ((winPozX(t, lp, szer, wys)==false)&&(winPozO(t, lp, szer, wys)==false)&&(winPionX(t, lp, szer, wys)==false)&&(winPionO(t, lp, szer, wys)==false)
  302. &&(winSkosDolX(t, lp, szer, wys)==false)&&(winSkosDolO(t, lp, szer, wys)==false)&&(winSkosGoraX(t, lp, szer, wys)==false)&&(winSkosGoraO(t, lp, szer, wys)==false))
  303. {
  304. cout<<"Remis!"<<endl;
  305. return true;
  306. }
  307. else return false;
  308. }
  309.  
  310.  
  311. int main()
  312. {
  313. do
  314. {
  315. int wys, szer, lp;
  316. int c;
  317. char t[30][30];
  318. char g;
  319. int liczbar=0;
  320. int k=0;
  321. while
  322. cout<<"Witaj w tej prostej grze, zanim zaczniemy nalezy podac nastepujace dane:"<<endl;
  323. cout<<"Wysokosc planszy (1,30)"<<" ";
  324. cin>>wys;
  325. cout<<endl;
  326. cout<<"Szerokosc planszy(1,30)"<<" ";
  327. cin>>szer;
  328. cout<<endl;
  329. cout<<"Liczba punktow potrzebna do zwyciestwa"<<" ";
  330. cin>>lp;
  331. cout<<endl;
  332. liczbar=szer*wys;
  333.  
  334.  
  335. if((szer>=1)&&(szer<=30)&&(wys>=1)&&(wys<=30)&&(lp>=1)&&(lp<=liczbar))
  336. {
  337. for (int i=1; i<=wys; i++)
  338. {
  339. for(int j=1; j<=szer; j++)
  340. {
  341. t[i][j]=' ';
  342. }
  343. cout<<endl;
  344. }
  345.  
  346.  
  347. for (int a=0; a<liczbar; a++)
  348. {
  349. if (a%2==1) g='X';
  350. else g='O';
  351. if((winPozX(t, lp, szer, wys)==false)&&(winPozO(t, lp, szer, wys)==false)&&(winPionX(t, lp, szer, wys)==false)&&(winPionO(t, lp, szer, wys)==false)
  352. &&(winSkosDolX(t, lp, szer, wys)==false)&&(winSkosDolO(t, lp, szer, wys)==false)&&(winSkosGoraX(t, lp, szer, wys)==false)&&(winSkosGoraO(t, lp, szer, wys)==false))
  353.  
  354. {
  355. ruch(t, szer, wys, g);
  356. }
  357. else
  358. {
  359. plansza(t, szer, wys);
  360. return 0;
  361. }
  362.  
  363. }
  364. remis(t, lp, szer, wys);
  365. } while
  366. cout<<"Koniec gry"<<endl;
  367. }
  368. else cout<<"Zle dane"<<endl;
  369. koniec:
  370. return 0;
  371.  
  372. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement