JoaoMBarbosa Posted March 22, 2018 at 07:29 PM Report #609872 Posted March 22, 2018 at 07:29 PM Pessoal Estou aqui a criar um jogo para a nota final do modulo e queria a vossa ajuda porque eu queria que aparece-se o X na coluna que indiquei mas isso nunca acontece ja tentei varias maneira mas nao estou a conseguir . Se me poderem ajudar agradecia . Desculpem por ter varias funções o meu professor quer assim mesmo. #include <iostream> #include <string> #include <stdlib.h> #include <conio.h> #include <iomanip> #include <windows.h> using namespace std; string nome1, nome2; char jogador='X'; int op; int numquard,numpont; void trocarjogador() { if(jogador=='X') { jogador='O'; } else { jogador='X'; } } char tab[7][6]={ {' ',' ',' ',' ',' ',' ',}, {' ',' ',' ',' ',' ',' ',}, {' ',' ',' ',' ',' ',' ',}, {' ',' ',' ',' ',' ',' ',}, {' ',' ',' ',' ',' ',' ',}, {' ',' ',' ',' ',' ',' ',}, {' ',' ',' ',' ',' ',' ',}}; void ganhar () { int i,j; int r=30; for(i=0;i<6;i++) { for(j=0;j<7;j++) { if(tab[j]==tab[i+1][j]&&tab[i+2][j]==tab[i+3][j]&&tab[j]==tab[i+3][j]&&tab[j]!=' ') cout<<"Ganhou o jogador do simbolo "<<jogador<<endl; vitoria=1; } } for(i=0;i<6;i++) { for(j=0;j<7;j++) { if(tab[j]==tab[j+1] && tab[j+2]==tab[j+3] && tab[j]==tab[j+2] && tab[j]!=' ') cout<<"Ganhou o jogador do simbolo "<<jogador<<endl; vitoria=1; } } for(i=0;i<6;i++) { for(j=0;j<7;j++) { if(tab[j]==tab[i+1][j+1]&&tab[j]==tab[i+2][j+2]&&tab[j]==tab[i+3][j+3]&&tab[j]==tab[i+2][j+2]&&tab[j]!=' ') cout<<"Ganhou o jogador do simbolo "<<jogador<<endl; vitoria=1; } } for(i=0;i<6;i++) { for(j=0;j<7;j++) { if(tab[j]==r) { cout<<"Empate"<<endl; } } } } void visor () { int i; int j; cout<<endl; cout<<" 1 2 3 4 5 "<<endl; cout<<"+-------------------+"<<endl;; for(i=0;i<6;i++) { for(j=0;j<5;j++) { cout<<"|"<<setw(3)<<tab[j]; } cout<<"|"<<endl; } cout<<"+-------------------+"<<endl; cout<<endl; } void limpa() { int i,j; for(i=0;i<6;i++) { for(j=0;j<7;j++) { tab[j]=' '; } } } void PrimaUmaTecla() { int c; cout << "Prima uma tecla para continuar ..."; c = getch(); } void jogo() { int a,i,j,r; int roda; cout<<"O jogador "<<jogador<<" esta na sua vez para jogar"<<endl; cout<<"Em que Coluna quer jogar-> "; cin>>a; tab[0][a]; if(a<0||a>6) { system("cls"); cout<<" Jogada Invalida tente novamente! "; _sleep(2000); system("cls"); } else { visor(); while(tab[j]!=' ') { } } } int menu() { int op; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN); cout<<" 4 em Linha"<<endl; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); cout<<" +---------+ +---------+ +---------+"<<endl; cout<<" |(0)Sair | |(1)Opcoes| |(2) Jogo |"<<endl; cout<<" +---------+ +---------+ +---------+"<<endl; op=getch(); return op; } void iniciarJogo() { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN); cout<<" 4 EM LINHA "<<endl; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); system("cls"); cout<<endl; cout<<" 4 EM LINHA"<<endl; while(1==1) { limpa(); while(vitoria!=1||vitoria!=2) { visor(); jogo(); ganhar(); trocarjogador(); system("cls"); } } } void definicoes() { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN); cout<<" 4 EM LINHA "<<endl; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); cout<<endl; cout<<"Numeros de Quadrados -> "; cin>>numquard; cout<<endl; cout<<"Numeros de Pontos para ganhar -> "; cin>>numpont; cout<<endl; PrimaUmaTecla(); system("cls"); } int main() { //Menu op=menu(); system("Cls"); while(op!=0) { switch(op) { case '1': //definições definicoes(); break; case '2': //jogar iniciarJogo(); break; } op=menu(); } return 0; }
HappyHippyHippo Posted March 22, 2018 at 09:27 PM Report #609876 Posted March 22, 2018 at 09:27 PM mas em que linha de código é que estás a colocar o X ? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
JoaoMBarbosa Posted March 22, 2018 at 10:15 PM Author Report #609879 Posted March 22, 2018 at 10:15 PM 46 minutos atrás, HappyHippyHippo disse: mas em que linha de código é que estás a colocar o X ? Quando eu vou jogar o jogo o jogador tem que jogar numa coluna mas quando joga numa coluna nao aparece o x ou o O isso e que nao estou a conseguir fazer ja fiz varias maneiras mas nao consegui
HappyHippyHippo Posted March 23, 2018 at 08:35 AM Report #609882 Posted March 23, 2018 at 08:35 AM (edited) algo como isto ? void jogo() { int i,j; cout<<"O jogador "<<jogador<<" esta na sua vez para jogar"<<endl; do { do { cout << "Em que Coluna quer jogar-> "; cin >> i; } while (i < 0 || i >= 6); do { cout << "Em que Linha quer jogar-> "; cin >> j; } while (j < 0 || j >= 7); if (tab[i][j] != ' ') cout << "Jogada invalida" << endl; } while (tab[i][j] != ' '); tab[i][j] != jogador; } nota ... isto é o que acontece no meu compilador com o teu código : g++ -c -g -MD -MP -Wall -Werror -pedantic -std=c++11 -I. -I./include/ src/main.cpp -o obj/MINGW64_NT-10.0/main.o src/main.cpp: In function 'void ganhar()': src/main.cpp:39:38: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if(tab[j]==tab[i+1][j]&&tab[i+2][j]==tab[i+3][j]&&tab[j]==tab[i+3][j]&&tab[j]!=' ') ^ src/main.cpp:39:85: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if(tab[j]==tab[i+1][j]&&tab[i+2][j]==tab[i+3][j]&&tab[j]==tab[i+3][j]&&tab[j]!=' ') ^ src/main.cpp:39:96: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if(tab[j]==tab[i+1][j]&&tab[i+2][j]==tab[i+3][j]&&tab[j]==tab[i+3][j]&&tab[j]!=' ') ^~~ src/main.cpp:39:17: error: this 'if' clause does not guard... [-Werror=misleading-indentation] if(tab[j]==tab[i+1][j]&&tab[i+2][j]==tab[i+3][j]&&tab[j]==tab[i+3][j]&&tab[j]!=' ') ^~ src/main.cpp:41:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if' vitoria=1; ^~~~~~~ src/main.cpp:41:21: error: 'vitoria' was not declared in this scope src/main.cpp:41:21: note: suggested alternative: 'itoa' vitoria=1; ^~~~~~~ itoa src/main.cpp:48:90: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if(tab[j]==tab[j+1] && tab[j+2]==tab[j+3] && tab[j]==tab[j+2] && tab[j]!=' ') ^~~ src/main.cpp:48:17: error: this 'if' clause does not guard... [-Werror=misleading-indentation] if(tab[j]==tab[j+1] && tab[j+2]==tab[j+3] && tab[j]==tab[j+2] && tab[j]!=' ') ^~ src/main.cpp:50:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if' vitoria=1; ^~~~~~~ src/main.cpp:50:21: error: 'vitoria' was not declared in this scope src/main.cpp:50:21: note: suggested alternative: 'itoa' vitoria=1; ^~~~~~~ itoa src/main.cpp:57:40: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if(tab[j]==tab[i+1][j+1]&&tab[j]==tab[i+2][j+2]&&tab[j]==tab[i+3][j+3]&&tab[j]==tab[i+2][j+2]&&tab[j]!=' ') ^ src/main.cpp:57:63: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if(tab[j]==tab[i+1][j+1]&&tab[j]==tab[i+2][j+2]&&tab[j]==tab[i+3][j+3]&&tab[j]==tab[i+2][j+2]&&tab[j]!=' ') ^ src/main.cpp:57:86: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if(tab[j]==tab[i+1][j+1]&&tab[j]==tab[i+2][j+2]&&tab[j]==tab[i+3][j+3]&&tab[j]==tab[i+2][j+2]&&tab[j]!=' ') ^ src/main.cpp:57:109: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if(tab[j]==tab[i+1][j+1]&&tab[j]==tab[i+2][j+2]&&tab[j]==tab[i+3][j+3]&&tab[j]==tab[i+2][j+2]&&tab[j]!=' ') ^ src/main.cpp:57:120: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if(tab[j]==tab[i+1][j+1]&&tab[j]==tab[i+2][j+2]&&tab[j]==tab[i+3][j+3]&&tab[j]==tab[i+2][j+2]&&tab[j]!=' ') ^~~ src/main.cpp:57:17: error: this 'if' clause does not guard... [-Werror=misleading-indentation] if(tab[j]==tab[i+1][j+1]&&tab[j]==tab[i+2][j+2]&&tab[j]==tab[i+3][j+3]&&tab[j]==tab[i+2][j+2]&&tab[j]!=' ') ^~ src/main.cpp:59:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if' vitoria=1; ^~~~~~~ src/main.cpp:59:25: error: 'vitoria' was not declared in this scope src/main.cpp:59:25: note: suggested alternative: 'itoa' vitoria=1; ^~~~~~~ itoa src/main.cpp:66:28: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if(tab[j]==r) ^ src/main.cpp: In function 'void limpa()': src/main.cpp:99:20: error: incompatible types in assignment of 'char' to 'char [6]' tab[j]=' '; ^~~ src/main.cpp: In function 'void jogo()': src/main.cpp:133:15: error: statement has no effect [-Werror=unused-value] tab[i][j] != jogador; ~~~~~~~~~~^~~~~~~~~~ src/main.cpp: In function 'void iniciarJogo()': src/main.cpp:159:19: error: 'vitoria' was not declared in this scope while(vitoria!=1||vitoria!=2) ^~~~~~~ src/main.cpp:159:19: note: suggested alternative: 'visor' while(vitoria!=1||vitoria!=2) ^~~~~~~ visor padrões !!! Edited March 23, 2018 at 08:35 AM by HappyHippyHippo IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
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