Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdbool.h>
  4.  
  5. //indica a posição a ser jogada
  6. bool posicao (int posi1[], int posi2[]);
  7. //define os jogadores e registra o nome
  8. void jogadores (char nome1[], char nome2 []);
  9. //imprime o tabuleiro
  10. void tabuleiro (char tab[3][3]);
  11. //registra a posição no tabuleiro
  12. void marcacao (char tab[3][3], int posicaoL[], int posicaoC[], bool simbolo);
  13. //informa de quem é a vez e qual a peça
  14. void imprimevez (char nome[], bool simbolo);
  15. //informa o vencedor
  16. bool vencedor ( char tab[3][3], char nome1[]);
  17.  
  18. int main()
  19. {
  20. char nome1[20];
  21. char nome2[20];
  22. char tab[3][3]={{'-','-','-'},{'-','-','-'},{'-','-','-'},};
  23. int lin=0, col=0;
  24. int *posicaoL=&lin, *posicaoC=&col;
  25. bool simbolo=true, venceu=true;
  26. jogadores(nome1,nome2);
  27. tabuleiro(tab);
  28. for(;;){
  29. simbolo=true;
  30. imprimevez(nome1,simbolo);
  31. posicao(posicaoL, posicaoC);
  32. marcacao(tab, posicaoL, posicaoC, simbolo);
  33. tabuleiro(tab);
  34. simbolo=false;
  35. imprimevez(nome2,simbolo);
  36. posicao(posicaoL, posicaoC);
  37. marcacao(tab, posicaoL, posicaoC, simbolo);
  38. tabuleiro(tab);
  39. vencedor(tab,nome1);
  40. venceu=vencedor(tab,nome1);
  41. if(venceu==true){
  42. printf("fim de jogo \n");
  43. break;
  44. }
  45. }
  46. }
  47.  
  48. bool posicao (int *pL, int *pC)
  49. {
  50. int lin, col;
  51. scanf("%d",&lin);
  52. scanf("%d",&col);
  53. *pL =lin;
  54. *pC=col;
  55. }
  56.  
  57. void jogadores (char nome1[], char nome2 [])
  58. {
  59. scanf("%s",nome1);
  60. scanf("%s",nome2);
  61. }
  62.  
  63. void tabuleiro (char tab[3][3])
  64. {
  65. for(int i=0; i<3; i++){
  66. printf("|");
  67. for(int j=0; j<3; j++){
  68. printf("%c",tab[i][j]);
  69. }
  70. printf("|\n");
  71. }
  72. }
  73.  
  74. void marcacao (char tab[3][3], int posicaoL[], int posicaoC[], bool simbolo)
  75. {
  76. if(simbolo==true){
  77. tab[posicaoL[0]-1][posicaoC[0]-1] = 'O';
  78. }
  79. if(simbolo==false){
  80. tab[posicaoL[0]-1][posicaoC[0]-1] = 'X';
  81. }
  82. }
  83.  
  84. void imprimevez (char nome[], bool simbolo)
  85. {
  86. if(simbolo==true){
  87. printf("%s, peça |O|, qual sua jogada?\n", nome);
  88. }
  89. if(simbolo==false){
  90. printf("%s, peça |X|, qual sua jogada?\n", nome);
  91. }
  92. }
  93.  
  94. bool vencedor ( char tab[3][3], char nome1[])
  95. {
  96. if(tab[1][1]==88 && tab[1][2]==88 && tab[2][3]==88){
  97. return true;
  98. }
  99. return false;
  100. }
  101.  
  102. /*int rep=0;
  103. for(int i=1; i<3;i++){
  104. for(int j=1; j<3;j++){
  105. if(tab[i][j]=='X'){
  106. rep++;
  107. printf("rep %d \n",rep);
  108. if(rep==3 && tab[i+1][j+1]=='X'){
  109. printf("Jogador %s venceu", nome1);
  110. return true;
  111. break;
  112. }
  113. }
  114. if(tab[j][i]=='X'){
  115. rep++;
  116. if(rep==3 && tab[j+1][i+1]=='X'){
  117. printf("Jogador %s venceu", nome1);
  118. return true;
  119. break;
  120. }
  121. }
  122. }
  123. return false;
  124. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement