Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cstdlib>
- char plansza[3][3];
- void czysc_plansze(void);
- void rysuj_plansze(void);
- void pobierz_wspolrzedne(int gracz);
- int sprawdz_kto_wygral(void);
- int main(void)
- {
- int gracz=0,koniec;
- printf("\n\n\nWitaj w grze kolko i kolko \n\n\n");
- czysc_plansze();
- do
- {
- rysuj_plansze();
- gracz=!gracz;
- pobierz_wspolrzedne(gracz);
- koniec = sprawdz_kto_wygral();
- }
- while(koniec!=0);
- rysuj_plansze();
- printf("\n\n\nKoniec gry !!! \n\n\n");
- system("PAUSE");
- return 0;
- }
- void czysc_plansze(void)
- {
- int x,y;
- for (y=0;y<3;y++)
- {
- for(x=0;x<3;x++)
- {
- plansza[y][x]=' ';
- }
- }
- return;
- }
- void rysuj_plansze(void)
- {
- int x,y;
- printf("\n\n\n");
- for (y=0;y<3;y++)
- {
- for (x=0;x<3;x++)
- {
- printf("+---");
- }
- printf("+\n");
- for(x=0;x<3;x++)
- {
- printf("| %c ",plansza[y][x]);
- }
- printf("|\n");
- }
- for (x=0;x<3;x++)
- {
- printf("+---");
- }
- printf("+\n");
- return;
- }
- void pobierz_wspolrzedne (int gracz)
- {
- int x,y;
- char znak;
- if (gracz==0)
- {
- znak='o';
- }
- else
- znak='x';
- do
- {
- do
- {
- printf("Podaj wspolrzedne x gracza %c:",znak);
- scanf("%d",&x);
- }
- while(x<1||x>3);
- do
- {
- printf("Podaj wspolrzedne y gracza %c:",znak);
- scanf("%d",&y);
- }
- while(y<1||y>3);
- }
- while(plansza[y-1][x-1] != ' ');
- plansza[y-1][x-1]=znak;
- return;
- }
- int sprawdz_kto_wygral(void)
- {
- int x,y,licz;
- licz=0;
- for(y=0;y<3;y++)
- {
- for(x=0;x<3;x++)
- {
- if(plansza[y][x]==' ')
- {
- licz++;
- }
- }
- }
- if(!licz)
- {
- printf("n\n\n\nBrak wolnych pol - Remis!!!\n\n\n");
- return(0);
- }
- return(1);
- }
Add Comment
Please, Sign In to add comment