-
Posts
49 -
Cadastrado em
-
Última visita
Tipo de conteúdo
Artigos
Selos
Livros
Cursos
Análises
Fórum
Tudo que Felipe Hoffmeister postou
-
C++ Como utilizar struct em uma biblioteca?
Felipe Hoffmeister respondeu ao tópico de Felipe Hoffmeister em C/C#/C++
eu nao comecei ainda mas eu tenho q usar esse struct, eu tenho que usar ele dentro de uma biblioteca que eu criei template <typename TIPO, int MAX> struct Agenda { TIPO itens[MAX]; int quantidade; }; adicionado 2 minutos depois e na biblioteca gostaria que tivesse essa funcao template <typename TIPO, int MAX> bool inicializa_agenda(Agenda <TIPO,MAX> &ag) { ag.quantidade = 0; return true; }; -
quero utilizar um struct numa biblioteca utilizada por min, mas quando eu uso uma funcao na biblioteca o codigo nao funciona
-
Estou fazendo um trabalho em c ++, porém quando eu faco o menu para selecionar o "escolha" o programa pula os cin para receber os nomes int main() { srand(time(NULL)); char nome1[256], nome2[256], nome3[256], nome4[256], nome5[256]; int matA[5][5],matB[5][5],matC[5][5],matD[5][5],matE[5][5]; int vet[75]= {0}; textcolor(CYAN); int escolha,para=0; do { cout<<"\t\tMENU\n\n\t1 AUTORES\n\t2 JOGAR\n\t3 SAIR\n\t>"; cin>>escolha; system("cls"); if(escolha==1) { system("cls"); cout<<"\tAUTORES:\n\tFelipe Hoffmeister\n\tRicardo Carvalho\n\tGuilherme"<<endl; } if(escolha==2) { do{ cout<<"\tDigite o nome do jogador da cartela 1:"; gets(nome1); cout<<"\tDigite o nome do jogador da cartela 2:"; cin.getline (nome2,256); cout<<"\tDigite o nome do jogador da cartela 3:"; cin.getline (nome3,256); cout<<"\tDigite o nome do jogador da cartela 4:"; cin.getline (nome4,256); cout<<"\tDigite o nome do jogador da cartela 5:"; cin.getline (nome5,256); system("cls"); Gera_Cartelas(matA); OrganizaMatriz(matA); Gera_Cartelas(matB); OrganizaMatriz(matB); Gera_Cartelas(matC); OrganizaMatriz(matC); Gera_Cartelas(matD); OrganizaMatriz(matD); Gera_Cartelas(matE); OrganizaMatriz(matE); Gera_Numeros_Sorteados(vet,matA,matB,matC,matD,matE,nome1,nome2,nome3,nome4,nome5); }while(para!=1); } } while(escolha!=3); return 0; }
-
eu to fazendo um trabalho de programacao em c, e preciso que quando determinado numero for selecionado ele mude de cor, como posso fazer isso?
-
C++ Como imprimir uma matriz com gotoxy?
Felipe Hoffmeister respondeu ao tópico de Felipe Hoffmeister em C/C#/C++
@devair1010 nao consegui usar a conio2.h, -
C++ Como imprimir uma matriz com gotoxy?
Felipe Hoffmeister respondeu ao tópico de Felipe Hoffmeister em C/C#/C++
eh que tem mais 4 matrizes, ai eu queria colocar uma do lado da outr entende? adicionado 0 minutos depois por isso o gotoxy, eu nao entendi o que você mudou adicionado 2 minutos depois #include <iostream> #include <stdlib.h> #include <time.h> #include <conio.h> #include <windows.h> using namespace std; void gotoxy_2(int x,int y ) { COORD c; c.X = x; c.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c); } void imp() { cout<<"\t°°°°\n"; cout<<"\t° °\n"; cout<<"\t° ° ° ° ° °°° °°°\n"; cout<<"\t°°°° ° °° ° ° ° °\n"; cout<<"\t° ° ° ° ° ° ° °° ° °\n"; cout<<"\t° ° ° ° ° ° ° ° ° °\n"; cout<<"\t°°°° ° ° °° °°° °°°\n\n"; } void nomes(char nome1[],char nome2[], char nome3[], char nome4[], char nome5[]) { imp(); cout<<"Digite o nome do jogador da cartela 1:"; cin.getline (nome1,256); cout<<"Digite o nome do jogador da cartela 2:"; cin.getline (nome2,256); cout<<"Digite o nome do jogador da cartela 3:"; cin.getline (nome3,256); cout<<"Digite o nome do jogador da cartela 4:"; cin.getline (nome4,256); cout<<"Digite o nome do jogador da cartela 5:"; cin.getline (nome5,256); system("cls"); } void organiza(int num[][5]) { for(int i=0; i<5; i++) { for(int j= 4; j>=0; j--) { for(int k= j-1; k>=0; k--) { if(num[i][j]< num[i][k]) { int l= num[i][j]; num[i][j]= num[i][k]; num[i][k]=l; } } } } } int existe(int matA[][5], int i, int j) { for (int k = 0; k <= i; k++) { for (int l = 0; l < j; l++) { if (matA[i][j] == matA[k][l]) { return 1; } } } return 0; } int existevet(int vetA[], int i) { for (int j = 0; j < 5; j++) { if (vetA[i] == vetA[j]) { return 1; } } return 0; } bool Existe(int valores[], int valor) { for(int i = 0; i<75; i++) { if(valores[i]==valor) return true; } return false; } void imprime(int matA[][5],int x,int y) { gotoxy(x,y); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { cout<<" "<<matA[i][j]; } y++; cout<<"\n"; } } void imp(int matA[][5],int matB[][5],int matC[][5],int matD[][5],int matE[][5],char nome1[],char nome2[],char nome3[],char nome4[],char nome5[]) { cout<<"CARTELA 1 NOME: "<<nome1<<endl; imprime(matA,10,1); cout<<"CARTELA 2 NOME: "<<nome2<<endl; imprime(matA,10,1); cout<<"CARTELA 3 NOME: "<<nome3<<endl; imprime(matA,10,1); cout<<"CARTELA 4 NOME: "<<nome4<<endl; imprime(matA,10,1); cout<<"CARTELA 5 NOME: "<<nome5<<endl; imprime(matA,10,1); } void GeraAleatorios(int numeros[],int matA[][5],int matB[][5],int matC[][5],int matD[][5],int matE[][5],char nome1[],char nome2[],char nome3[],char nome4[],char nome5[]) { srand(time(NULL)); int v,bingo=0,bingo2=0,bingo3=0,bingo4=0,bingo5=0; for(int k=0; k<75; k++) { imp(matA,matB,matC,matD,matE,nome1,nome2,nome3,nome4,nome5); v = 1+rand() % 75; while(Existe(numeros,v)) { v = 1+rand() % 75; } numeros[k] = v; cout<<"\n"<<numeros[k]; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if(matA[i][j]==numeros[k]) { bingo++; } if(bingo==25) { cout<<"bingo jogador 1"; system("pause"); } if(matB[i][j]==numeros[k]) { bingo2++; } if(bingo2==25) { cout<<"bingo jogador 2"; system("pause"); } if(matC[i][j]==numeros[k]) { bingo3++; } if(bingo3==25) { cout<<"bingo jogador 3"; system("pause"); } if(matD[i][j]==numeros[k]) { bingo4++; } if(bingo4==25) { cout<<"bingo jogador 4"; system("pause"); } if(matE[i][j]==numeros[k]) { bingo5++; } if(bingo5==25) { cout<<"bingo jogador 5"; system("pause"); } } } Sleep(1000); system("cls"); } } void gera(int matA[][5]) { int Limite; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if(i==0) { Limite =1; } if(i==1) { Limite =16; } if(i==2) { Limite =31; } if(i==3) { Limite =46; } if(i==4) { Limite =61; } while (1) { matA[i][j]= Limite + rand() % 15; if (!existe(matA, i, j)) break; } } } } int main() { srand(time(NULL)); char nome1[256], nome2[256], nome3[256], nome4[256], nome5[256]; int matA[5][5],matB[5][5],matC[5][5],matD[5][5],matE[5][5]; int vet[75]; nomes( nome1, nome2,nome3,nome4,nome5); gera(matA); organiza(matA); gera(matB); organiza(matB); gera(matC); organiza(matC); gera(matD); organiza(matD); gera(matE); organiza(matE); GeraAleatorios(vet,matA,matB,matC,matD,matE,nome1, nome2,nome3,nome4,nome5); return 0; } -
C++ Como imprimir uma matriz com gotoxy?
Felipe Hoffmeister respondeu ao tópico de Felipe Hoffmeister em C/C#/C++
#include <iostream> using namespace std; #include <stdlib.h> #include <time.h> #include <conio.h> #include <windows.h> void gotoxy(int x,int y ) { COORD coord; coord.X = (short)x; coord.Y = (short)y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); \ } void imp() { cout<<"\t°°°°\n"; cout<<"\t° °\n"; cout<<"\t° ° ° ° ° °°° °°°\n"; cout<<"\t°°°° ° °° ° ° ° °\n"; cout<<"\t° ° ° ° ° ° ° °° ° °\n"; cout<<"\t° ° ° ° ° ° ° ° ° °\n"; cout<<"\t°°°° ° ° °° °°° °°°\n\n"; } void nomes(char nome1[],char nome2[], char nome3[], char nome4[], char nome5[]) { imp(); cout<<"Digite o nome do jogador da cartela 1:"; cin.getline (nome1,256); cout<<"Digite o nome do jogador da cartela 2:"; cin.getline (nome2,256); cout<<"Digite o nome do jogador da cartela 3:"; cin.getline (nome3,256); cout<<"Digite o nome do jogador da cartela 4:"; cin.getline (nome4,256); cout<<"Digite o nome do jogador da cartela 5:"; cin.getline (nome5,256); system("cls"); } void organiza(int num[][5]) { for(int i=0; i<5; i++) { for(int j= 4; j>=0; j--) { for(int k= j-1; k>=0; k--) { if(num[i][j]< num[i][k]) { int l= num[i][j]; num[i][j]= num[i][k]; num[i][k]=l; } } } } } int existe(int matA[][5], int i, int j) { for (int k = 0; k <= i; k++) { for (int l = 0; l < j; l++) { if (matA[i][j] == matA[k][l]) { return 1; } } } return 0; } int existevet(int vetA[], int i) { for (int j = 0; j < 5; j++) { if (vetA[i] == vetA[j]) { return 1; } } return 0; } bool Existe(int valores[], int valor) { for(int i = 0; i<75; i++) { if(valores[i]==valor) return true; } return false; } void imprime(int matA[][5],int x,int y) { for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { cout<<" "<<matA[i][j]; } y++; cout<<"\n"; } } void imp(int matA[][5],int matB[][5],int matC[][5],int matD[][5],int matE[][5],char nome1[],char nome2[],char nome3[],char nome4[],char nome5[]) { cout<<"CARTELA 1 NOME: "<<nome1<<endl; imprime(matA,10,1); } void GeraAleatorios(int numeros[],int matA[][5],int matB[][5],int matC[][5],int matD[][5],int matE[][5],char nome1[],char nome2[],char nome3[],char nome4[],char nome5[]) { srand(time(NULL)); int v,bingo=0,bingo2=0,bingo3=0,bingo4=0,bingo5=0; for(int k=0; k<75; k++) { imp(matA,matB,matC,matD,matE,nome1,nome2,nome3,nome4,nome5); v = 1+rand() % 75; while(Existe(numeros,v)) { v = 1+rand() % 75; } numeros[k] = v; cout<<"\n"<<numeros[k]; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if(matA[i][j]==numeros[k]) { bingo++; } if(bingo==25) { cout<<"bingo jogador 1"; system("pause"); } if(matB[i][j]==numeros[k]) { bingo2++; } if(bingo2==25) { cout<<"bingo jogador 2"; system("pause"); } if(matC[i][j]==numeros[k]) { bingo3++; } if(bingo3==25) { cout<<"bingo jogador 3"; system("pause"); } if(matD[i][j]==numeros[k]) { bingo4++; } if(bingo4==25) { cout<<"bingo jogador 4"; system("pause"); } if(matE[i][j]==numeros[k]) { bingo5++; } if(bingo5==25) { cout<<"bingo jogador 5"; system("pause"); } } } _sleep(1000); system("cls"); } } void gera(int matA[][5]) { int Limite; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if(i==0) { Limite =1; } if(i==1) { Limite =16; } if(i==2) { Limite =31; } if(i==3) { Limite =46; } if(i==4) { Limite =61; } while (1) { matA[i][j]= Limite + rand() % 15; if (!existe(matA, i, j)) break; } } } } int main() { srand(time(NULL)); char nome1[256], nome2[256], nome3[256], nome4[256], nome5[256]; int matA[5][5],matB[5][5],matC[5][5],matD[5][5],matE[5][5]; int vet[75]; nomes( nome1, nome2,nome3,nome4,nome5); gera(matA); organiza(matA); gera(matB); organiza(matB); gera(matC); organiza(matC); gera(matD); organiza(matD); gera(matE); organiza(matE); GeraAleatorios(vet,matA,matB,matC,matD,matE,nome1, nome2,nome3,nome4,nome5); return 0; } adicionado 2 minutos depois eu quero que imprima a matriz com 5 linha e com 5 colunas -
C++ posso utilizar 2 vetores em uma funcao em c++
Felipe Hoffmeister respondeu ao tópico de Felipe Hoffmeister em C/C#/C++
eu entendi a forma que voce fez, porém meu professor quer que eu faca com subrotinas e passagem de parâmetros, eu estou com duvida de como posso imprimir na tela as matrizes das cartelas -
C++ Como imprimir uma matriz com gotoxy?
Felipe Hoffmeister respondeu ao tópico de Felipe Hoffmeister em C/C#/C++
eu to chamando a matriz por uma funcao, e quando bota para imprimir ela com o gotoxy nao aparece os valores -
estou com duvida de como escolher o local onde imprimir minha matriz em c++
-
C++ como posso utlizar 2 vetores em uma funcao em c++
Felipe Hoffmeister respondeu ao tópico de Felipe Hoffmeister em C/C#/C++
Valeu pela ajuda, Eu ja consegui fazer a cartela numa matriz sem que nos numeros se repitam e de forma crescente, agora flata sortear o os numeros como você fez? adicionado 4 minutos depois meu programa esta assim agora #include <iostream> using namespace std; #include <stdlib.h> #include <time.h> #include <conio.h> void nomes(char nome1[],char nome2[], char nome3[], char nome4[], char nome5[]) { cout<<"\t\tBINGO\n"; cout<<"Digite o nome do jogador da cartela 1:"; cin.getline (nome1,256); cout<<"Digite o nome do jogador da cartela 2:"; cin.getline (nome2,256); cout<<"Digite o nome do jogador da cartela 3:"; cin.getline (nome3,256); cout<<"Digite o nome do jogador da cartela 4:"; cin.getline (nome4,256); cout<<"Digite o nome do jogador da cartela 5:"; cin.getline (nome5,256); system("cls"); } void comparador(int vet[],int matA[][5],int matB[][5],int matC[][5],int matD[][5],int matE[][5]){ for(int i=0; i<5; i++) { for(int j= 0; j>=0; j++) { if(matA[i][j]==vet[i]){ cout<<"a"; break;} }} } void organiza(int num[][5]) { for(int i=0; i<5; i++) { for(int j= 4; j>=0; j--) { for(int var1= j-1; var1>=0; var1--) { if(num[i][j]< num[i][var1]) { int var2= num[i][j]; num[i][j]= num[i][var1]; num[i][var1]=var2; } } } } } int existe(int matA[][5], int i, int j) { for (int k = 0; k <= i; k++) { for (int l = 0; l < j; l++) { if (matA[i][j] == matA[k][l]) { return 1; } } } return 0; } int existevet(int vetA[], int i) { for (int j = 0; j < 5; j++) { if (vetA[i] == vetA[j]) { return 1; } } return 0; } bool Existe(int valores[], int valor){ for(int i = 0;i<75;i++){ if(valores[i]==valor) return true; } return false; } void GeraAleatorios(int numeros[],int matA[][5],int matB[][5],int matC[][5],int matD[][5],int matE[][5]){ srand(time(NULL)); int v; for(int i=0;i<75;i++){ v = 1+rand() % 75; while(Existe(numeros,v)){ v = 1+rand() % 75; } numeros[i] = v; cout<<"\n"<<numeros[i]; _sleep(1000); } } void gera(int matA[][5]) { int Limite; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if(i==0) { Limite =1; } if(i==1) { Limite =16; } if(i==2) { Limite =31; } if(i==3) { Limite =46; } if(i==4) { Limite =61; } while (1) { matA[i][j]= Limite + rand() % 15; if (!existe(matA, i, j)) break; } } } } void imprime(int matA[][5]) { for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { cout<<" "<<matA[i][j]; } cout<<"\n"; } } int main() { srand(time(NULL)); char nome1[256], nome2[256], nome3[256], nome4[256], nome5[256]; int matA[5][5],matB[5][5],matC[5][5],matD[5][5],matE[5][5]; int vet[75]; nomes( nome1, nome2,nome3,nome4,nome5); gera(matA); organiza(matA); gera(matB); organiza(matB); gera(matC); organiza(matC); gera(matD); organiza(matD); gera(matE); organiza(matE); cout<<"CARTELA 1 NOME: "<<nome1<<endl; imprime(matA); cout<<"CARTELA 2 NOME: "<<nome2<<endl; imprime(matB); cout<<"CARTELA 3 NOME: "<<nome3<<endl; imprime(matC); cout<<"CARTELA 4 NOME: "<<nome4<<endl; imprime(matD); cout<<"CARTELA 5 NOME: "<<nome5<<endl; imprime(matE); GeraAleatorios(vet,matA,matB,matC,matD,matE); return 0; } -
C++ como posso utlizar 2 vetores em uma funcao em c++
Felipe Hoffmeister respondeu ao tópico de Felipe Hoffmeister em C/C#/C++
consegui meu codigo estava errado por isso a duvida, mas valeu pela ajuda -
C++ posso utilizar 2 vetores em uma funcao em c++
Felipe Hoffmeister respondeu ao tópico de Felipe Hoffmeister em C/C#/C++
eu gostaria que a funcao GeraAleatorios receba os vetores cartelaA[5] e cartelaB[5], porém o resultado do cartelaB[5] da errado -
voce tem que colocar o n e o s em char e trocar o %d por %s #include <stdio.h> #include <stdlib.h> int main(){ int alarme; char s, n; printf("Devemos acionar o alarme? \n"); scanf("%s", &alarme); if (alarme == 'n'){ printf("ok.", 'n'); } else{ printf("ALERTA, ALERTA, ALERTA.", s); } return 0; }
-
coloque o n entre aspas simples
-
estou com uma duvida de como usar a mesma funcao para 2 vetores diferentes, meu programa tem que colocar valores aleatorios em vetores sem que se repitam e de forma crescente #include <iostream> using namespace std; #include <stdlib.h> #include <time.h> bool Existe(int cartelaA[],int tam, int valor) { for(int i = 0; i<tam; i++) { if(cartelaA[i]==valor) return true; } return false; } void GeraAleatorios(int cartelaA[],int Limite) { srand(time(NULL)); int v; for(int i=0; i<5; i++) { v = Limite+ rand() % 15; while(Existe(cartelaA,i,v)) { v = rand() % 15; } cartelaA[i] = v; } } int main() { srand(time(NULL)); int cartelaA[5]; int cartelaB[5]; GeraAleatorios(cartelaA,1); GeraAleatorios(cartelaB,16); for(int i = 0; i<5; i++) { cout<<cartelaA[i]<<" - "; } cout<<"\n"; for(int i = 0; i<5; i++) { cout<<cartelaB[i]<<" - "; } return 0; }
-
C++ como posso utlizar 2 vetores em uma funcao em c++
Felipe Hoffmeister respondeu ao tópico de Felipe Hoffmeister em C/C#/C++
@devair1010 edite agora voce consegue ver? -
C++ como posso utlizar 2 vetores em uma funcao em c++
Felipe Hoffmeister postou um tópico em C/C#/C++
estou com duvida no meu trabalho de programacao, eu gostaria de saber se tem como eu usar 2 vetores na mesma funcao void. #include <iostream> using namespace std; #include <stdlib.h> #include <time.h> bool Existe(int cartelaA[],int tam, int valor){ for(int i = 0;i<tam;i++){ if(cartelaA==valor) return true; } return false; } void GeraAleatorios(int cartelaA[],int Limite){ srand(time(NULL)); int v; for(int i=0;i<5;i++){ v = Limite+ rand() % 15; while(Existe(cartelaA,i,v)){ v = rand() % 15; } cartelaA = v; } } int main() { srand(time(NULL)); int cartelaA[5]; int cartelaB[5]; GeraAleatorios(cartelaA,1); GeraAleatorios(cartelaB,16); for(int i = 0;i<5;i++){ cout<<cartelaA<<" - "; } cout<<"\n"; for(int i = 0;i<5;i++){ cout<<cartelaB<<" - "; } return 0; } -
valeu, vou testar aqui
-
estou criando um jogo em c para um trabalho de faculdade, o jogo ja esta pronto falta somente os menus estou com duvida, o jogo basicamente tem 2 mapas eu tenho que no menu principal : 1 Indicação dos autores do trabalho e da atividade 2 Orientações de jogo 3 Jogar (nessa opção o jogador deverá escolher um dos mapas destacando os que ainda não foram resolvidos) 4 Sair: só deve sair por essa opção
-
C Nao consigo finalizar meu programa em C
Felipe Hoffmeister respondeu ao tópico de Felipe Hoffmeister em C/C#/C++
entendi sua forma, porém eu nao posso fazer assim pois tenho que continuar o programa que a professora mandou, seria uma forma dela garantir que nao foi pego da internet . eu recebi o programa assim dela: #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include<windows.h> #include<conio.h> #define L 10 #define C 20 int main() { ///ALERTA: NÃO MODIFICAR O TRECHO DE CÓDIGO, A SEGUIR. //INICIO: COMANDOS PARA QUE O CURSOR NÃO FIQUE PISCANDO NA TELA HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_CURSOR_INFO cursorInfo; GetConsoleCursorInfo(out, &cursorInfo); cursorInfo.bVisible = false; // set the cursor visibility SetConsoleCursorInfo(out, &cursorInfo); //FIM: COMANDOS PARA QUE O CURSOR NÃO FIQUE PISCANDO NA TELA //INÍCIO: COMANDOS PARA REPOSICIONAR O CURSOR NO INÍCIO DA TELA short int CX=0, CY=0; COORD coord; coord.X = CX; coord.Y = CY; //FIM: COMANDOS PARA REPOSICIONAR O CURSOR NO INÍCIO DA TELA ///ALERTA: NÃO MODIFICAR O TRECHO DE CÓDIGO, ACIMA. //Posição inicial do personagem no console int x=3, y=3; //Variável para recla precionada char tecla; //Coordenadas para impressão na tela int i,j; while(1){ ///Imprime o jogo: mapa e personagem. i=0; while (i<L) { j=0; while (j<C) { if (x==i && y==j){ printf("*"); } else if (i==0 || i==L-1 || j==0 || j==C-1){ printf("°"); } else { printf(" "); } j++; } printf("\n"); i++; } if ( _kbhit() ){ tecla = getch(); switch(tecla) { case 'w': ///cima x--; break; case 's': ///baixo x++; break; case 'a': ///esquerda y--; break; case 'd': ///direita y++; break; } } /** Recoloca o mapa no inicio da tela, isso faz com que o jogo seja escrito sempre no mesmo lugar. */ SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); } return 0; } -
C Nao consigo finalizar meu programa em C
Felipe Hoffmeister respondeu ao tópico de Felipe Hoffmeister em C/C#/C++
eu gostaria porém a professora mandou usar o codigo da forma que veio, · O personagem deve ser capaz de se movimentar em todas as direções. · O personagem deve poder empurrar uma caixa e movimentá-la pelo cenário em todas as direções. · O personagem e a caixa não podem sair do mapa. · ( Quando a caixa for colocada no local designado no mapa o jogo deve terminar.) · Quando o jogo terminar, deve ser exibida uma mensagem de “Vitória” na tela. · Não é permitido utilizar variáveis globais. -
Eu tenho uma duvida de como posso finalizar meu programa quando o # do meu jogo estiver em cima do X se alguem pode me ajudar?? #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include<windows.h> #include<conio.h> #define L 10 #define C 20 int main() { ///ALERTA: NÃO MODIFICAR O TRECHO DE CÓDIGO, A SEGUIR. //INICIO: COMANDOS PARA QUE O CURSOR NÃO FIQUE PISCANDO NA TELA HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_CURSOR_INFO cursorInfo; GetConsoleCursorInfo(out, &cursorInfo); cursorInfo.bVisible = false; // set the cursor visibility SetConsoleCursorInfo(out, &cursorInfo); //FIM: COMANDOS PARA QUE O CURSOR NÃO FIQUE PISCANDO NA TELA //INÍCIO: COMANDOS PARA REPOSICIONAR O CURSOR NO INÍCIO DA TELA short int CX=0, CY=0; COORD coord; coord.X = CX; coord.Y = CY; //FIM: COMANDOS PARA REPOSICIONAR O CURSOR NO INÍCIO DA TELA ///ALERTA: NÃO MODIFICAR O TRECHO DE CÓDIGO, ACIMA. //Posição inicial do personagem no console int x=5, y=3; // Posição inicial da caixa no console int n=2,m=2; // Posição inicial do final no console int v=8,b=18; //Variável para recla precionada char tecla; //Coordenadas para impressão na tela int i,j; while(1){ ///Imprime o jogo: mapa e personagem. i=0; while (i<L) { j=0; while (j<C) { if (x==i && y==j){ printf("$"); } else if (i==0 || i==L-1 || j==0 || j==C-1){ printf("°"); }else if(n==i&& m==j){ printf("#"); } else if(v==i&& b==j){ printf("X"); } else{ printf(" "); } j++; } printf("\n"); i++; } if ( _kbhit() ){ tecla = getch(); switch(tecla) { case 'w': ///cima x--; if (x==n && y==m) { n--; } break; case 's': ///baixo x++; if (x==n && y==m) { n++; } break; case 'a': ///esquerda y--; if (x==n && y==m) { m--; } break; case 'd': ///direita y++; if (x==n && y==m) { m++; } break; } } if (n==0 && x==1)// NAO DEIXA O JOGADOR E A CAIXA SAIR PARA CIMA { n++; x++; } if (n==9 && x==8)// NAO DEIXA O JOGADOR E A CAIXA SAIR PARA BAIXO { n--; x--; } if (m==19 && y==18)// NAO DEIXA O JOGADOR E A CAIXA SAIR PARA DIREITA { m--; y--; } if (m==0 && y==1)// NAO DEIXA O JOGADOR E A CAIXA SAIR PARA ESQUERDA { m++; y++; } if(x==0) // NAO DEIXA O JOGADOR SAIR PARA CIMA { x++; } if(x==9)// NAO DEIXA O JOGADOR SAIR PARA BAIXO { x--; } if(y==0)// NAO DEIXA O JOGADOR SAIR PARA ESQUERDA { y++; } if(y==19)// NAO DEIXA O JOGADOR SAIR PARA DIREITA { y--; } printf("X %d Y %d n %d m %d", x,y,n,m); if (n==8 && m==18) { printf("vitoria"); break; return 0; } /** Recoloca o mapa no inicio da tela, isso faz com que o jogo seja escrito sempre no mesmo lugar. */ SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); } return 0; }
Sobre o Clube do Hardware
No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais
Direitos autorais
Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais