Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio2.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <time.h>
- #define X_I 1
- #define Y_I 1
- #define X_F 80
- #define Y_F 20
- struct TpPalavra
- {
- char port[30], ing[30], significado[100];
- int pont, status;
- };
- struct TpData
- {
- int dia, mes, ano;
- };
- struct TpPessoa
- {
- char nome[40], login[10];
- int senha, pont, status;
- TpData Data;
- };
- struct TpPalavForca
- {
- char Palavra[30], Login[10];
- int Acertou;
- };
- void Quadro()
- {
- int i;
- textcolor(14);
- gotoxy(X_I,Y_I);
- printf("%c",201);
- gotoxy(X_F,Y_I);
- printf("%c",187);
- gotoxy(X_I,Y_F);
- printf("%c",200);
- gotoxy(X_F,Y_F);
- printf("%c",188);
- for(i = X_I + 1; i < X_F; i++)
- {
- gotoxy(i, Y_I);
- printf("%c", 205);
- gotoxy(i, Y_F);
- printf("%c", 205);
- }
- for(i = Y_I + 1; i < Y_F; i++)
- {
- gotoxy(X_I, i);
- printf("%c", 186);
- gotoxy(X_F, i);
- printf("%c", 186);
- }
- textcolor(15);
- }
- void QuadroFlexivel(int XI, int YI, int XF, int YF)
- {
- int i;
- textcolor(14);
- gotoxy(XI, YI);
- printf("%c",201);
- gotoxy(XF, YI);
- printf("%c",187);
- gotoxy(XI, YF);
- printf("%c",200);
- gotoxy(XF, YF);
- printf("%c",188);
- for(i = XI + 1; i < XF; i++)
- {
- gotoxy(i, YI);
- printf("%c", 205);
- gotoxy(i, YF);
- printf("%c", 205);
- }
- for(i = YI + 1; i < YF; i++)
- {
- gotoxy(XI, i);
- printf("%c", 186);
- gotoxy(XF, i);
- printf("%c", 186);
- }
- }
- void Cabecalho(char Titulo[100])
- {
- Quadro();
- textcolor(15);
- gotoxy(30, 2);
- printf("%s\n", Titulo);
- textcolor(14);
- for(int i = 2; i <= 79; i++)
- {
- gotoxy(i, 3);
- printf("%c", 205);
- }
- textcolor(15);
- }
- void ImprimePalavra(TpPalavra Pal, int linha)
- {
- QuadroFlexivel(2, linha - 1, 79, linha + 4);
- gotoxy(3, linha++);
- textcolor(14);
- printf("Portugues: ");
- textcolor(15);
- printf("%s", Pal.port);
- gotoxy(3, linha++);
- textcolor(14);
- printf("Ingles: ");
- textcolor(15);
- printf("%s", Pal.ing);
- gotoxy(3, linha++);
- textcolor(14);
- printf("Pontuacao: ");
- textcolor(15);
- printf("%d", Pal.pont);
- gotoxy(3, linha);
- printf("%s", Pal.significado);
- }
- void ImprimePessoa(TpPessoa Pes, int linha)
- {
- QuadroFlexivel(2, linha - 1, 79, linha + 4);
- gotoxy(3, linha++);
- textcolor(14);
- printf("Nome: ");
- textcolor(15);
- printf("%s", Pes.nome);
- gotoxy(3, linha);
- textcolor(14);
- printf("Login: ");
- textcolor(15);
- printf("%s", Pes.login);
- gotoxy(30, linha);
- textcolor(14);
- printf("Pontuacao: ");
- textcolor(15);
- printf("%d", Pes.pont);
- linha++;
- gotoxy(3, linha);
- textcolor(14);
- printf("Data: ");
- textcolor(15);
- printf("%d/%d/%d", Pes.Data.dia, Pes.Data.mes, Pes.Data.ano);
- textcolor(15);
- }
- void RelatorioPalavras(FILE *PtrArq)
- {
- TpPalavra Pal;
- int linha = 6;
- system("cls");
- QuadroFlexivel(1, 1, 80, 3);
- gotoxy(30, 2);
- printf("Relatorio de palavras");
- PtrArq = fopen("Palavra.dat", "rb");
- if(PtrArq == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de palavras inexistente");
- textcolor(15);
- }
- else
- {
- rewind(PtrArq);
- fread(&Pal, sizeof(TpPalavra), 1, PtrArq);
- while(!feof(PtrArq))
- {
- if(Pal.status == 1)
- {
- ImprimePalavra(Pal, linha);
- linha += 6;
- }
- fread(&Pal, sizeof(TpPalavra), 1, PtrArq);
- }
- gotoxy(1, 1);
- }
- fclose(PtrArq);
- getch();
- }
- int PosicaoMaiorPessoa(FILE *PtrPes, int NumR)
- {
- TpPessoa Pes;
- int Pos, i = 0;
- char MaiorNome[40];
- rewind(PtrPes);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- strcpy(MaiorNome, Pes.login);
- Pos = 0;
- for(i = 1; i < NumR; i++)
- {
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- if(stricmp(Pes.login, MaiorNome) > 0)
- {
- strcpy(MaiorNome, Pes.login);
- Pos = i;
- }
- }
- return Pos * sizeof(TpPessoa);
- }
- void SelecaoDiretaPessoa(FILE *PtrPes)
- {
- int PosMaior, NumR;
- TpPessoa PesA, PesB;
- PtrPes = fopen("Pessoa.dat", "rb+");
- fseek(PtrPes, 0, 2);
- NumR = ftell(PtrPes) / sizeof(TpPessoa);
- while(NumR > 0)
- {
- PosMaior = PosicaoMaiorPessoa(PtrPes, NumR);
- if(PosMaior < (NumR - 1) * sizeof(TpPessoa))
- {
- fseek(PtrPes, PosMaior, 0);
- fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
- fseek(PtrPes, (NumR - 1) * sizeof(TpPessoa), 0);
- fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
- fseek(PtrPes, (NumR - 1) * sizeof(TpPessoa), 0);
- fwrite(&PesA, sizeof(TpPessoa), 1, PtrPes);
- fseek(PtrPes, PosMaior, 0);
- fwrite(&PesB, sizeof(TpPessoa), 1, PtrPes);
- }
- NumR--;
- }
- fclose(PtrPes);
- }
- void InsercaoDiretaPessoa(FILE *PtrPes)
- {
- TpPessoa PesA, PesB;
- int NumR, Pos;
- PtrPes = fopen("Pessoa.dat", "rb+");
- if(PtrPes != NULL)
- {
- fseek(PtrPes, 0, 2);
- NumR = ftell(PtrPes) / sizeof(TpPessoa);
- if(NumR > 1)
- {
- Pos = NumR - 1;
- fseek(PtrPes, Pos * sizeof(TpPessoa), 0);
- fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
- fseek(PtrPes, (Pos - 1) * sizeof(TpPessoa), 0);
- fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
- while(Pos > 0 && stricmp(PesA.login, PesB.login) < 0)
- {
- fseek(PtrPes, Pos * sizeof(TpPessoa), 0);
- fwrite(&PesB, sizeof(TpPessoa), 1, PtrPes);
- fseek(PtrPes, (Pos - 1) * sizeof(TpPessoa), 0);
- fwrite(&PesA, sizeof(TpPessoa), 1, PtrPes);
- Pos--;
- if(Pos > 0)
- {
- fseek(PtrPes, Pos * sizeof(TpPessoa), 0);
- fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
- fseek(PtrPes, (Pos - 1) * sizeof(TpPessoa), 0);
- fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
- }
- }
- }
- }
- fclose(PtrPes);
- }
- void InsercaoDiretaPalavra(FILE *PtrPal)
- {
- TpPalavra PalA, PalB;
- int Pos, NumR;
- PtrPal = fopen("Palavra.dat", "rb+");
- if(PtrPal != NULL)
- {
- fseek(PtrPal, 0, 2);
- NumR = ftell(PtrPal) / sizeof(TpPalavra);
- if(NumR > 1)
- {
- Pos = NumR - 1;
- fseek(PtrPal, Pos * sizeof(TpPalavra), 0);
- fread(&PalA, sizeof(TpPalavra), 1, PtrPal);
- fseek(PtrPal, (Pos - 1) * sizeof(TpPalavra), 0);
- fread(&PalB, sizeof(TpPalavra), 1, PtrPal);
- while(Pos > 0 && stricmp(PalA.port, PalB.port) < 0)
- {
- fseek(PtrPal, Pos * sizeof(TpPalavra), 0);
- fwrite(&PalB, sizeof(TpPalavra), 1, PtrPal);
- fseek(PtrPal, (Pos - 1) * sizeof(TpPalavra), 0);
- fwrite(&PalA, sizeof(TpPalavra), 1, PtrPal);
- Pos--;
- if(Pos > 0)
- {
- fseek(PtrPal, Pos * sizeof(TpPalavra), 0);
- fread(&PalA, sizeof(TpPalavra), 1, PtrPal);
- fseek(PtrPal, (Pos - 1) * sizeof(TpPalavra), 0);
- fread(&PalB, sizeof(TpPalavra), 1, PtrPal);
- }
- }
- }
- }
- fclose(PtrPal);
- }
- void RelatorioPessoa(FILE *PtrPes)
- {
- int linha = 5;
- TpPessoa Pes;
- clrscr();
- QuadroFlexivel(1, 1, 80, 3);
- gotoxy(30, 2);
- printf("Relatorio de pessoas");
- PtrPes = fopen("Pessoa.dat", "rb");
- if(PtrPes == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de pessoas inexistente");
- textcolor(15);
- }
- else
- {
- rewind(PtrPes);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- while(!feof(PtrPes))
- {
- if(Pes.status == 1)
- {
- ImprimePessoa(Pes, linha);
- linha += 6;
- }
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- }
- gotoxy(1, 1);
- }
- fclose(PtrPes);
- getch();
- }
- int BuscaPalavraPort(FILE *PtrPal, char Palavra[40])
- {
- TpPalavra Pal;
- //BUSCA EXAUSTIVA DE PALAVRAS
- rewind(PtrPal);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- while(!feof(PtrPal) && stricmp(Pal.port, Palavra) != 0)
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- if(stricmp(Palavra, Pal.port) == 0)
- return ftell(PtrPal) - sizeof(TpPalavra);
- else
- return -1;
- }
- int BuscaExaustivaPessoa(FILE *PtrPes, char login[10])
- {
- TpPessoa Pes;
- rewind(PtrPes);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- while(!feof(PtrPes) && (stricmp(login, Pes.login) != 0 || Pes.status == 0))
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- if(stricmp(login, Pes.login) == 0)
- return ftell(PtrPes) - sizeof(TpPessoa);
- else
- return -1;
- }
- void BubbleSortPessoa(FILE *PtrPes)
- {
- TpPessoa PesA, PesB;
- int i, j, QntdR;
- PtrPes = fopen("Pessoa.dat", "rb+");
- fseek(PtrPes, 0, 2);
- QntdR = ftell(PtrPes) / sizeof(TpPessoa);
- while(QntdR > 0)
- {
- for(i = 0; i < QntdR - 1; i++)
- {
- fseek(PtrPes, i * sizeof(TpPessoa), 0);
- fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
- fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
- if(stricmp(PesA.nome, PesB.nome) > 0)
- {
- fseek(PtrPes, i * sizeof(TpPessoa), 0);
- fwrite(&PesB, sizeof(TpPessoa), 1, PtrPes);
- fwrite(&PesA, sizeof(TpPessoa), 1, PtrPes);
- }
- }
- QntdR--;
- }
- fclose(PtrPes);
- getch();
- }
- void BubbleSortPalavra(FILE *PtrPal)
- {
- TpPalavra PalA, PalB;
- int i, j, QntdR;
- PtrPal = fopen("Palavra.dat", "rb+");
- if(PtrPal != NULL)
- {
- fseek(PtrPal, 0, 2);
- QntdR = ftell(PtrPal) / sizeof(TpPalavra);
- while(QntdR > 0)
- {
- for(i = 0; i < QntdR - 1; i++)
- {
- fseek(PtrPal, i * sizeof(TpPalavra), 0);
- fread(&PalA, sizeof(TpPalavra), 1, PtrPal);
- fread(&PalB, sizeof(TpPalavra), 1, PtrPal);
- if(stricmp(PalA.port, PalB.port) > 0)
- {
- fseek(PtrPal, i * sizeof(TpPalavra), 0);
- fwrite(&PalB, sizeof(TpPalavra), 1, PtrPal);
- fwrite(&PalA, sizeof(TpPalavra), 1, PtrPal);
- }
- }
- QntdR--;
- }
- }
- fclose(PtrPal);
- }
- int BuscaSeqIndPessoa(FILE *PtrPes, char loginChave[10])
- {
- TpPessoa Pes;
- rewind(PtrPes);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- while(!feof(PtrPes) && (stricmp(loginChave, Pes.login) > 0 || Pes.login == 0))
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- if(stricmp(loginChave, Pes.login) == 0)
- return ftell(PtrPes) - sizeof(TpPessoa);
- else
- return -1;
- }
- int BuscaSentinelaPessoa(FILE *PtrPes, char loginChave[10])
- {
- FILE *PtrAux;
- int i = 0, j, NumR;
- TpPessoa R;
- PtrPes = fopen("Pessoa.dat", "rb+");
- fseek(PtrPes, 0, 2);
- NumR = ftell(PtrPes) / sizeof(TpPessoa);
- strcpy(R.login, loginChave);
- fwrite(&R, sizeof(TpPessoa), 1, PtrPes);
- rewind(PtrPes);
- fread(&R, sizeof(TpPessoa), 1, PtrPes);
- while(strcmp(R.login, loginChave) != 0 || R.status == 0)
- {
- i++;
- fread(&R, sizeof(TpPessoa), 1, PtrPes);
- }
- PtrAux = fopen("Temp.dat", "ab+");
- rewind(PtrPes);
- for(j = 0; j < NumR; j++)
- {
- fread(&R, sizeof(TpPessoa), 1, PtrPes);
- fwrite(&R, sizeof(TpPessoa), 1, PtrAux);
- }
- fclose(PtrPes);
- fclose(PtrAux);
- remove("Pessoa.dat");
- rename("Temp.dat", "Pessoa.dat");
- if(i < NumR)
- return i * sizeof(TpPessoa);
- else
- return -1;
- }
- int BuscaBinariaPessoa(FILE *PtrPes, char loginChave[10])
- {
- int inicio = 0, meio, fim;
- TpPessoa R;
- fseek(PtrPes, 0, 2);
- fim = ftell(PtrPes) / sizeof(TpPessoa) - 1;
- meio = fim / 2;
- fseek(PtrPes, meio * sizeof(TpPessoa), 0);
- fread(&R, sizeof(TpPessoa), 1, PtrPes);
- while(inicio < fim && (strcmp(loginChave, R.login) != 0 || R.status == 0))
- {
- if(strcmp(loginChave, R.login) > 0)
- inicio = meio + 1;
- else
- fim = meio - 1;
- meio = (inicio + fim) / 2;
- fseek(PtrPes, meio * sizeof(TpPessoa), 0);
- fread(&R, sizeof(TpPessoa), 1, PtrPes);
- }
- if(strcmp(loginChave, R.login) == 0)
- return meio * sizeof(TpPessoa);
- else
- return -1;
- }
- int BuscaBinariaPalavra(FILE *PtrPal, char palavraChave[40])
- {
- TpPalavra R;
- int inicio = 0, meio, fim;
- fseek(PtrPal, 0, 2);
- fim = ftell(PtrPal) / sizeof(TpPalavra) - 1;
- meio = fim / 2;
- fseek(PtrPal, meio * sizeof(TpPalavra), 0);
- fread(&R, sizeof(TpPalavra), 1, PtrPal);
- while(inicio < fim && (strcmp(R.port, palavraChave) != 0 && R.status == 0))
- {
- if(strcmp(palavraChave, R.port) > 0)
- inicio = meio + 1;
- else
- fim = meio - 1;
- meio = (inicio + fim) / 2;
- fseek(PtrPal, meio * sizeof(TpPalavra), 0);
- fread(&R, sizeof(TpPalavra), 1, PtrPal);
- }
- if(strcmp(palavraChave, R.port) == 0)
- return meio * sizeof(TpPalavra);
- else
- return -1;
- }
- void ExclusaoFisicaPessoa(FILE *PtrPes)
- {
- TpPessoa Pes;
- char LoginAux[10];
- int Pos;
- system("cls");
- Cabecalho("Exclusao Fisica de Pessoas");
- gotoxy(2, 4);
- printf("Pessoa a ser excluida:");
- fflush(stdin);
- gets(LoginAux);
- while(strcmp(LoginAux, "\0") != 0)
- {
- PtrPes = fopen("Pessoa.dat", "rb");
- if(PtrPes == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de pessoas inexistente");
- textcolor(15);
- fclose(PtrPes);
- }
- else
- {
- Pos = BuscaBinariaPessoa(PtrPes, LoginAux);
- if(Pos == -1)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Login nao cadastrado");
- textcolor(15);
- fclose(PtrPes);
- }
- else
- {
- gotoxy(2, 5);
- printf("Dados encontrados:");
- fseek(PtrPes, Pos, 0);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- ImprimePessoa(Pes, 7);
- gotoxy(2, 12);
- printf("Confirma exclusao?(S/N)");
- if(toupper(getche()) == 'S')
- {
- FILE *PtrTemp = fopen("Temp.dat", "ab+");
- rewind(PtrPes);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- while(!feof(PtrPes))
- {
- if(strcmp(Pes.login, LoginAux) != 0)
- fwrite(&Pes, sizeof(TpPessoa), 1, PtrTemp);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- }
- fclose(PtrPes);
- fclose(PtrTemp);
- remove("Pessoa.dat");
- rename("Temp.dat", "Pessoa.dat");
- textcolor(3);
- gotoxy(25, 15);
- printf("Pessoa excluida!");
- }
- else
- fclose(PtrPes);
- }
- getch();
- system("cls");
- Cabecalho("Exclusao Fisica de Pessoas");
- gotoxy(2, 4);
- printf("Pessoa a ser excluida:");
- fflush(stdin);
- gets(LoginAux);
- }
- }
- getch();
- }
- void ExclusaoLogicaPessoa(FILE *PtrPes)
- {
- TpPessoa Pes;
- int Pos;
- char LoginAux[10];
- system("cls");
- Cabecalho("Exclusao Logica de Pessoas");
- PtrPes = fopen("Pessoa.dat", "rb+");
- if(PtrPes == NULL)
- {
- }
- else
- {
- gotoxy(2, 4);
- printf("Login:");
- fflush(stdin);
- gets(LoginAux);
- while(strcmp(LoginAux, "\0") != 0)
- {
- Pos = BuscaBinariaPessoa(PtrPes, LoginAux);
- if(Pos == -1)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Login nao cadastrado");
- textcolor(15);
- fclose(PtrPes);
- }
- else
- {
- gotoxy(2, 5);
- printf("Dados encontrados:");
- fseek(PtrPes, Pos, 0);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- ImprimePessoa(Pes, 7);
- gotoxy(2, 12);
- printf("Confirma exclusao?(S/N)");
- if(toupper(getche()) == 'S')
- {
- Pes.status = 0;
- fseek(PtrPes, Pos, 0);
- fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
- textcolor(3);
- gotoxy(25, 15);
- printf("Pessoa excluida!");
- }
- }
- getch();
- system("cls");
- Cabecalho("Exclusao Logica de Pessoas");
- gotoxy(2, 4);
- printf("Login:");
- fflush(stdin);
- gets(LoginAux);
- }
- }
- fclose(PtrPes);
- getch();
- }
- void ConsultaPalavras(FILE *PtrArq)
- {
- TpPalavra Pal;
- int Pos, linha;
- system("cls");
- Cabecalho("Consulta de Palavras");
- PtrArq = fopen("Palavra.dat", "rb");
- if(PtrArq == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de palavras inexistente");
- textcolor(15);
- }
- else
- {
- gotoxy(2, 4);
- printf("Palavra em portugues:");
- fflush(stdin);
- gets(Pal.port);
- while(strcmp(Pal.port, "\0") != 0)
- {
- Pos = BuscaPalavraPort(PtrArq, Pal.port);
- if(Pos == -1)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Palavra inexistente");
- textcolor(15);
- }
- else
- {
- gotoxy(30, 5);
- printf("Dados encontrados:");
- fseek(PtrArq, Pos, 0);
- fread(&Pal, sizeof(TpPalavra), 1, PtrArq);
- ImprimePalavra(Pal, 7);
- }
- getch();
- system("cls");
- Cabecalho("Consulta de Palavras");
- gotoxy(2, 4);
- printf("Palavra em portugues:");
- fflush(stdin);
- gets(Pal.port);
- }
- }
- fclose(PtrArq);
- getch();
- }
- char MenuAlteraPessoa(void)
- {
- gotoxy(3, 6);
- printf("[A] - Alterar nome");
- gotoxy(3, 7);
- printf("[B] - Alterar senha");
- gotoxy(3, 8);
- printf("[ESC] - Sair ");
- return toupper(getche());
- }
- char MenuAlteraPalavra(void)
- {
- gotoxy(3, 6);
- printf("[A] - Alterar palavra em ingles");
- gotoxy(3, 7);
- printf("[B] - Alterar pontuacao");
- gotoxy(3, 8);
- printf("[C] - Alterar significado ");
- gotoxy(3, 9);
- printf("[ESC] - Sair ");
- return toupper(getche());
- }
- void CadastraPalavra(FILE *PtrPal)
- {
- TpPalavra Pal;
- system("cls");
- Cabecalho("Cadastro de Palavras");
- gotoxy(2, 4);
- printf("Palavra em portugues: ");
- fflush(stdin);
- gets(Pal.port);
- while(strcmp(Pal.port, "\0") != 0)
- {
- PtrPal = fopen("Palavra.dat", "rb+");
- if(PtrPal == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de palavras inexistente!");
- textcolor(15);
- fclose(PtrPal);
- }
- else
- {
- if(BuscaPalavraPort(PtrPal, Pal.port) >= 0)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Palavra ja cadastrada");
- textcolor(15);
- fclose(PtrPal);
- }
- else
- {
- gotoxy(2, 5);
- printf("Palavra em ingles: ");
- fflush(stdin);
- gets(Pal.ing);
- while(strcmp(Pal.ing, "\0") == 0)
- {
- textcolor(4);
- gotoxy(2, 6);
- printf("Digite uma palavra valida:");
- fflush(stdin);
- textcolor(15);
- gets(Pal.ing);
- }
- gotoxy(2, 7);
- printf("Significado da palavra: ");
- fflush(stdin);
- gets(Pal.significado);
- while(strcmp(Pal.significado, "\0") == 0)
- {
- textcolor(4);
- gotoxy(2, 8);
- printf("Digite um significado valido:");
- fflush(stdin);
- textcolor(15);
- gets(Pal.significado);
- }
- gotoxy(2, 9);
- printf("Pontuacao: ");
- scanf("%d", &Pal.pont);
- while(Pal.pont <= 0)
- {
- textcolor(4);
- gotoxy(2, 10);
- printf("Digite uma pontuacao valida:");
- textcolor(15);
- scanf("%d", &Pal.pont);
- }
- Pal.status = 1;
- fseek(PtrPal, 0, 2);
- fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
- fclose(PtrPal);
- InsercaoDiretaPalavra(PtrPal);
- textcolor(3);
- gotoxy(25, 15);
- printf("Palavra cadastrada!");
- }
- }
- getch();
- system("cls");
- Cabecalho("Cadastro de Palavras");
- gotoxy(2, 4);
- printf("Palavra em portugues: ");
- fflush(stdin);
- gets(Pal.port);
- }
- getch();
- }
- void AlteracaoPalavra(FILE *PtrPal)
- {
- TpPalavra Pal;
- char Op;
- int Pos;
- system("cls");
- Cabecalho("Alteracao de Palavras");
- PtrPal = fopen("Palavra.dat", "rb+");
- if(PtrPal == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de palavras inexistente!");
- textcolor(15);
- fclose(PtrPal);
- }
- else
- {
- gotoxy(2, 4);
- printf("Palavra em portugues: ");
- fflush(stdin);
- gets(Pal.port);
- while(strcmp(Pal.port, "\0") != 0)
- {
- Pos = BuscaBinariaPalavra(PtrPal, Pal.port);
- if(Pos == -1)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Palavra inexistente");
- textcolor(15);
- }
- else
- {
- fseek(PtrPal, Pos, 0);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- Op = MenuAlteraPalavra();
- while(Op != 27)
- {
- switch(Op)
- {
- case 'A':
- gotoxy(2, 10);
- printf("Palavra em ingles atual: %s", Pal.ing);
- gotoxy(2, 11);
- printf("Nova palavra em ingles: ");
- fflush(stdin);
- gets(Pal.ing);
- while(strcmp(Pal.ing, "\0") == 0)
- {
- textcolor(4);
- gotoxy(2, 12);
- printf("Digite uma palavra valida:");
- fflush(stdin);
- textcolor(15);
- gets(Pal.ing);
- }
- fseek(PtrPal, Pos, 0);
- fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
- textcolor(3);
- gotoxy(25, 15);
- printf("Palavra alterada!");
- break;
- case 'B':
- gotoxy(2, 10);
- printf("Pontuacao atual: %d", Pal.pont);
- gotoxy(2, 11);
- printf("Nova pontuacao: ");
- scanf("%d", &Pal.pont);
- while(Pal.pont <= 0)
- {
- textcolor(4);
- gotoxy(2, 12);
- printf("Digite uma pontuacao valida:");
- textcolor(15);
- scanf("%d", &Pal.pont);
- }
- textcolor(3);
- gotoxy(25, 15);
- printf("Pontuacao alterada!");
- break;
- case 'C':
- gotoxy(2, 10);
- printf("Significado atual: %s", Pal.significado);
- gotoxy(2, 11);
- printf("Novo significado: ");
- fflush(stdin);
- gets(Pal.significado);
- while(strcmp(Pal.significado, "\0") == 0)
- {
- textcolor(4);
- gotoxy(2, 12);
- printf("Digite um significado valido:");
- fflush(stdin);
- textcolor(15);
- gets(Pal.significado);
- }
- fseek(PtrPal, Pos, 0);
- fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
- textcolor(3);
- gotoxy(25, 15);
- printf("Significado alterado!");
- break;
- default:
- gotoxy(2, 11);
- textcolor(4);
- printf("Opcao invalida!");
- textcolor(15);
- break;
- }
- getch();
- system("cls");
- Cabecalho("Alteracao de Palavras");
- Op = MenuAlteraPalavra();
- }
- }
- getch();
- system("cls");
- Cabecalho("Alteracao de Palavras");
- gotoxy(2, 4);
- printf("Palavra em portugues: ");
- gotoxy(2, 5);
- fflush(stdin);
- gets(Pal.port);
- }
- }
- fclose(PtrPal);
- getch();
- }
- void ExclusaoFisicaPalavra(FILE *PtrPal)
- {
- TpPalavra Pal;
- int Pos;
- char PalavraAux[40];
- system("cls");
- Cabecalho("Exclusao Fisica de Palavras");
- gotoxy(2, 4);
- printf("Palavra a ser excluida:");
- fflush(stdin);
- gets(PalavraAux);
- while(strcmp(PalavraAux, "\0") != 0)
- {
- PtrPal = fopen("Palavra.dat", "rb");
- if(PtrPal == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de palavras inexistente");
- textcolor(15);
- fclose(PtrPal);
- }
- else
- {
- Pos = BuscaBinariaPalavra(PtrPal, PalavraAux);
- if(Pos == -1)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Palavra inexistente");
- textcolor(15);
- fclose(PtrPal);
- }
- else
- {
- fseek(PtrPal, Pos, 0);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- gotoxy(2, 5);
- printf("Dados encontrados:");
- ImprimePalavra(Pal, 7);
- gotoxy(2, 12);
- printf("Confirma exclusao?(S/N)");
- if(toupper(getche()) == 'S')
- {
- FILE *PtrTemp = fopen("Temp.dat", "ab+");
- rewind(PtrPal);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- while(!feof(PtrPal))
- {
- if(strcmp(Pal.port, PalavraAux) != 0)
- fwrite(&Pal, sizeof(TpPalavra), 1, PtrTemp);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- }
- fclose(PtrPal);
- fclose(PtrTemp);
- remove("Palavra.dat");
- rename("Temp.dat", "Palavra.dat");
- textcolor(3);
- gotoxy(25, 15);
- printf("Palavra excluida!");
- }
- else
- fclose(PtrPal);
- }
- }
- getch();
- system("cls");
- Cabecalho("Exclusao Fisica de Palavras");
- gotoxy(2, 4);
- printf("Palavra a ser excluida:");
- fflush(stdin);
- gets(PalavraAux);
- }
- getch();
- }
- void ExclusaoLogicaPalavra(FILE *PtrPal)
- {
- TpPalavra Pal;
- int Pos;
- system("cls");
- Cabecalho("Exclusao Logica de Palavras");
- PtrPal = fopen("Palavra.dat", "rb+");
- if(PtrPal == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de palavras inexistente!");
- textcolor(15);
- fclose(PtrPal);
- }
- else
- {
- gotoxy(2, 4);
- printf("Palavra a ser excluida:");
- fflush(stdin);
- gets(Pal.port);
- while(strcmp(Pal.port, "\0") != 0)
- {
- Pos = BuscaBinariaPalavra(PtrPal, Pal.port);
- if(Pos == -1)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Palavra inexistente");
- textcolor(15);
- fclose(PtrPal);
- }
- else
- {
- fseek(PtrPal, Pos, 0);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- gotoxy(2, 5);
- printf("Dados encontrados:");
- ImprimePalavra(Pal, 7);
- gotoxy(2, 12);
- printf("Confirma exclusao?(S/N)");
- if(toupper(getche()) == 'S')
- {
- Pal.status = 0;
- fseek(PtrPal, Pos, 0);
- fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
- textcolor(3);
- gotoxy(25, 15);
- printf("Palavra excluida!");
- }
- }
- getch();
- system("cls");
- Cabecalho("Exclusao Logica de Palavras");
- gotoxy(2, 4);
- printf("Palavra a ser excluida:");
- fflush(stdin);
- gets(Pal.port);
- }
- }
- fclose(PtrPal);
- getch();
- }
- void CadastraPessoa(FILE *PtrPes)
- {
- TpPessoa Pes;
- time_t t = time(NULL);
- struct tm tm = *localtime(&t);
- system("cls");
- Cabecalho("Cadastro de Pessoas");
- gotoxy(2, 4);
- printf("Login a ser cadastrado: ");
- fflush(stdin);
- gets(Pes.login);
- while(strcmp(Pes.login, "\0") != 0)
- {
- PtrPes = fopen("Pessoa.dat", "rb+");
- if(BuscaExaustivaPessoa(PtrPes, Pes.login) >= 0)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Login ja cadastrado");
- textcolor(15);
- fclose(PtrPes);
- }
- else
- {
- gotoxy(2, 5);
- printf("Nome: ");
- fflush(stdin);
- gets(Pes.nome);
- while(strcmp(Pes.nome, "\0") == 0)
- {
- textcolor(4);
- gotoxy(2, 6);
- printf("Digite um nome valido:");
- fflush(stdin);
- textcolor(15);
- gets(Pes.nome);
- }
- gotoxy(2, 7);
- printf("Senha: "); textcolor(0);
- scanf("%d", &Pes.senha);
- while(Pes.senha <= 0)
- {
- textcolor(4);
- gotoxy(2, 8);
- printf("Digite uma senha valida:");
- textcolor(0);
- scanf("%d", &Pes.senha);
- }
- textcolor(15);
- Pes.Data.dia = tm.tm_mday;
- Pes.Data.mes = tm.tm_mon + 1;
- Pes.Data.ano = tm.tm_year + 1900;
- Pes.pont = 0;
- Pes.status = 1;
- fseek(PtrPes, 0, 2);
- fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
- fclose(PtrPes);
- InsercaoDiretaPessoa(PtrPes);
- textcolor(3);
- gotoxy(25, 15);
- printf("Pessoa cadastrada!");
- }
- getch();
- system("cls");
- Cabecalho("Cadastro de Pessoas");
- gotoxy(2, 4);
- printf("Login a ser cadastrado: ");
- fflush(stdin);
- gets(Pes.login);
- }
- getch();
- }
- void AlteracaoPessoa(FILE *PtrPes)
- {
- TpPessoa Pes;
- int Pos;
- char Op;
- system("cls");
- Cabecalho("Alteracao de Pessoas");
- PtrPes = fopen("Pessoa.dat", "rb+");
- if(PtrPes == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de pessoas inexistente!");
- textcolor(15);
- fclose(PtrPes);
- }
- else
- {
- gotoxy(2, 4);
- printf("Login da pessoa a ser alterada: ");
- fflush(stdin);
- gets(Pes.login);
- while(strcmp(Pes.login, "\0") != 0)
- {
- Pos = BuscaBinariaPessoa(PtrPes, Pes.login);
- if(Pos == -1)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Login inexistente!");
- textcolor(15);
- }
- else
- {
- fseek(PtrPes, Pos, 0);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- Op = MenuAlteraPessoa();
- while(Op != 27)
- {
- switch(Op)
- {
- case 'A':
- gotoxy(2, 10);
- printf("Nome atual: %s\n", Pes.nome);
- gotoxy(2, 11);
- printf("Novo nome: ");
- fflush(stdin);
- gets(Pes.nome);
- while(strcmp(Pes.nome, "\0") == 0)
- {
- textcolor(4);
- gotoxy(2, 12);
- printf("Digite um nome valido:");
- fflush(stdin);
- textcolor(15);
- gets(Pes.nome);
- }
- fseek(PtrPes, Pos, 0);
- fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
- textcolor(3);
- gotoxy(25, 15);
- printf("Nome alterado!");
- break;
- case 'B':
- gotoxy(2, 10);
- printf("Senha atual: %d\n", Pes.senha);
- gotoxy(2, 11);
- printf("Nova senha: "); textcolor(0);
- scanf("%d", &Pes.senha);
- while(Pes.senha <= 0)
- {
- textcolor(4);
- gotoxy(2, 12);
- printf("Digite uma senha valida:");
- textcolor(0);
- scanf("%d", &Pes.senha);
- }
- fseek(PtrPes, Pos, 0);
- fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
- textcolor(3);
- gotoxy(25, 15);
- printf("Senha alterada!");
- break;
- default:
- gotoxy(2, 11);
- textcolor(4);
- printf("Opcao invalida!");
- textcolor(15);
- break;
- }
- getch();
- system("cls");
- Cabecalho("Alteracao de Pessoas");
- Op = MenuAlteraPessoa();
- }
- }
- getch();
- system("cls");
- Cabecalho("Alteracao de Pessoas");
- gotoxy(2, 4);
- printf("Login da pessoa a ser alterada: ");
- fflush(stdin);
- gets(Pes.login);
- }
- }
- fclose(PtrPes);
- getch();
- }
- void ConsultaPessoa(FILE *PtrPes)
- {
- TpPessoa Pes;
- int Pos;
- system("cls");
- Cabecalho("Consulta de pessoas");
- PtrPes = fopen("Pessoa.dat", "rb");
- if(PtrPes == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de pessoas inexistente");
- textcolor(15);
- }
- else
- {
- gotoxy(2, 4);
- printf("Login a ser procurado: ");
- fflush(stdin);
- gets(Pes.login);
- while(strcmp(Pes.login, "\0") != 0)
- {
- Pos = BuscaBinariaPessoa(PtrPes, Pes.login);
- if(Pos == -1)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Login inexistente");
- textcolor(15);
- }
- else
- {
- gotoxy(30, 5);
- printf("Dados encontrados:");
- fseek(PtrPes, Pos, 0);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- ImprimePessoa(Pes, 7);
- }
- getch();
- system("cls");
- Cabecalho("Consulta de pessoas");
- gotoxy(2, 4);
- printf("Login a ser procurado: ");
- fflush(stdin);
- gets(Pes.login);
- }
- }
- fclose(PtrPes);
- getch();
- }
- int BuscaPalavraIngles(FILE *PtrPal, char Ing[40])
- {
- TpPalavra Pal;
- rewind(PtrPal);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- while(!feof(PtrPal) && (stricmp(Pal.ing, Ing) != 0 || Pal.status == 0))
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- if(stricmp(Pal.ing, Ing) == 0)
- return ftell(PtrPal) - sizeof(TpPalavra);
- else
- return -1;
- }
- int ELetra(char c)
- {
- if(toupper(c) >= 65 && toupper(c) <= 92)
- return 1;
- else
- return 0;
- }
- void Tradutor(FILE *PtrPal)
- {
- TpPalavra Pal;
- int Pos, i, Aux;
- char Frase[1000], StrAux[1000], Traducao[1000];
- system("cls");
- Cabecalho("Tradutor");
- PtrPal = fopen("Palavra.dat", "rb");
- if(PtrPal == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de palavras inexistente");
- textcolor(15);
- }
- else
- {
- gotoxy(2, 4);
- printf("Texto em ingles:");
- fflush(stdin);
- gets(Frase);
- while(strcmp(Frase, "\0") != 0)
- {
- strcpy(Traducao, "\0");
- Aux = 0;
- for(i = 0; i <= strlen(Frase); i++)
- {
- if(ELetra(Frase[i]) == 1)
- StrAux[Aux++] = Frase[i];
- else if(i > 0 && Frase[i] == ' ' || Frase[i] == '\0' && ELetra(Frase[i - 1]) == 1)
- {
- StrAux[Aux] = '\0';
- Pos = BuscaPalavraIngles(PtrPal, StrAux);
- if(Pos == -1)
- {
- strcat(Traducao, StrAux);
- strcat(Traducao, " ");
- }
- else
- {
- fseek(PtrPal, Pos, 0);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- strcat(Traducao, Pal.port);
- strcat(Traducao, " ");
- }
- strcpy(StrAux, "\0");
- Aux = 0;
- }
- }
- gotoxy(2, 5);
- printf("Traducao: %s", Traducao);
- getch();
- system("cls");
- Cabecalho("Tradutor");
- gotoxy(2, 4);
- printf("Texto em ingles:");
- fflush(stdin);
- gets(Frase);
- }
- }
- fclose(PtrPal);
- }
- void InsercaoAutomatica(FILE *PtrPes, FILE *PtrPal)
- {
- int NumRPes, NumRPal, i;
- time_t t = time(NULL);
- struct tm tm = *localtime(&t);
- TpPessoa VetPessoa[5] = {{"Joao Victor", "jvsierra", 12345, 0, 1, {tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900}},
- {"Rafael", "rafa", 45678, 0, 1, {tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900}},
- {"Miranda", "mir23", 12458, 0, 1, {tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900}},
- {"Arthur", "art657", 41256, 0, 1, {tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900}},
- {"Sofia", "sf123", 13879, 0, 1, {tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900}}};
- TpPalavra VetPalavra[5] = {{"lapis", "pencil", "Instrumento usado para escrever", 10, 1},
- {"celular", "cellphone", "Dispositivo telefonico movel", 15, 1},
- {"bolsa", "bag", "Item usado para carregar coisas", 20, 1},
- {"copo", "cup", "Item usado para colocar liquidos", 15, 1},
- {"cama", "bed", "Lugar onde se dorme", 10, 1}};
- system("cls");
- Cabecalho("Insercao Automatica");
- PtrPes = fopen("Pessoa.dat", "ab+");
- PtrPal = fopen("Palavra.dat", "ab+");
- fseek(PtrPes, 0, 2);
- NumRPes = ftell(PtrPes) / sizeof(TpPessoa);
- fseek(PtrPal, 0, 2);
- NumRPal = ftell(PtrPal) / sizeof(TpPalavra);
- if(NumRPes > 0 || NumRPal > 0)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Os arquivos ja contem dados");
- textcolor(15);
- fclose(PtrPal);
- }
- else
- {
- fwrite(VetPessoa, sizeof(TpPessoa), 5, PtrPes);
- fwrite(VetPalavra, sizeof(TpPalavra), 5, PtrPal);
- gotoxy(30, 6);
- textcolor(2);
- printf("Dados inseridos");
- textcolor(15);
- }
- fclose(PtrPes);
- fclose(PtrPal);
- SelecaoDiretaPessoa(PtrPes);
- BubbleSortPalavra(PtrPal);
- getch();
- }
- int TemLetraPalavra(char Palavra[40], char Letra)
- {
- int i = 0;
- while(i < strlen(Palavra) && Palavra[i] != Letra)
- i++;
- if(i < strlen(Palavra))
- return i;
- else
- return -1;
- }
- void OrdenaJogadoresPontuacao(FILE *PtrPes)
- {
- int a, NumR;
- TpPessoa RegA, RegB;
- PtrPes = fopen("Pessoa.dat", "rb+");
- fseek(PtrPes, 0, 2);
- NumR = ftell(PtrPes) / sizeof(TpPessoa);
- while(NumR > 0)
- {
- for(a = 0; a < NumR - 1; a++)
- {
- fseek(PtrPes, a * sizeof(TpPessoa), 0);
- fread(&RegA, sizeof(TpPessoa), 1, PtrPes);
- fread(&RegB, sizeof(TpPessoa), 1, PtrPes);
- if(RegA.pont < RegB.pont)
- {
- fseek(PtrPes, a * sizeof(TpPessoa), 0);
- fwrite(&RegB, sizeof(TpPessoa), 1, PtrPes);
- fwrite(&RegA, sizeof(TpPessoa), 1, PtrPes);
- }
- }
- NumR--;
- }
- fclose(PtrPes);
- }
- void RankingJogadores(FILE *PtrPes)
- {
- int linha = 5;
- TpPessoa Pes;
- system("cls");
- QuadroFlexivel(1, 1, 80, 3);
- gotoxy(30, 2);
- printf("Ranking dos Jogadores");
- PtrPes = fopen("Pessoa.dat", "rb");
- if(PtrPes == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de jogadores inexistente");
- textcolor(15);
- }
- else
- {
- OrdenaJogadoresPontuacao(PtrPes);
- rewind(PtrPes);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- while(!feof(PtrPes))
- {
- if(Pes.status == 1)
- {
- ImprimePessoa(Pes, linha);
- linha += 6;
- }
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- }
- gotoxy(1, 1);
- }
- fclose(PtrPes);
- getch();
- }
- void ImprimeJogada(TpPalavForca Jog, int linha)
- {
- QuadroFlexivel(2, linha - 1, 79, linha + 4);
- gotoxy(3, linha++);
- textcolor(14);
- printf("Login: ");
- textcolor(15);
- printf("%s", Jog.Login);
- gotoxy(4, linha++);
- textcolor(14);
- printf("Palavra: ");
- textcolor(15);
- printf("%s", Jog.Palavra);
- gotoxy(4, linha);
- textcolor(14);
- if(Jog.Acertou == 0)
- printf("Jogador perdeu");
- else
- printf("Joador ganhou");
- textcolor(15);
- }
- void ConsultaJogadas(FILE *PtrPalavForca)
- {
- TpPalavForca PalForca;
- char loginAux[10];
- int linha = 7, Pos;
- system("cls");
- QuadroFlexivel(1, 1, 80, 3);
- gotoxy(30, 2);
- printf("Consulta de Jogadas");
- PtrPalavForca = fopen("PalavraForca.dat", "rb");
- if(PtrPalavForca == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de jogadas inexistente");
- textcolor(15);
- }
- else
- {
- gotoxy(2, 5);
- printf("Digite o login: ");
- fflush(stdin);
- gets(loginAux);
- while(strcmp(loginAux, "\0") != 0)
- {
- rewind(PtrPalavForca);
- fread(&PalForca, sizeof(TpPalavForca), 1, PtrPalavForca);
- while(!feof(PtrPalavForca))
- {
- if(strcmp(PalForca.Login, loginAux) == 0)
- {
- ImprimeJogada(PalForca, linha);
- linha += 6;
- }
- fread(&PalForca, sizeof(TpPalavForca), 1, PtrPalavForca);
- }
- gotoxy(20, linha);
- printf("Relatorio concluido");
- gotoxy(1, 1);
- getch();
- system("cls");
- QuadroFlexivel(1, 1, 80, 3);
- gotoxy(30, 2);
- printf("Consulta de Jogadas");
- gotoxy(2, 5);
- printf("Digite o login: ");
- fflush(stdin);
- gets(loginAux);
- }
- }
- fclose(PtrPalavForca);
- getch();
- }
- int UsuarioGanhou(char Letras[40], char Palavra[40])
- {
- int i, Cont = 0;
- for(i = 0; i < strlen(Palavra); i++)
- if(TemLetraPalavra(Letras, Palavra[i]) >= 0)
- Cont++;
- if(Cont == strlen(Palavra))
- return 1;
- else
- return 0;
- }
- void Desenha(char Palavra[40], char LetrasCorretas[40], int NumErros)
- {
- int i, j;
- textcolor(14);
- gotoxy(45, 5);
- printf("Chances restantes: ");
- textcolor(15);
- printf("%d", 6 - NumErros);
- textcolor(14);
- if(NumErros >= 1)
- {
- gotoxy(30, 10);
- printf("%c", 2);
- }
- if(NumErros >= 2)
- {
- gotoxy(30, 11);
- printf("%c", '|');
- }
- if(NumErros >= 3)
- {
- gotoxy(29,11);
- printf("%c", '/');
- }
- if(NumErros >= 4)
- {
- gotoxy(31,11);
- printf("%c", '\\');
- }
- if(NumErros >= 5)
- {
- gotoxy(29,12);
- printf("%c", '/');
- }
- if(NumErros >= 6)
- {
- gotoxy(31,12);
- printf("%c", '\\');
- }
- textcolor(15);
- for(i = 0; i < strlen(Palavra); i++)
- {
- gotoxy((i+2) * 5, 15);
- printf("___");
- }
- textcolor(14);
- gotoxy(2, 6);
- textcolor(14);
- printf("Letras ja colocadas: ");
- gotoxy(25, 6);
- for(i = 0; i < strlen(LetrasCorretas); i++)
- printf("%c ", LetrasCorretas[i]);
- for(i = 0; LetrasCorretas[i] != '\0'; i++)
- {
- for(j = 0; j < strlen(Palavra); j++)
- if(toupper(Palavra[j]) == toupper(LetrasCorretas[i]))
- {
- gotoxy((j + 2) * 5, 14);
- printf("%c", LetrasCorretas[i]);
- }
- }
- textcolor(15);
- gotoxy(20, 10);
- }
- int BuscaJogada(FILE *PtrJogada, char login[10], char palavra[40])
- {
- int i = 0;
- TpPalavForca Reg;
- rewind(PtrJogada);
- fread(&Reg, sizeof(TpPalavForca), 1, PtrJogada);
- while(!feof(PtrJogada) && (strcmp(Reg.Login, login) != 0 || strcmp(Reg.Palavra, palavra) != 0))
- fread(&Reg, sizeof(TpPalavForca), 1, PtrJogada);
- if(!feof(PtrJogada))
- return ftell(PtrJogada) - sizeof(TpPalavForca);
- else
- return -1;
- }
- void JogoForca(FILE *PtrPes, FILE *PtrPal)
- {
- FILE *PtrPalForca;
- TpPalavForca PalForca;
- TpPessoa Pes;
- TpPalavra Pal;
- int Pos, NumR, SenhaAux, UsuarioLogado = 0;
- int PosPalavra, Lingua, NumTentativas, TLLetras, Ganhou, i;
- char Letra, PalavraSorteada[40], VetLetras[40];
- system("cls");
- Cabecalho("Jogo da Forca");
- PtrPes = fopen("Pessoa.dat", "rb+");
- if(PtrPes == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de pessoas inexistente");
- textcolor(15);
- }
- else
- {
- PtrPal = fopen("Palavra.dat", "rb");
- if(PtrPal == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de palavras inexistente");
- textcolor(15);
- }
- else
- {
- fseek(PtrPal, 0, 2);
- NumR = ftell(PtrPal) / sizeof(TpPalavra);
- if(NumR == 0)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Nenhuma palavra cadastrada");
- textcolor(15);
- }
- else
- {
- do
- {
- system("cls");
- Cabecalho("Jogo da Forca");
- gotoxy(2, 4);
- printf("Login: ");
- fflush(stdin);
- gets(Pes.login);
- gotoxy(2, 5);
- printf("Senha: ");
- textcolor(0);
- scanf("%d", &SenhaAux);
- textcolor(15);
- Pos = BuscaExaustivaPessoa(PtrPes, Pes.login);
- if(Pos == -1)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Login inexistente");
- textcolor(15);
- }
- else
- {
- fseek(PtrPes, Pos, 0);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- if(Pes.senha != SenhaAux)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Senha errada");
- textcolor(15);
- }
- else
- UsuarioLogado = 1;
- }
- getch();
- }while(strcmp(Pes.login, "\0") != 0 && UsuarioLogado == 0);
- }
- if(UsuarioLogado == 1)
- {
- PtrPalForca = fopen("PalavraForca.dat", "ab+");
- do
- {
- system("cls");
- Cabecalho("Jogo da forca");
- do
- {
- Lingua = rand() % 2;
- PosPalavra = rand() % NumR;
- fseek(PtrPal, PosPalavra * sizeof(TpPalavra), 0);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- if(Lingua == 0)
- strcpy(PalavraSorteada, Pal.port);
- else
- strcpy(PalavraSorteada, Pal.ing);
- gotoxy(30, 18);
- printf("%d", NumR);
- }while(BuscaJogada(PtrPalForca, Pes.login, PalavraSorteada) != -1);
- NumTentativas = 6;
- strcpy(VetLetras, "\0");
- TLLetras = 0;
- while(NumTentativas > 0 && UsuarioGanhou(VetLetras, PalavraSorteada) == 0)
- {
- system("cls");
- Cabecalho("Jogo da forca");
- gotoxy(2, 4);
- textcolor(14);
- printf("Dica: ");
- textcolor(15);
- printf("%s", Pal.significado);
- gotoxy(2, 5);
- textcolor(14);
- printf("Lingua: ");
- textcolor(15);
- if(Lingua == 0)
- printf("Portugues");
- else
- printf("Ingles");
- Desenha(PalavraSorteada, VetLetras, 6 - NumTentativas);
- gotoxy(2, 7);
- printf("Digite uma letra: ");
- fflush(stdin);
- Letra = getche();
- if(TemLetraPalavra(VetLetras, Letra) >= 0)
- {
- gotoxy(30, 8);
- textcolor(14);
- printf("Voce ja usou essa letra!");
- }
- else
- {
- gotoxy(30, 8);
- if(TemLetraPalavra(PalavraSorteada, Letra) >= 0)
- {
- textcolor(2);
- printf("Acertou a letra");
- textcolor(15);
- }
- else
- {
- textcolor(4);
- printf("Errou a letra");
- textcolor(15);
- NumTentativas--;
- }
- VetLetras[TLLetras++] = Letra;
- VetLetras[TLLetras] = '\0';
- }
- getch();
- }
- Desenha(PalavraSorteada, VetLetras, 6 - NumTentativas);
- if(NumTentativas == 0)
- {
- textcolor(4);
- gotoxy(2, 17);
- printf("Voce perdeu! A palavra era: %s", PalavraSorteada);
- Ganhou = 0;
- }
- else
- {
- Pes.pont += Pal.pont;
- fseek(PtrPes, Pos, 0);
- fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
- Ganhou = 1;
- textcolor(2);
- gotoxy(2, 17);
- printf("Voce ganhou!");
- }
- PalForca.Acertou = Ganhou;
- strcpy(PalForca.Login, Pes.login);
- strcpy(PalForca.Palavra, PalavraSorteada);
- fwrite(&PalForca, sizeof(TpPalavForca), 1, PtrPalForca);
- gotoxy(2, 18);
- textcolor(14);
- printf("Deseja jogar novamente? (S/N):");
- textcolor(15);
- }while(toupper(getche()) == 'S');
- fclose(PtrPalForca);
- }
- }
- fclose(PtrPal);
- }
- fclose(PtrPes);
- getch();
- }
- char Menu(void)
- {
- int i;
- system("cls");
- Quadro();
- textcolor(14);
- gotoxy(27, 2);
- printf("ATP 2 - JOGO DA FORCA\n");
- for(i = 2; i <= 79; i++)
- {
- gotoxy(i, 3);
- printf("%c", 205);
- }
- textbackground(4);
- gotoxy(4, 4);
- printf(" MENU DE PALAVRAS ");
- gotoxy(4, 5);
- printf("[A] - Cadastrar palavras ");
- gotoxy(4, 6);
- printf("[B] - Relatorio de palavras ");
- gotoxy(4, 7);
- printf("[C] - Alteracao de palavras ");
- gotoxy(4, 8);
- printf("[D] - Consulta de palavras ");
- gotoxy(4, 9);
- printf("[E] - Exclusao Fisica de Palavras");
- gotoxy(4, 10);
- printf("[F] - Exclusao Logica de Palavras");
- gotoxy(4, 11);
- printf("[G] - Ordenar Palavras ");
- gotoxy(40, 4);
- printf(" MENU DE PESSOAS ");
- gotoxy(40, 5);
- printf("[H] - Cadastrar pessoas ");
- gotoxy(40, 6);
- printf("[I] - Relatorio de pessoas ");
- gotoxy(40, 7);
- printf("[J] - Alteracao de pessoas ");
- gotoxy(40, 8);
- printf("[K] - Consulta de pessoas ");
- gotoxy(40, 9);
- printf("[L] - Exclusao Fisica de Pessoas ");
- gotoxy(40, 10);
- printf("[M] - Exclusao Logica de Pessoas ");
- gotoxy(40, 11);
- printf("[N] - Ordenar Pessoas Por Nome ");
- gotoxy(25, 13);
- printf(" MENU GERAL ");
- gotoxy(4, 15);
- printf("[O] - JOGAR FORCA ");
- gotoxy(40, 15);
- printf("[P] - Tradutor de frases ");
- gotoxy(4, 16);
- printf("[Q] - Insercao Automatica ");
- gotoxy(40, 16);
- printf("[R] - Ranking dos Jogadores ");
- gotoxy(4, 19);
- printf("[ESC] - Sair ");
- gotoxy(40, 19);
- printf("[S] - Consulta de jogadas ");
- textbackground(0);
- textcolor(7);
- return toupper(getche());
- }
- void TestaBusca(FILE *PtrPes)
- {
- system("cls");
- PtrPes = fopen("Pessoa.dat", "rb+");
- char login[10];
- fflush(stdin);
- gets(login);
- printf("\n%d", BuscaSentinelaPessoa(PtrPes, login));
- fclose(PtrPes);
- getch();
- }
- void Executa(void)
- {
- char Op;
- FILE *PtrArq, *PtrPes, *PtrPalavForca;
- //TestaBusca(PtrPes);
- Op = Menu();
- while(Op != 27)
- {
- switch(Op)
- {
- case 'A':
- CadastraPalavra(PtrArq);
- break;
- case 'B':
- RelatorioPalavras(PtrArq);
- break;
- case 'C':
- AlteracaoPalavra(PtrArq);
- break;
- case 'D':
- ConsultaPalavras(PtrArq);
- break;
- case 'E':
- ExclusaoFisicaPalavra(PtrArq);
- break;
- case 'F':
- ExclusaoLogicaPalavra(PtrArq);
- break;
- case 'G':
- BubbleSortPalavra(PtrArq);
- system("cls");
- gotoxy(40, 2);
- printf("Palavras ordenadas");
- getch();
- break;
- case 'H':
- CadastraPessoa(PtrPes);
- break;
- case 'I':
- RelatorioPessoa(PtrPes);
- break;
- case 'J':
- AlteracaoPessoa(PtrPes);
- break;
- case 'K':
- ConsultaPessoa(PtrPes);
- break;
- case 'L':
- ExclusaoFisicaPessoa(PtrPes);
- break;
- case 'M':
- ExclusaoLogicaPessoa(PtrPes);
- break;
- case 'N':
- BubbleSortPessoa(PtrPes);
- system("cls");
- gotoxy(40, 2);
- printf("Pessoas ordenadas");
- getch();
- break;
- case 'O':
- JogoForca(PtrPes, PtrArq);
- break;
- case 'P':
- Tradutor(PtrArq);
- break;
- case 'Q':
- InsercaoAutomatica(PtrPes, PtrArq);
- break;
- case 'R':
- RankingJogadores(PtrPes);
- break;
- case 'S':
- ConsultaJogadas(PtrPalavForca);
- break;
- default:
- printf("Opcao invalida\n");
- getch();
- break;
- }
- Op = Menu();
- }
- getch();
- }
- int main(void)
- {
- srand(time(NULL));
- Executa();
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement