Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdbool.h>
- //indica a posição a ser jogada
- bool posicao (int posi1[], int posi2[]);
- //define os jogadores e registra o nome
- void jogadores (char nome1[], char nome2 []);
- //imprime o tabuleiro
- void tabuleiro (char tab[3][3]);
- //registra a posição no tabuleiro
- void marcacao (char tab[3][3], int posicaoL[], int posicaoC[], bool simbolo);
- //informa de quem é a vez e qual a peça
- void imprimevez (char nome[], bool simbolo);
- //informa o vencedor
- bool vencedor ( char tab[3][3], char nome1[]);
- int main()
- {
- char nome1[20];
- char nome2[20];
- char tab[3][3]={{'-','-','-'},{'-','-','-'},{'-','-','-'},};
- int lin=0, col=0;
- int *posicaoL=&lin, *posicaoC=&col;
- bool simbolo=true, venceu=true;
- jogadores(nome1,nome2);
- tabuleiro(tab);
- for(;;){
- simbolo=true;
- imprimevez(nome1,simbolo);
- posicao(posicaoL, posicaoC);
- marcacao(tab, posicaoL, posicaoC, simbolo);
- tabuleiro(tab);
- simbolo=false;
- imprimevez(nome2,simbolo);
- posicao(posicaoL, posicaoC);
- marcacao(tab, posicaoL, posicaoC, simbolo);
- tabuleiro(tab);
- vencedor(tab,nome1);
- venceu=vencedor(tab,nome1);
- if(venceu==true){
- printf("fim de jogo \n");
- break;
- }
- }
- }
- bool posicao (int *pL, int *pC)
- {
- int lin, col;
- scanf("%d",&lin);
- scanf("%d",&col);
- *pL =lin;
- *pC=col;
- }
- void jogadores (char nome1[], char nome2 [])
- {
- scanf("%s",nome1);
- scanf("%s",nome2);
- }
- void tabuleiro (char tab[3][3])
- {
- for(int i=0; i<3; i++){
- printf("|");
- for(int j=0; j<3; j++){
- printf("%c",tab[i][j]);
- }
- printf("|\n");
- }
- }
- void marcacao (char tab[3][3], int posicaoL[], int posicaoC[], bool simbolo)
- {
- if(simbolo==true){
- tab[posicaoL[0]-1][posicaoC[0]-1] = 'O';
- }
- if(simbolo==false){
- tab[posicaoL[0]-1][posicaoC[0]-1] = 'X';
- }
- }
- void imprimevez (char nome[], bool simbolo)
- {
- if(simbolo==true){
- printf("%s, peça |O|, qual sua jogada?\n", nome);
- }
- if(simbolo==false){
- printf("%s, peça |X|, qual sua jogada?\n", nome);
- }
- }
- bool vencedor ( char tab[3][3], char nome1[])
- {
- if(tab[1][1]==88 && tab[1][2]==88 && tab[2][3]==88){
- return true;
- }
- return false;
- }
- /*int rep=0;
- for(int i=1; i<3;i++){
- for(int j=1; j<3;j++){
- if(tab[i][j]=='X'){
- rep++;
- printf("rep %d \n",rep);
- if(rep==3 && tab[i+1][j+1]=='X'){
- printf("Jogador %s venceu", nome1);
- return true;
- break;
- }
- }
- if(tab[j][i]=='X'){
- rep++;
- if(rep==3 && tab[j+1][i+1]=='X'){
- printf("Jogador %s venceu", nome1);
- return true;
- break;
- }
- }
- }
- return false;
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement