Guest User

Untitled

a guest
Dec 17th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cstdlib>
  3. char plansza[3][3];
  4. void czysc_plansze(void);
  5. void rysuj_plansze(void);
  6. void pobierz_wspolrzedne(int gracz);
  7. int sprawdz_kto_wygral(void);
  8. int main(void)
  9. {
  10. int gracz=0,koniec;
  11. printf("\n\n\nWitaj w grze kolko i kolko \n\n\n");
  12. czysc_plansze();
  13.  
  14.  
  15. do
  16. {
  17. rysuj_plansze();
  18. gracz=!gracz;
  19. pobierz_wspolrzedne(gracz);
  20. koniec = sprawdz_kto_wygral();
  21. }
  22.  
  23. while(koniec!=0);
  24.  
  25. rysuj_plansze();
  26. printf("\n\n\nKoniec gry !!! \n\n\n");
  27. system("PAUSE");
  28. return 0;
  29. }
  30.  
  31.  
  32. void czysc_plansze(void)
  33. {
  34. int x,y;
  35. for (y=0;y<3;y++)
  36. {
  37. for(x=0;x<3;x++)
  38. {
  39. plansza[y][x]=' ';
  40. }
  41. }
  42. return;
  43. }
  44.  
  45.  
  46. void rysuj_plansze(void)
  47. {
  48. int x,y;
  49. printf("\n\n\n");
  50. for (y=0;y<3;y++)
  51. {
  52. for (x=0;x<3;x++)
  53. {
  54. printf("+---");
  55. }
  56. printf("+\n");
  57. for(x=0;x<3;x++)
  58. {
  59. printf("| %c ",plansza[y][x]);
  60. }
  61. printf("|\n");
  62. }
  63.  
  64. for (x=0;x<3;x++)
  65. {
  66. printf("+---");
  67. }
  68. printf("+\n");
  69. return;
  70. }
  71.  
  72. void pobierz_wspolrzedne (int gracz)
  73. {
  74. int x,y;
  75. char znak;
  76. if (gracz==0)
  77. {
  78. znak='o';
  79. }
  80. else
  81. znak='x';
  82. do
  83. {
  84. do
  85. {
  86. printf("Podaj wspolrzedne x gracza %c:",znak);
  87. scanf("%d",&x);
  88. }
  89. while(x<1||x>3);
  90. do
  91. {
  92. printf("Podaj wspolrzedne y gracza %c:",znak);
  93. scanf("%d",&y);
  94. }
  95. while(y<1||y>3);
  96. }
  97. while(plansza[y-1][x-1] != ' ');
  98. plansza[y-1][x-1]=znak;
  99. return;
  100. }
  101. int sprawdz_kto_wygral(void)
  102. {
  103. int x,y,licz;
  104.  
  105. licz=0;
  106. for(y=0;y<3;y++)
  107. {
  108. for(x=0;x<3;x++)
  109. {
  110. if(plansza[y][x]==' ')
  111. {
  112. licz++;
  113. }
  114. }
  115. }
  116. if(!licz)
  117. {
  118. printf("n\n\n\nBrak wolnych pol - Remis!!!\n\n\n");
  119. return(0);
  120. }
  121. return(1);
  122. }
Add Comment
Please, Sign In to add comment