SHOW:
|
|
- or go back to the newest paste.
1 | #include <iostream> | |
2 | ||
3 | using namespace std; | |
4 | int a,b; | |
5 | void bicie(char plansza[][8],char wybor,int a, int b); | |
6 | void rysuj_plansze(char plansza[][8], char wybor) | |
7 | { | |
8 | for(int i=0; i<8; i++) | |
9 | { | |
10 | cout << " " << i+1; | |
11 | } | |
12 | cout << " Ruch "<<wybor <<endl ; | |
13 | for(int i=0; i<8; i++) | |
14 | { | |
15 | cout << i+1; | |
16 | if(plansza[i][0]=='C') | |
17 | { | |
18 | cout << "[C]"; | |
19 | } | |
20 | else if(plansza[i][0]=='B') | |
21 | { | |
22 | cout << "[B]"; | |
23 | } | |
24 | else if (plansza[i][0]==' ') | |
25 | { | |
26 | cout<< "[ ]"; | |
27 | } | |
28 | else if (plansza[i][0]=='a') | |
29 | { | |
30 | cout<< "[1]"; | |
31 | } | |
32 | else if (plansza[i][0]=='b') | |
33 | { | |
34 | cout<< "[2]"; | |
35 | } | |
36 | else if (plansza[i][0]=='c') | |
37 | { | |
38 | cout<< "[3]"; | |
39 | } | |
40 | else if (plansza[i][0]=='d') | |
41 | { | |
42 | cout<< "[4]"; | |
43 | } | |
44 | ||
45 | for(int j=1; j<8; j++) | |
46 | { | |
47 | if(plansza[i][j]=='C') | |
48 | { | |
49 | cout << "[C]"; | |
50 | } | |
51 | else if(plansza[i][j]=='B') | |
52 | { | |
53 | cout << "[B]"; | |
54 | } | |
55 | ||
56 | else if(plansza[i][j]==' ') | |
57 | { | |
58 | cout << "[ ]"; | |
59 | } | |
60 | else if (plansza[i][j]=='a') | |
61 | { | |
62 | cout << "[1]"; | |
63 | } | |
64 | else if (plansza[i][j]=='b') | |
65 | { | |
66 | cout << "[2]"; | |
67 | } | |
68 | else if (plansza[i][j]=='c') | |
69 | { | |
70 | cout << "[3]"; | |
71 | } | |
72 | else if (plansza[i][j]=='d') | |
73 | { | |
74 | cout << "[4]"; | |
75 | } | |
76 | } | |
77 | ||
78 | cout <<endl; | |
79 | } | |
80 | ||
81 | ||
82 | } | |
83 | void biale(char plansza[][8]) | |
84 | { | |
85 | int i,j,k=0; | |
86 | for( i=0,j=0; k<12;) | |
87 | { | |
88 | plansza[i][j]='B'; | |
89 | j+=2; | |
90 | if(j==8) | |
91 | { | |
92 | j=1; | |
93 | i++; | |
94 | } | |
95 | else if(j==9) | |
96 | { | |
97 | j=0; | |
98 | i++; | |
99 | } | |
100 | k++; | |
101 | } | |
102 | } | |
103 | void czarne(char plansza[][8]) | |
104 | { | |
105 | int i,j,k=0; | |
106 | for( i=7,j=7; k<12;) | |
107 | { | |
108 | plansza[i][j]='C'; | |
109 | j=j-2; | |
110 | if(j==-2) | |
111 | { | |
112 | j=7; | |
113 | i--; | |
114 | } | |
115 | else if(j==-1) | |
116 | { | |
117 | j=6; | |
118 | i--; | |
119 | } | |
120 | k++; | |
121 | } | |
122 | } | |
123 | void nowa_gra(char plansza[][8]) | |
124 | { | |
125 | for(int i=0; i<8; i++) | |
126 | { | |
127 | plansza[i][0]=' '; | |
128 | for(int j=1; j<8; j++) | |
129 | { | |
130 | plansza[i][j]=' '; | |
131 | } | |
132 | } | |
133 | //biale(plansza); | |
134 | //czarne(plansza); | |
135 | plansza[3][3]='B'; | |
136 | plansza[3][5]='B'; | |
137 | plansza[4][4]='C'; | |
138 | } | |
139 | void sprawdz_plansze(char plansza[][8]) // ta funkcja sprawdza jaka wartosc przyjmuje poszczegolna plansza[][]. | |
140 | { | |
141 | for(int i=0; i<8;i++) | |
142 | { | |
143 | char ocb; | |
144 | ocb=plansza[i][0]; | |
145 | cout<< " plansza["<<i<<"][0]= "<< ocb; | |
146 | cout<< endl; | |
147 | for(int j=1; j<8;j++) | |
148 | { | |
149 | ocb=plansza[i][j]; | |
150 | cout<< " plansza["<<i<<"]["<<j<<"]= "<< ocb; | |
151 | cout << endl; | |
152 | ||
153 | } | |
154 | ||
155 | } | |
156 | } | |
157 | void wybor_kapsla(char plansza[][8],char wybor) // ta funkcja jest zaimplementowana bezposrednio w ruchu, na ta chwile nie potrafie korzystac z niej bezposrednio w innej funkcji. | |
158 | { | |
159 | int a,b; | |
160 | if(wybor=='B') | |
161 | { | |
162 | cout << "Wybierz kapsel: Ruch: Bia³y" ; | |
163 | } | |
164 | if(wybor=='C') | |
165 | { | |
166 | cout << "Wybierz kapsel: Ruch: Czerwony" ; | |
167 | } | |
168 | cin >> a >> b; | |
169 | a-=1; | |
170 | b-=1; | |
171 | plansza[a][b]=wybor; | |
172 | } | |
173 | void ruch_B(char plansza[][8],char wybor) | |
174 | { | |
175 | /////////////////wybor kapsla///////////////////////////////////// | |
176 | int a,b; | |
177 | char tymczas_a,tymczas_b; | |
178 | ||
179 | do | |
180 | { | |
181 | cout << "Wybierz kapsel: "; | |
182 | cin >> a >> b; | |
183 | a-=1; | |
184 | b-=1; | |
185 | ||
186 | if(plansza[a+1][b-1]!=' '&& plansza[a+1][b-1]==wybor && plansza[a+1][b+1]!=' ' && plansza[a+1][b+1]==wybor || | |
187 | b==0 && plansza[a+1][b+1]!=' ' && plansza[a+1][b+1]==wybor || b==7 && plansza[a+1][b-1]!=' ' && plansza[a+1][b-1]==wybor) | |
188 | { | |
189 | cout<< "Nie mozesz ruszyc sie tym kapslem..." << endl; | |
190 | } | |
191 | else if(plansza[a][b]==' ') | |
192 | { | |
193 | cout << "Wybrales puste pole" <<endl; | |
194 | } | |
195 | ||
196 | ||
197 | } | |
198 | while(plansza[a+1][b-1]!=' ' && plansza[a+1][b-1]==wybor && plansza[a+1][b+1]!=' ' && plansza[a+1][b+1]==wybor || | |
199 | b==0 && plansza[a+1][b+1]!=' ' && plansza[a+1][b+1]==wybor || | |
200 | b==7 && plansza[a+1][b-1]!=' ' && plansza[a+1][b-1]==wybor || | |
201 | plansza[a][b]==' '); | |
202 | ||
203 | plansza[a][b]=wybor; | |
204 | ////zajmuje tymczasowe miejsce miejsc na planszy zeby pozniej je oddac ////// | |
205 | tymczas_a=plansza[a+1][b-1]; | |
206 | tymczas_b=plansza[a+1][b+1]; | |
207 | ||
208 | //////////Jeśli bedzie bicie to ta komedna pomija zaznaczanie ruchu pionka////// | |
209 | if(plansza[a-1][b-1]!=wybor && plansza[a-1][b-1]!=' '||plansza[a-1][b+1]!=wybor && plansza[a-1][b+1]!=' ' || | |
210 | plansza[a+1][b-1]!=wybor && plansza[a+1][b-1]!=' ' ||plansza[a+1][b+1]!=wybor && plansza[a+1][b+1]!=' ' ) | |
211 | { | |
212 | if(plansza[a-2][b-2]==' ' ||plansza[a-2][b+2]==' ' || | |
213 | plansza[a+2][b-2]==' ' ||plansza[a+2][b+2]==' ' ) | |
214 | { | |
215 | return; | |
216 | } | |
217 | } | |
218 | ||
219 | //////Zaznaczamy na planszy jak moze ruszac sie kapsel///////////////////////////// | |
220 | if(plansza[a+1][b-1]==' ' && plansza[a+1][b+1]==' ' && b>0 && b<7) | |
221 | { | |
222 | plansza[a+1][b-1]='a'; | |
223 | plansza[a+1][b+1]='b'; | |
224 | } | |
225 | else if(plansza[a+1][b-1]!=' '|| b==0) | |
226 | { | |
227 | plansza[a+1][b+1]='b'; | |
228 | } | |
229 | else if(plansza[a+1][b+1]!=' ' || b==7) | |
230 | { | |
231 | plansza[a+1][b-1]='a'; | |
232 | } | |
233 | ||
234 | ////////////////////// | |
235 | ||
236 | ||
237 | /////////////////ruch///////////////////////////////////////////// | |
238 | int rusz_sie; | |
239 | cout << "gdzie chcesz sie ruszyc? "<< endl; | |
240 | rysuj_plansze(plansza, wybor); | |
241 | ||
242 | ////////// oddaje tymczasowe ////////////// | |
243 | plansza[a+1][b-1]=tymczas_a; | |
244 | plansza[a+1][b+1]=tymczas_b; | |
245 | ////////////////////////////////////////// | |
246 | ||
247 | cin>> rusz_sie; | |
248 | ////////////////wybiera pole ktore nie jest zajete/////////////////////////////////////// | |
249 | if(plansza[a+1][b-1]!=' ' || b==0) | |
250 | { | |
251 | switch (rusz_sie) | |
252 | { | |
253 | case 2: | |
254 | { | |
255 | plansza[a][b]=' '; | |
256 | plansza[a+1][b+1]=wybor; | |
257 | } | |
258 | ||
259 | break; | |
260 | default: cout << "nie mozesz tego zrobic." << endl; | |
261 | } | |
262 | } | |
263 | else if(plansza[a+1][b+1]!=' ' || b==7) | |
264 | { | |
265 | switch (rusz_sie) | |
266 | { | |
267 | case 1: | |
268 | { | |
269 | plansza[a][b]=' '; | |
270 | plansza[a+1][b-1]=wybor; | |
271 | } | |
272 | ||
273 | break; | |
274 | } | |
275 | } | |
276 | else | |
277 | { | |
278 | switch (rusz_sie) | |
279 | { | |
280 | case 2: | |
281 | if (plansza[a+1][b+1]==' ') | |
282 | { | |
283 | plansza[a][b]=' '; | |
284 | plansza[a+1][b+1]=wybor; | |
285 | } | |
286 | else cout << "Nie mozesz tego zrobic."; | |
287 | break; | |
288 | case 1: | |
289 | if (plansza[a+1][b-1]==' ') | |
290 | { | |
291 | plansza[a][b]=' '; | |
292 | plansza[a+1][b-1]=wybor; | |
293 | } | |
294 | else cout << "Nie mozesz tego zrobic."; | |
295 | break; | |
296 | } | |
297 | ||
298 | } | |
299 | ///////////////////////////////////////////////////////////////////////// | |
300 | ||
301 | } | |
302 | void ruch_C(char plansza[][8],char wybor) | |
303 | { | |
304 | /////////////////wybor kapsla///////////////////////////////////// | |
305 | //int a,b; | |
306 | char tymczas_a,tymczas_b; | |
307 | ||
308 | do | |
309 | { | |
310 | cout << "Wybierz kapsel: "; | |
311 | cin >> a >> b; | |
312 | a-=1; | |
313 | b-=1; | |
314 | ||
315 | if(plansza[a-1][b-1]!=' '&& plansza[a-1][b-1]==wybor && plansza[a-1][b+1]!=' ' && plansza[a-1][b+1]==wybor || | |
316 | b==0 && plansza[a-1][b+1]!=' ' && plansza[a-1][b+1]==wybor || b==7 && plansza[a-1][b-1]!=' ' && plansza[a-1][b-1]==wybor) | |
317 | { | |
318 | cout<< "Nie mozesz ruszyc sie tym kapslem..." << endl; | |
319 | } | |
320 | else if(plansza[a][b]==' ') | |
321 | { | |
322 | cout << "Wybrales puste pole" <<endl; | |
323 | } | |
324 | ||
325 | ||
326 | } | |
327 | while(plansza[a-1][b-1]!=' '&& plansza[a-1][b-1]==wybor && plansza[a-1][b+1]!=' '&& plansza[a-1][b+1]==wybor || | |
328 | b==0 && plansza[a-1][b+1]!=' '&& plansza[a-1][b+1]==wybor|| | |
329 | b==7 && plansza[a-1][b-1]!=' '&& plansza[a-1][b-1]==wybor|| | |
330 | plansza[a][b]==' '); | |
331 | ||
332 | plansza[a][b]=wybor; | |
333 | ////zajmuje tymczasowe miejsce miejsc na planszy zeby pozniej je oddac ////// | |
334 | tymczas_a=plansza[a-1][b-1]; | |
335 | tymczas_b=plansza[a-1][b+1]; | |
336 | ||
337 | //////////Jeśli bedzie bicie to ta komedna pomija zaznaczanie ruchu pionka////// | |
338 | if(plansza[a-1][b-1]!=wybor && plansza[a-1][b-1]!=' '||plansza[a-1][b+1]!=wybor && plansza[a-1][b+1]!=' ' || | |
339 | plansza[a+1][b-1]!=wybor && plansza[a+1][b-1]!=' ' ||plansza[a+1][b+1]!=wybor && plansza[a+1][b+1]!=' ' ) | |
340 | { | |
341 | if(plansza[a-2][b-2]==' ' ||plansza[a-2][b+2]==' ' || | |
342 | plansza[a+2][b-2]==' ' ||plansza[a+2][b+2]==' ' ) | |
343 | { | |
344 | return; | |
345 | } | |
346 | } | |
347 | ||
348 | //////Zaznaczamy na planszy jak moze ruszac sie kapsel///////////////////////////// | |
349 | if(plansza[a-1][b-1]==' ' && plansza[a-1][b+1]==' ' && b>0 && b<7) | |
350 | { | |
351 | plansza[a-1][b-1]='a'; | |
352 | plansza[a-1][b+1]='b'; | |
353 | } | |
354 | else if(plansza[a-1][b-1]!=' '|| b==0) | |
355 | { | |
356 | plansza[a-1][b+1]='b'; | |
357 | } | |
358 | else if(plansza[a-1][b+1]!=' ' || b==7) | |
359 | { | |
360 | plansza[a-1][b-1]='a'; | |
361 | } | |
362 | ||
363 | ////////////////////// | |
364 | ||
365 | ||
366 | /////////////////ruch///////////////////////////////////////////// | |
367 | int rusz_sie; | |
368 | cout << "gdzie chcesz sie ruszyc? "<< endl; | |
369 | rysuj_plansze(plansza,wybor); | |
370 | ||
371 | ////////// oddaje tymczasowe ////////////// | |
372 | plansza[a-1][b-1]=tymczas_a; | |
373 | plansza[a-1][b+1]=tymczas_b; | |
374 | ////////////////////////////////////////// | |
375 | ||
376 | cin>> rusz_sie; | |
377 | ////////////////wybiera pole ktore nie jest zajete/////////////////////////////////////// | |
378 | if(plansza[a-1][b-1]!=' ' || b==0) | |
379 | { | |
380 | switch (rusz_sie) | |
381 | { | |
382 | case 2: | |
383 | { | |
384 | plansza[a][b]=' '; | |
385 | plansza[a-1][b+1]=wybor; | |
386 | } | |
387 | ||
388 | break; | |
389 | default: cout << "nie mozesz tego zrobic." << endl; | |
390 | } | |
391 | } | |
392 | else if(plansza[a-1][b+1]!=' ' || b==7) | |
393 | { | |
394 | switch (rusz_sie) | |
395 | { | |
396 | case 1: | |
397 | { | |
398 | plansza[a][b]=' '; | |
399 | plansza[a-1][b-1]=wybor; | |
400 | } | |
401 | ||
402 | break; | |
403 | } | |
404 | } | |
405 | else | |
406 | { | |
407 | switch (rusz_sie) | |
408 | { | |
409 | case 2: | |
410 | if (plansza[a-1][b+1]==' ') | |
411 | { | |
412 | plansza[a][b]=' '; | |
413 | plansza[a-1][b+1]=wybor; | |
414 | } | |
415 | else cout << "Nie mozesz tego zrobic."; | |
416 | break; | |
417 | case 1: | |
418 | if (plansza[a-1][b-1]==' ') | |
419 | { | |
420 | plansza[a][b]=' '; | |
421 | plansza[a-1][b-1]=wybor; | |
422 | } | |
423 | else cout << "Nie mozesz tego zrobic."; | |
424 | break; | |
425 | } | |
426 | ||
427 | } | |
428 | ///////////////////////////////////////////////////////////////////////// | |
429 | ||
430 | } | |
431 | void bicie(char plansza[][8],char wybor,int a, int b) | |
432 | { | |
433 | int ruch; | |
434 | if(plansza[a-1][b-1]!=wybor ||plansza[a-1][b+1]!=wybor || | |
435 | plansza[a+1][b-1]!=wybor ||plansza[a+1][b+1]!=wybor ) | |
436 | { | |
437 | if(plansza[a-2][b-2]==' ' ||plansza[a-2][b+2]==' ' || | |
438 | plansza[a+2][b-2]==' ' ||plansza[a+2][b+2]==' ' ) | |
439 | { | |
440 | char tymczas_a,tymczas_b,tymczas_c,tymczas_d; | |
441 | tymczas_a = plansza[a-2][b-2]; | |
442 | tymczas_b = plansza[a-2][b+2]; | |
443 | tymczas_c = plansza[a+2][b-2]; | |
444 | tymczas_d = plansza[a+2][b+2]; | |
445 | ||
446 | if(b>0 && b<7 && plansza[a-2][b-2]==' ' && plansza[a-1][b-1]!=wybor && plansza[a-1][b-1]!=' ') | |
447 | { | |
448 | plansza[a-2][b-2]='a'; | |
449 | } | |
450 | if(b>0 && b<7 && plansza[a-2][b+2]==' ' && plansza[a-1][b+1]!=wybor && plansza[a-1][b+1]!=' ') | |
451 | { | |
452 | plansza[a-2][b+2]='b'; | |
453 | } | |
454 | if(b>0 && b<7 && plansza[a+2][b-2]==' ' && plansza[a+1][b-1]!=wybor && plansza[a+1][b-1]!=' ') | |
455 | { | |
456 | plansza[a+2][b-2]='c'; | |
457 | } | |
458 | if(b>0 && b<7 && plansza[a+2][b+2]==' ' && plansza[a+1][b+1]!=wybor && plansza[a+1][b+1]!=' ') | |
459 | { | |
460 | plansza[a+2][b+2]='d'; | |
461 | } | |
462 | rysuj_plansze(plansza,wybor); | |
463 | cout << "gdzie bicie? "<< endl; | |
464 | //// oddaje tymczasowe //////////////////// | |
465 | // plansza[a-2][b-2] = tymczas_a; | |
466 | // plansza[a-2][b+2] = tymczas_b; | |
467 | // plansza[a+2][b-2] = tymczas_c; | |
468 | // plansza[a+2][b+2] = tymczas_d; | |
469 | ///////////////////////////////////////////// | |
470 | ||
471 | // cin >> ruch; | |
472 | /* | |
473 | switch (ruch) | |
474 | { | |
475 | case 1: | |
476 | if(plansza[a-2][b-2]==' ') | |
477 | { | |
478 | plansza[a-2][b-2]=wybor; | |
479 | } | |
480 | ||
481 | case 2: | |
482 | if(plansza[a-2][b+2]==' ') | |
483 | { | |
484 | plansza[a-2][b+2]=wybor; | |
485 | } | |
486 | case 3: | |
487 | if(plansza[a+2][b-2]==' ') | |
488 | { | |
489 | plansza[a+2][b-2]=wybor; | |
490 | } | |
491 | case 4: | |
492 | if(plansza[a+2][b+2]==' ') | |
493 | { | |
494 | plansza[a+2][b+2]=wybor; | |
495 | } | |
496 | break; | |
497 | ||
498 | }*/ | |
499 | } | |
500 | } | |
501 | } | |
502 | int main() | |
503 | { | |
504 | char plansza [8][8]; | |
505 | char wybor='B'; | |
506 | nowa_gra(plansza); | |
507 | //biale(plansza); | |
508 | //rysuj_plansze(plansza, wybor); | |
509 | //wybor_kapsla(plansza,wybor); | |
510 | while(1) | |
511 | { | |
512 | wybor='B'; | |
513 | rysuj_plansze(plansza, wybor); | |
514 | ruch_B(plansza,wybor); | |
515 | bicie(plansza,wybor,a,b); | |
516 | rysuj_plansze(plansza, wybor); | |
517 | wybor='C'; | |
518 | rysuj_plansze(plansza, wybor); | |
519 | ruch_C(plansza,wybor); | |
520 | bicie(plansza,wybor,a,b); | |
521 | rysuj_plansze(plansza, wybor); | |
522 | //sprawdz_plansze(plansza); | |
523 | } | |
524 | return 0; | |
525 | } |