mcosta Posted April 24, 2012 at 12:47 PM Report #451102 Posted April 24, 2012 at 12:47 PM Olá pessoal tudo bem... saquei o jogo do três em linha, e funciona bem, no entanto, tenho um problema.. quis alterar o código para ter funções e procedimentos.. ou melhor procedimentos... o problema é que quero fazer um procedimento para criar o tabuleiro que é facil: tabuleiro[1]='1'; tabuleiro[2]='2'; tabuleiro[3]='3'; tabuleiro[4]='4'; tabuleiro[5]='5'; tabuleiro[6]='6'; tabuleiro[7]='7'; tabuleiro[8]='8'; tabuleiro[9]='9'; printf ("\n\n\n\t\t\t\tJOGO DO GALO\n\n"); printf ("\t\t\t\t%c %c %c %c %c \n",linha [1][1],linha[2] [1],linha[3][1],linha[4] [1], linha [5] [1]); printf ("\t\t\t\t%c %c %c %c %c \n",linha[1][2],tabuleiro[1],tabuleiro[2],tabuleiro[3], linha [5][2]); printf ("\t\t\t\t%c %c %c %c %c \n",linha [1][3],tabuleiro[4],tabuleiro[5],tabuleiro[6], linha[5][3]); printf ("\t\t\t\t%c %c %c %c %c \n",linha[1][4],tabuleiro[7],tabuleiro[8],tabuleiro[9], linha [5] [4]); printf ("\t\t\t\t%c %c %c %c %c \n",linha [1][5],linha[2] [5],linha[3][5],linha[4] [5], linha [5] [5]); e depois um procedimento para o jogo: aqui é que está o problema, ele no while entra num ciclo infinito, mas não percebo porque?? alguem me ajuda?? outro problema é conforme jogo actualizar o tabuleiro, basta na função jojo chamar tabuleiro()? deixo o codigo ja a seguir: void jogar () { nj=0; jogada =0; while (sair == 0) printf ("jogador 1, introduza a jogada\n"); scanf ("%d",&jogada); printf ("entrei"); system ("pause"); tabuleiro[jogada]='x';nj++; if ((tabuleiro[1]=='x' && tabuleiro[2]=='x' && tabuleiro[3]=='x') || (tabuleiro[4]=='x' && tabuleiro[5]=='x' && tabuleiro[6]=='x') || (tabuleiro[7]=='x' && tabuleiro[8]=='x' && tabuleiro[9]=='x')) { printf ("O jogador 1 venceu!\n"); sair=1; } else if ((tabuleiro[1]=='x' && tabuleiro[4]=='x' && tabuleiro[7]=='x') || (tabuleiro[2]=='x' && tabuleiro[5]=='x' && tabuleiro[8]=='x') || (tabuleiro[3]=='x' && tabuleiro[6]=='x' && tabuleiro[9]=='x')) { printf ("o jogador 1 venceu!\n"); sair=1; } else if ((tabuleiro[1]=='x' && tabuleiro[5]=='x' && tabuleiro[9]=='x') || (tabuleiro[2]=='x' && tabuleiro[5]=='x' && tabuleiro[8]=='x') || (tabuleiro[3]=='x' && tabuleiro[5]=='x' && tabuleiro[7]=='x')) { printf ("o jogador 1 venceu!\n"); sair=1; } if(nj==9) { printf("empate"); printf("\n"); system ("pause"); sair=1;} //jogador 2 else { printf ("jogador 2, introduza a jogada\n"); scanf ("%d",&jogada);nj++; tabuleiro(); tabuleiro[jogada]='o'; if ((tabuleiro[1]=='o' && tabuleiro[2]=='o' && tabuleiro[3]=='o') || (tabuleiro[4]=='o' && tabuleiro[5]=='o' && tabuleiro[6]=='o') || (tabuleiro[7]=='o' && tabuleiro[8]=='o' && tabuleiro[9]=='o')) { printf ("O jogador 2 venceu!\n"); sair=1; } else if ((tabuleiro[1]=='o' && tabuleiro[4]=='o' && tabuleiro[7]=='o') || (tabuleiro[2]=='o' && tabuleiro[5]=='o' && tabuleiro[8]=='o') || (tabuleiro[3]=='o' && tabuleiro[6]=='o' && tabuleiro[9]=='o')) { printf ("o jogador 2 venceu!\n"); sair=1; } else if ((tabuleiro[1]=='o' && tabuleiro[5]=='o' && tabuleiro[9]=='o') || (tabuleiro[2]=='o' && tabuleiro[5]=='o' && tabuleiro[8]=='o') || (tabuleiro[3]=='o' && tabuleiro[5]=='o'&& tabuleiro[7]=='o')) { printf ("o jogador 2 venceu!\n"); sair=1; } } } Eu sei que se colocar tudo dentro da função jogar, isto é fazer os prints do tabulareido para jogador um e outro para jogador 2 funciona mas eu queria assim... Alguem me ajuda?? cumprimentos!!
HappyHippyHippo Posted April 24, 2012 at 04:47 PM Report #451162 Posted April 24, 2012 at 04:47 PM 1º - não estás a usar o GeShi correctamente 2º - não identaste uma única linha de código 3º - não existe uma única linha de comentário no teu código 4º - não encontro o while que referes do ciclo infinito do código que apresentaste como achas que uma se pode resolver uma questão desta maneira ?? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
mcosta Posted April 24, 2012 at 04:50 PM Author Report #451166 Posted April 24, 2012 at 04:50 PM desculpa..sou novo aqui... desculpa o erro!!
HappyHippyHippo Posted April 24, 2012 at 04:52 PM Report #451171 Posted April 24, 2012 at 04:52 PM desculpa..sou novo aqui... desculpa o erro!! isso só te desculpa o primeiro ponto ... e os outros 3 ? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
mcosta Posted April 24, 2012 at 04:56 PM Author Report #451172 Posted April 24, 2012 at 04:56 PM ok tens razão em tudo:-)) desculpa o while está logo a começar o procedimento jogar() no enatnto, resolvi de outra forma, criei o tabuleiro no proprio procedimento jogar que assim atualiza sempre e não da erro:-)) mais uma vez desculpa!! tenho um tópico que tem um erro e precisava mesmo de conseguir tirar!! o topico chama-se o jogo da forca.. não me podes dar uma ajuda?? muito obrigado por tudo...e mais uma vez desculpa.
seuqram Posted April 24, 2012 at 10:14 PM Report #451256 Posted April 24, 2012 at 10:14 PM eu tambem sou novo!!! e que tem ser? com os erros aprendes! as chavetas do while, onde estão?
pikax Posted April 24, 2012 at 10:49 PM Report #451268 Posted April 24, 2012 at 10:49 PM isso só te desculpa o primeiro ponto ... e os outros 3 ? LOOOOOOOL poe as chavetas no while: void jogar () { nj=0; jogada =0; while (sair == 0) { printf ("jogador 1, introduza a jogada\n"); scanf ("%d",&jogada); printf ("entrei"); system ("pause"); tabuleiro[jogada]='x';nj++; if ((tabuleiro[1]=='x' && tabuleiro[2]=='x' && tabuleiro[3]=='x') || (tabuleiro[4]=='x' && tabuleiro[5]=='x' && tabuleiro[6]=='x') || (tabuleiro[7]=='x' && tabuleiro[8]=='x' && tabuleiro[9]=='x')) { printf ("O jogador 1 venceu!\n"); sair=1; } else if ((tabuleiro[1]=='x' && tabuleiro[4]=='x' && tabuleiro[7]=='x') || (tabuleiro[2]=='x' && tabuleiro[5]=='x' && tabuleiro[8]=='x') || (tabuleiro[3]=='x' && tabuleiro[6]=='x' && tabuleiro[9]=='x')) { printf ("o jogador 1 venceu!\n"); sair=1; } else if ((tabuleiro[1]=='x' && tabuleiro[5]=='x' && tabuleiro[9]=='x') || (tabuleiro[2]=='x' && tabuleiro[5]=='x' && tabuleiro[8]=='x') || (tabuleiro[3]=='x' && tabuleiro[5]=='x' && tabuleiro[7]=='x')) { printf ("o jogador 1 venceu!\n"); sair=1; } if(nj==9) { printf("empate"); printf("\n"); system ("pause"); sair=1; } //jogador 2 else { printf ("jogador 2, introduza a jogada\n"); scanf ("%d",&jogada);nj++; tabuleiro(); tabuleiro[jogada]='o'; if ((tabuleiro[1]=='o' && tabuleiro[2]=='o' && tabuleiro[3]=='o') || (tabuleiro[4]=='o' && tabuleiro[5]=='o' && tabuleiro[6]=='o') || (tabuleiro[7]=='o' && tabuleiro[8]=='o' && tabuleiro[9]=='o')) { printf ("O jogador 2 venceu!\n"); sair=1; } else if ((tabuleiro[1]=='o' && tabuleiro[4]=='o' && tabuleiro[7]=='o') || (tabuleiro[2]=='o' && tabuleiro[5]=='o' && tabuleiro[8]=='o') || (tabuleiro[3]=='o' && tabuleiro[6]=='o' && tabuleiro[9]=='o')) { printf ("o jogador 2 venceu!\n"); sair=1; } else if ((tabuleiro[1]=='o' && tabuleiro[5]=='o' && tabuleiro[9]=='o') || (tabuleiro[2]=='o' && tabuleiro[5]=='o' && tabuleiro[8]=='o') || (tabuleiro[3]=='o' && tabuleiro[5]=='o'&& tabuleiro[7]=='o')) { printf ("o jogador 2 venceu!\n"); sair=1; } } } Aprende a indentar codigo e a comenta-lo Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."
mcosta Posted April 25, 2012 at 12:21 AM Author Report #451285 Posted April 25, 2012 at 12:21 AM Ok!! Obrigado por tudo!! cumprimentos
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now