Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct jogador{
- char userName[50];
- char password[50];
- char nome[100];
- int idade;
- int pontuacao;
- char data[50];
- char hora[50];
- } JOGADOR;
- typedef struct administrador{
- char userName[50];
- char password[50];
- } ADMINISTRADOR;
- typedef struct infoEM {
- int numero;
- char enunciado[200];
- char respostaCorreta[200];
- char respostaIncorreta1[200];
- char respostaIncorreta2[200];
- char respostaIncorreta3[200];
- } INFO_EM;
- typedef struct infoVF {
- int numero;
- char enunciado[200];
- char respostaCorreta[200];
- char respostaIncorreta[200];
- } INFO_VF;
- typedef struct infoO {
- int numero;
- char enunciado[2000];
- char respostaCorreta[20];
- } INFO_O;
- typedef struct infoT {
- int numero;
- char enunciado[2000];
- char respostaCorreta[500];
- } INFO_T;
- typedef struct elemEM {
- INFO_EM infoEM;
- struct elemEM *seguinte;
- struct elemEM *anterior;
- } ELEMENTO_EM;
- typedef struct elemVF {
- INFO_VF infoVF;
- struct elemVF *seguinte;
- struct elemVF *anterior;
- } ELEMENTO_VF;
- typedef struct elemO {
- INFO_O infoO;
- struct elemO *seguinte;
- struct elemO *anterior;
- } ELEMENTO_O;
- typedef struct elemT {
- INFO_T infoT;
- struct elemT *seguinte;
- struct elemT *anterior;
- } ELEMENTO_T;
- ELEMENTO_EM *iniListaEM = NULL;
- ELEMENTO_EM *fimListaEM = NULL;
- ELEMENTO_VF *iniListaVF = NULL;
- ELEMENTO_VF *fimListaVF = NULL;
- ELEMENTO_O *iniListaO = NULL;
- ELEMENTO_O *fimListaO = NULL;
- ELEMENTO_T *iniListaT = NULL;
- ELEMENTO_T *fimListaT = NULL;
- void criarAdministrador (ADMINISTRADOR administrador){
- FILE *registoAdministradores;
- registoAdministradores = fopen ("registoAdministradores.dat", "ab");
- if (registoAdministradores == NULL){
- printf ("ERRO na abertura do ficheiro <registoAdministradores.dat>. \n \a");
- return;
- }
- printf ("***** CRIACAO DE ADMINISTRADOR ***** \n");
- printf ("************************************ \n");
- printf ("Introduza o username que pretende criar: \n");
- fflush(stdin);
- scanf ("%s", &administrador.userName);
- printf ("Introduza a password do novo username: \n ");
- fflush(stdin);
- scanf ("%s", &administrador.password);
- fwrite (&administrador, sizeof (ADMINISTRADOR), 1, registoAdministradores);
- fclose (registoAdministradores);
- }
- void criarJogador (JOGADOR jogador){
- FILE *registoJogadores;
- registoJogadores = fopen ("registoJogadores.dat", "ab");
- if (registoJogadores == NULL){
- printf ("ERRO na abertura do ficheiro <registoJogadores.dat>. \n \a");
- return;
- }
- printf ("***** CRIACAO DE JOGADOR ***** \n");
- printf ("****************************** \n");
- printf ("Introduza o username que pretende criar: \n");
- fflush(stdin);
- scanf ("%s", &jogador.userName);
- printf ("Introduza a password do novo username: \n ");
- fflush(stdin);
- scanf ("%s", &jogador.password);
- printf ("Introduza o seu nome: \n");
- fflush(stdin);
- scanf ("%s", &jogador.nome);
- printf ("Introduza a sua idade: \n");
- fflush(stdin);
- scanf ("%i", &jogador.idade);
- fwrite (&jogador, sizeof (JOGADOR), 1, registoJogadores);
- fclose (registoJogadores);
- }
- void listarAdministradores (ADMINISTRADOR administrador){
- FILE *registoAdministradores;
- ADMINISTRADOR administradorTemp;
- int resultado = 0;
- registoAdministradores = fopen ("registoAdministradores.dat", "rb");
- if (registoAdministradores == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoAdministradores.dat>. \n");
- return;
- }
- printf ("***** LISTAGEM DE ADMINISTRADORES ***** \n");
- printf ("*************************************** \n");
- while (!feof(registoAdministradores)){
- resultado = fread (&administradorTemp, sizeof (ADMINISTRADOR), 1, registoAdministradores);
- if (resultado){
- printf ("Username: %s\nPassword: %s\n\n",
- administradorTemp.userName, administradorTemp.password);
- }
- }
- fclose (registoAdministradores);
- }
- int listarJogadores (JOGADOR jogador){
- JOGADOR jogadorTemp;
- char *resultado = 0;
- FILE *registoJogadores;
- int i=0;
- registoJogadores = fopen ("registoJogadores.dat", "rb");
- if (registoJogadores == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoJogadores.dat>. \n");
- return -1;
- }
- printf ("***** LISTAGEM DE JOGADORES ***** \n");
- printf ("********************************* \n");
- i=1;
- while (!feof(registoJogadores)){
- resultado = fread (&jogadorTemp, sizeof (JOGADOR), 1, registoJogadores);
- if (resultado){
- printf ("Username: %s\nPassword: %s\nNome: %s\nIdade: %i \n\n",
- jogadorTemp.userName, jogadorTemp.password, jogadorTemp.nome, jogadorTemp.idade);
- i++;
- }
- }
- fclose (registoJogadores);
- return 0;
- }
- // retorna 0 se o utilizador nao existir, 1 se a identificacao estiver errada e 2 se existir
- int existeAdministrador (ADMINISTRADOR administrador){
- int resultado = 0;
- ADMINISTRADOR administradorTemp;
- FILE *registoAdministradores;
- registoAdministradores = fopen ("registoAdministradores.dat", "rb");
- if (registoAdministradores == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoAdministradores.dat>. \n");
- return 0;
- }
- printf ("***** LOGIN COMO ADMINISTRADOR ***** \n");
- printf ("************************************ \n");
- printf ("Introduza o seu username: (NOTA - Maximo de 50 carateres) \n");
- fflush(stdin);
- scanf ("%s", &administrador.userName);
- printf ("Introduza a sua password: (NOTA - Maximo de 50 carateres) \n");
- fflush(stdin);
- scanf ("%s", &administrador.password);
- while (!feof(registoAdministradores)){
- resultado = fread (&administradorTemp, sizeof (ADMINISTRADOR), 1, registoAdministradores);
- if (strcmp(administrador.userName, administradorTemp.userName) == 0 && strcmp(administrador.password, administradorTemp.password) == 0){
- return 2;
- }
- if (strcmp(administrador.userName, administradorTemp.userName) == 0 && strcmp(administrador.password, administradorTemp.password) != 0){
- return 1;
- }
- }
- fclose (registoAdministradores);
- return 0;
- }
- // retorna 0 se o utilizador nao existir, 1 se a identificacao estiver errada e 2 se existir
- int existeJogador (JOGADOR jogador){
- int resultado = 0;
- JOGADOR jogadorTemp;
- FILE *registoJogadores;
- registoJogadores = fopen ("registoJogadores.dat", "rb");
- if (registoJogadores == NULL){
- printf ("ERRO na abertura do ficheiro <registoJogadores.dat>. \n \a");
- return 0;
- }
- printf ("***** LOGIN COMO JOGADOR ***** \n");
- printf ("****************************** \n");
- printf ("Introduza o seu username: \n");
- fflush(stdin);
- scanf ("%s", &jogador.userName);
- printf ("Introduza a sua password: (NOTA - Maximo de 50 carateres) \n");
- fflush(stdin);
- scanf ("%s", &jogador.password);
- while (!feof(registoJogadores)){
- resultado = fread (&jogadorTemp, sizeof (JOGADOR), 1, registoJogadores);
- if (strcmp(jogador.userName, jogadorTemp.userName) == 0 && strcmp(jogador.password, jogadorTemp.password) == 0){
- return 2;
- }
- if (strcmp(jogador.userName, jogadorTemp.userName) == 0 && strcmp(jogador.password, jogadorTemp.password) != 0){
- return 1;
- }
- }
- fclose (registoJogadores);
- return 0;
- }
- void acrescentarFimListaEM (ELEMENTO_EM **iniListaEM, ELEMENTO_EM **fimListaEM, INFO_EM newInfoEM){
- ELEMENTO_EM *novoEM = NULL;
- novoEM = (ELEMENTO_EM *) malloc (1 * sizeof (ELEMENTO_EM));
- if (novoEM == NULL){
- printf ("ERRO ao reservar memoria. \n \a");
- return;
- }
- novoEM->infoEM = newInfoEM;
- novoEM->seguinte = NULL;
- novoEM->anterior = NULL;
- if (*fimListaEM == NULL){
- *iniListaEM = novoEM;
- *fimListaEM = novoEM;
- }
- else{
- novoEM->anterior = (*fimListaEM);
- (*fimListaEM)->seguinte = novoEM;
- (*fimListaEM) = novoEM;
- }
- free (novoEM);
- }
- void acrescentarFimListaVF (ELEMENTO_VF **iniListaVF, ELEMENTO_VF **fimListaVF, INFO_VF newInfoVF){
- ELEMENTO_VF *novoVF = NULL;
- novoVF = (ELEMENTO_VF *) malloc (1 * sizeof (ELEMENTO_VF));
- if (novoVF == NULL){
- printf ("ERRO ao reservar memoria. \n \a");
- return;
- }
- novoVF->infoVF = newInfoVF;
- novoVF->seguinte = NULL;
- novoVF->anterior = NULL;
- if (*fimListaVF == NULL){
- *iniListaVF = novoVF;
- *fimListaVF = novoVF;
- }
- else{
- novoVF->anterior = (*fimListaVF);
- (*fimListaVF)->seguinte = novoVF;
- (*fimListaVF) = novoVF;
- }
- free (novoVF);
- }
- void acrescentarFimListaO (ELEMENTO_O **iniListaO, ELEMENTO_O **fimListaO, INFO_O newInfoO){
- ELEMENTO_O *novoO = NULL;
- novoO = (ELEMENTO_O *) malloc (1 * sizeof (ELEMENTO_O));
- if (novoO == NULL){
- printf ("ERRO ao reservar memoria. \n \a");
- return;
- }
- novoO->infoO = newInfoO;
- novoO->seguinte = NULL;
- novoO->anterior = NULL;
- if (*fimListaO == NULL){
- *iniListaO = novoO;
- *fimListaO = novoO;
- }
- else{
- novoO->anterior = (*fimListaO);
- (*fimListaO)->seguinte = novoO;
- (*fimListaO) = novoO;
- }
- free (novoO);
- }
- void acrescentarFimListaT (ELEMENTO_T **iniListaT, ELEMENTO_T **fimListaT, INFO_T newInfoT){
- ELEMENTO_T *novoT = NULL;
- novoT = (ELEMENTO_T *) malloc (1 * sizeof (ELEMENTO_T));
- if (novoT == NULL){
- printf ("ERRO ao reservar memoria. \n \a");
- return;
- }
- novoT->infoT = newInfoT;
- novoT->seguinte = NULL;
- novoT->anterior = NULL;
- if (*fimListaT == NULL){
- *iniListaT = novoT;
- *fimListaT = novoT;
- }
- else{
- novoT->anterior = (*fimListaT);
- (*fimListaT)->seguinte = novoT;
- (*fimListaT) = novoT;
- }
- free (novoT);
- }
- void listarCrescentePerguntasEM (ELEMENTO_EM *iniListaEM){
- ELEMENTO_EM *auxEM = NULL;
- if (iniListaEM == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxEM = iniListaEM; auxEM != NULL; auxEM = auxEM->seguinte){
- printf ("Enunciado: %s \n", auxEM->infoEM.enunciado);
- printf ("Resposta Correta: %s \n", auxEM->infoEM.respostaCorreta);
- printf ("Resposta Incorreta 1: %s \n", auxEM->infoEM.respostaIncorreta1);
- printf ("Resposta Incorreta 2: %s \n", auxEM->infoEM.respostaIncorreta2);
- printf ("Resposta Incorreta 3: %s \n", auxEM->infoEM.respostaIncorreta3);
- }
- }
- void listarCrescentePerguntasVF (ELEMENTO_VF *iniListaVF){
- ELEMENTO_VF *auxVF = NULL;
- if (iniListaVF == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxVF = iniListaVF; auxVF != NULL; auxVF = auxVF->seguinte){
- printf ("Enunciado: %s \n", auxVF->infoVF.numero, auxVF->infoVF.enunciado);
- printf ("Resposta Correta: %s \n", auxVF->infoVF.respostaCorreta);
- printf ("Resposta Incorreta: %s \n", auxVF->infoVF.respostaIncorreta);
- }
- }
- void listarCrescentePerguntasO (ELEMENTO_O *iniListaO){
- ELEMENTO_O *auxO = NULL;
- if (iniListaO == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxO = iniListaO; auxO != NULL; auxO = auxO->seguinte){
- printf ("Enunciado: %s \n", auxO->infoO.enunciado);
- printf ("Resposta Correta: %s \n", auxO->infoO.respostaCorreta);
- }
- }
- void listarCrescentePerguntasT (ELEMENTO_T *iniListaT){
- ELEMENTO_T *auxT = NULL;
- if (iniListaT == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxT = iniListaT; auxT != NULL; auxT = auxT->seguinte){
- printf ("Enunciado: %s \n", auxT->infoT.enunciado);
- printf ("Resposta Correta: %s \n", auxT->infoT.respostaCorreta);
- }
- }
- void lerFicheiroBinarioPerguntasEM (FILE *registoDePerguntasEM){
- int resultadoEM = 0;
- INFO_EM infoEMTemp;
- registoDePerguntasEM = fopen ("registoDePerguntasEM.dat", "rb");
- if (registoDePerguntasEM == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasEM.dat>. \n \a");
- return;
- }
- while (!feof(registoDePerguntasEM)){
- resultadoEM = fread (&infoEMTemp, sizeof (INFO_EM), 1, registoDePerguntasEM);
- if (resultadoEM){
- printf ("Numero da pergunta: %i. \n", infoEMTemp.numero);
- printf ("Enunciado: %s \n", infoEMTemp.enunciado);
- printf ("Resposta Correta: %s \n", infoEMTemp.respostaCorreta);
- printf ("Resposta Incorreta 1: %s \n", infoEMTemp.respostaIncorreta1);
- printf ("Resposta Incorreta 2: %s \n", infoEMTemp.respostaIncorreta2);
- printf ("Resposta Incorreta 3: %s \n", infoEMTemp.respostaIncorreta3);
- }
- }
- fclose (registoDePerguntasEM);
- }
- void lerFicheiroBinarioPerguntasVF (FILE *registoDePerguntasVF){
- int resultadoVF = 0;
- INFO_VF infoVFTemp;
- registoDePerguntasVF = fopen ("registoDePerguntasVF.dat", "rb");
- if (registoDePerguntasVF == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasVF.dat>. \n \a");
- return;
- }
- while (!feof(registoDePerguntasVF)){
- resultadoVF = fread (&infoVFTemp, sizeof (INFO_VF), 1, registoDePerguntasVF);
- if (resultadoVF){
- printf ("Numero da pergunta: %i. \n", infoVFTemp.numero);
- printf ("Enunciado: %s \n", infoVFTemp.enunciado);
- printf ("Resposta Correta: %s \n", infoVFTemp.respostaCorreta);
- printf ("Resposta Incorreta: %s \n", infoVFTemp.respostaIncorreta);
- }
- }
- fclose (registoDePerguntasVF);
- }
- void lerFicheiroBinarioPerguntasO (FILE *registoDePerguntasO){
- int resultadoO = 0;
- INFO_O infoOTemp;
- registoDePerguntasO = fopen ("registoDePerguntasO.dat", "rb");
- if (registoDePerguntasO == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasO.dat>. \n \a");
- return;
- }
- while (!feof(registoDePerguntasO)){
- resultadoO = fread (&infoOTemp, sizeof (INFO_O), 1, registoDePerguntasO);
- if (resultadoO){
- printf ("Numero da pergunta: %i. \n", infoOTemp.numero);
- printf ("Enunciado: %s \n", infoOTemp.enunciado);
- printf ("Resposta Correta: %s \n", infoOTemp.respostaCorreta);
- }
- }
- fclose (registoDePerguntasO);
- }
- void lerFicheiroBinarioPerguntasT (FILE *registoDePerguntasT){
- int resultadoT = 0;
- INFO_T infoTTemp;
- registoDePerguntasT = fopen ("registoDePerguntasT.dat", "rb");
- if (registoDePerguntasT == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoDePerguntasT.dat>. \n \a");
- return;
- }
- while (!feof(registoDePerguntasT)){
- resultadoT = fread (&infoTTemp, sizeof (INFO_T), 1, registoDePerguntasT);
- if (resultadoT){
- printf ("Numero da pergunta: %i. \n", infoTTemp.numero);
- printf ("Enunciado: %s \n", infoTTemp.enunciado);
- printf ("Resposta Correta: %s \n", infoTTemp.respostaCorreta);
- }
- }
- fclose (registoDePerguntasT);
- }
- void acrescentarPerguntas (int *numTotalEM, int *numTotalVF, int *numTotalO, int *numTotalT){
- INFO_EM newInfoEM;
- INFO_VF newInfoVF;
- INFO_O newInfoO;
- INFO_T newInfoT;
- FILE *registoDePerguntasEM;
- FILE *registoDePerguntasVF;
- FILE *registoDePerguntasO;
- FILE *registoDePerguntasT;
- int opcao;
- printf ("***** ACRESCIMO DE PERGUNTAS ***** \n");
- printf ("********************************** \n\n");
- do{
- printf ("Que tipo de pergunta pretende acrescentar? \n");
- printf ("1. Escolha Multipla \n");
- printf ("2. Verdadeiro ou Falso \n");
- printf ("3. Ordenacao \n");
- printf ("4. Texto \n");
- printf ("0. Sair \n");
- fflush (stdin);
- scanf ("%i", &opcao);
- switch (opcao){
- case 1 : *numTotalEM = *numTotalEM + 1;
- printf ("Esta pergunta sera o numero %i do tipo <Escolha Multipla>. \n", *numTotalEM);
- printf ("Introduza o enunciado da pergunta: \n" );
- fflush (stdin);
- gets (newInfoEM.enunciado);
- printf ("Introduza a resposta correta: \n");
- fflush (stdin);
- gets (newInfoEM.respostaCorreta);
- printf ("Introduza a primeira resposta incorreta: \n");
- fflush (stdin);
- gets (newInfoEM.respostaIncorreta1);
- printf ("Introduza a segunda resposta incorreta: \n");
- fflush (stdin);
- gets (newInfoEM.respostaIncorreta2);
- printf ("Introduza a terceira resposta incorreta: \n");
- fflush (stdin);
- gets (newInfoEM.respostaIncorreta3);
- acrescentarFimListaEM (&iniListaEM, &fimListaEM, newInfoEM);
- break;
- case 2 : *numTotalVF = *numTotalVF + 1;
- printf ("Esta pergunta sera o numero %i do tipo <Verdadeiro ou Falso>. \n", *numTotalVF);
- printf ("Introduza o enunciado da pergunta: \n" );
- fflush (stdin);
- gets (newInfoVF.enunciado);
- printf ("Introduza a resposta correta: \n");
- fflush (stdin);
- gets (newInfoVF.respostaCorreta);
- printf ("Introduza a primeira resposta incorreta: \n");
- fflush (stdin);
- gets (newInfoVF.respostaIncorreta);
- acrescentarFimListaVF (&iniListaVF, &fimListaVF, newInfoVF);
- break;
- case 3 : *numTotalO = *numTotalO + 1;
- printf ("Esta pergunta sera o numero %i do tipo <Ordenacao>. \n", *numTotalO);
- printf ("Introduza o enunciado da pergunta: \n" );
- fflush (stdin);
- gets (newInfoO.enunciado);
- printf ("Introduza a resposta correta: \n");
- fflush (stdin);
- gets (newInfoO.respostaCorreta);
- acrescentarFimListaO (&iniListaO, &fimListaO, newInfoO);
- break;
- case 4 : *numTotalT = *numTotalT + 1;
- printf ("Esta pergunta sera o numero %i do tipo <Texto>. \n", *numTotalT);
- printf ("Introduza o enunciado da pergunta: \n" );
- fflush (stdin);
- gets (newInfoO.enunciado);
- printf ("Introduza a resposta correta:\n");
- fflush (stdin);
- gets (newInfoO.respostaCorreta);
- acrescentarFimListaT (&iniListaT, &fimListaT, newInfoT);
- break;
- }
- } while (opcao != 0);
- }
- void alterarPerguntaEM_Enunciado (char enunciadoEM []){
- ELEMENTO_EM *auxEM = NULL;
- if (iniListaEM == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxEM->infoEM.enunciado, enunciadoEM);
- }
- void alterarPerguntaEM_RC (char respostaCorretaEM []){
- ELEMENTO_EM *auxEM = NULL;
- if (iniListaEM == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxEM->infoEM.respostaCorreta, respostaCorretaEM);
- }
- void alterarPerguntaEM_RI1 (char respostaIncorreta1EM []){
- ELEMENTO_EM *auxEM = NULL;
- if (iniListaEM == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxEM->infoEM.respostaIncorreta1, respostaIncorreta1EM);
- }
- void alterarPerguntaEM_RI2 (char respostaIncorreta2EM []){
- ELEMENTO_EM *auxEM = NULL;
- if (iniListaEM == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxEM->infoEM.respostaIncorreta2, respostaIncorreta2EM);
- }
- void alterarPerguntaEM_RI3 ( char respostaIncorreta3EM []){
- ELEMENTO_EM *auxEM = NULL;
- if (iniListaEM == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxEM->infoEM.respostaIncorreta3, respostaIncorreta3EM);
- }
- void alterarPerguntaVF_Enunciado (char enunciadoVF []){
- ELEMENTO_VF *auxVF = NULL;
- if (iniListaVF == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxVF->infoVF.enunciado, enunciadoVF);
- }
- void alterarPerguntaVF_RC (char respostaCorretaVF []){
- ELEMENTO_VF *auxVF = NULL;
- if (iniListaVF == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxVF->infoVF.respostaCorreta, respostaCorretaVF);
- }
- void alterarPerguntaVF_RI (char respostaIncorretaVF []){
- ELEMENTO_VF *auxVF = NULL;
- if (iniListaVF == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxVF->infoVF.respostaIncorreta, respostaIncorretaVF);
- }
- void alterarPerguntaO_Enunciado (char enunciadoO []){
- ELEMENTO_O *auxO = NULL;
- if (iniListaO == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxO->infoO.enunciado, enunciadoO);
- }
- void alterarPerguntaO_RC (char respostaCorretaO []){
- ELEMENTO_O *auxO = NULL;
- if (iniListaO == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxO->infoO.respostaCorreta, respostaCorretaO);
- }
- void alterarPerguntaT_Enunciado (char enunciadoT []){
- ELEMENTO_T *auxT = NULL;
- if (iniListaT == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxT->infoT.enunciado, enunciadoT);
- }
- void alterarPerguntaT_RC (char respostaCorretaT []){
- ELEMENTO_T *auxT = NULL;
- if (iniListaT == NULL){
- printf ("Lista VAZIA ! \n");
- return;
- }
- strcpy (auxT->infoT.respostaCorreta, respostaCorretaT);
- }
- void alterarPerguntas (){
- int opcao = 0;
- int opcaoEM = 0;
- int opcaoVF = 0;
- int opcaoO = 0;
- int opcaoT = 0;
- char enunciadoEM[200];
- char respostaCorretaEM[200];
- char respostaIncorreta1EM[200];
- char respostaIncorreta2EM[200];
- char respostaIncorreta3EM[200];
- char enunciadoVF[200];
- char respostaCorretaVF[200];
- char respostaIncorretaVF[200];
- char enunciadoO[200];
- char respostaCorretaO[20];
- char enunciadoT[200];
- char respostaCorretaT[200];
- int resultadoEM = 0;
- int resultadoVF = 0;
- int resultadoO = 0;
- int resultadoT = 0;
- INFO_EM infoEMTemp;
- INFO_VF infoVFTemp;
- INFO_O infoOTemp;
- INFO_T infoTTemp;
- FILE *registoDePerguntasEM;
- FILE *registoDePerguntasVF;
- FILE *registoDePerguntasO;
- FILE *registoDePerguntasT;
- printf ("***** ALTERACAO DE PERGUNTAS ***** \n");
- printf ("********************************** \n\n");
- do {
- printf ("Que tipo de pergunta pretende alterar: \n");
- printf ("1. Escolha Multipla \n");
- printf ("2. Verdadeiro ou Falso \n");
- printf ("3. Ordenacao \n");
- printf ("4. Texto \n");
- printf ("0. Sair \n");
- fflush (stdin);
- scanf ("%i", &opcao);
- switch (opcao) {
- case 1 : printf ("Ira alterar uma pergunta do tipo <Escolha Multipla>. \n");
- listarCrescentePerguntasEM (iniListaEM);
- do{
- printf ("Qual a prte da perugn de <Escolha Multipla> que pretende alterar? \n");
- printf ("1. Enunciado \n");
- printf ("2. Resposta Correta \n");
- printf ("3. Resposta Incorreta 1 \n");
- printf ("4. Resposta Incorreta 2 \n");
- printf ("5. Resposta Incorreta 3 \n");
- printf ("0. Sair \n");
- fflush (stdin);
- scanf ("%i", &opcaoEM);
- switch (opcaoEM){
- case 1 : printf ("Introduza o novo Enunciado: \n");
- fflush (stdin);
- gets (enunciadoEM);
- alterarPerguntaEM_Enunciado (enunciadoEM);
- break;
- case 2 : printf ("Introduza a nova Resposta Correta: \n");
- fflush (stdin);
- gets (respostaCorretaEM);
- alterarPerguntaEM_RC (respostaCorretaEM);
- break;
- case 3 : printf ("Introduza a nova Resposta Incorreta 1: \n");
- fflush (stdin);
- gets (respostaIncorreta1EM);
- alterarPerguntaEM_RI1 (respostaIncorreta1EM);
- break;
- case 4 : printf ("Introduza a nova Resposta Incorreta 2: \n");
- fflush (stdin);
- gets (respostaIncorreta2EM);
- alterarPerguntaEM_RI2 (respostaIncorreta2EM);
- break;
- case 5 : printf ("Introduza a nova Resposta Incorreta 3: \n");
- fflush (stdin);
- gets (respostaIncorreta3EM);
- alterarPerguntaEM_RI3 (respostaIncorreta3EM);
- break;
- }
- } while (opcaoEM != 0);
- break;
- case 2 : printf ("Ira alterar uma pergunta do tipo <Verdadeiro ou Falso>. \n");
- listarCrescentePerguntasVF (iniListaVF);
- do{
- printf ("Qual o numero da pergunta de <Verdadeiro ou Falso> que pretende alterar? \n");
- printf ("1. Enunciado \n");
- printf ("2. Resposta Correta \n");
- printf ("3. Resposta Incorreta \n");
- printf ("0. Sair \n");
- fflush (stdin);
- scanf ("%i", &opcaoVF);
- switch (opcaoVF){
- case 1 : printf ("Introduza o novo Enunciado: \n");
- fflush (stdin);
- gets (enunciadoVF);
- alterarPerguntaVF_Enunciado (enunciadoVF);
- break;
- case 2 : printf ("Introduza a nova Resposta Correta: \n");
- fflush (stdin);
- gets (respostaCorretaVF);
- alterarPerguntaVF_RC (respostaCorretaVF);
- break;
- case 3 : printf ("Introduza a nova Resposta Incorreta: \n");
- fflush (stdin);
- gets (respostaIncorretaVF);
- alterarPerguntaVF_RI (respostaIncorretaVF);
- break;
- }
- } while (opcaoVF != 0);
- break;
- case 3 : printf ("Ira alterar uma pergunta do tipo <Ordenacao>. \n");
- listarCrescentePerguntasO (iniListaO);
- do{
- printf ("Qual o numero da pergunta de <Ordenar> que pretende alterar? \n");
- printf ("1. Enunciado \n");
- printf ("2. Resposta Correta \n");
- printf ("0. Sair \n");
- fflush (stdin);
- scanf ("%i", &opcaoO);
- switch (opcaoO){
- case 1 : printf ("Introduza o novo Enunciado: \n");
- fflush (stdin);
- gets (enunciadoO);
- alterarPerguntaO_Enunciado (enunciadoO);
- break;
- case 2 : printf ("Introduza a nova Resposta Correta: \n");
- fflush (stdin);
- gets (respostaCorretaO);
- alterarPerguntaO_RC (respostaCorretaO);
- break;
- }
- } while (opcaoO != 0);
- break;
- case 4 : printf ("Ira remover uma pergunta do tipo <Texto>. \n");
- listarCrescentePerguntasT (iniListaT);
- do{
- printf ("Qual o numero da pergunta de <Ordenar> que pretende alterar? \n");
- printf ("1. Enunciado \n");
- printf ("2. Resposta Correta \n");
- printf ("0. Sair \n");
- fflush (stdin);
- scanf ("%i", &opcaoT);
- switch (opcaoVF){
- case 1 : printf ("Introduza o novo Enunciado: \n");
- fflush (stdin);
- gets (enunciadoT);
- alterarPerguntaT_Enunciado (enunciadoT);
- break;
- case 2 : printf ("Introduza a nova Resposta Correta: \n");
- fflush (stdin);
- gets (respostaCorretaT);
- alterarPerguntaT_RC (respostaCorretaT);
- break;
- }
- } while (opcaoT != 0);
- break;
- }
- } while (opcao != 0);
- }
- void removerPerguntasEM (ELEMENTO_EM **iniListaEM, ELEMENTO_EM **fimListaEM, int numeroEM){
- ELEMENTO_EM *auxEM = NULL;
- auxEM = (ELEMENTO_EM *) malloc (1 * sizeof (ELEMENTO_EM *));
- if (auxEM == NULL){
- printf ("ERRO ao reservar memoria. \n \a");
- return;
- }
- auxEM = *iniListaEM;
- if (*iniListaEM == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- while (auxEM != NULL && auxEM->infoEM.numero != numeroEM){
- auxEM = auxEM->seguinte;
- }
- if (auxEM == NULL){
- printf ("Numero da pergunta NAO EXISTE. \n");
- return;
- }
- if (auxEM->anterior == NULL){
- (*iniListaEM) = auxEM->seguinte;
- if ((*iniListaEM) != NULL){
- (*iniListaEM)->anterior = NULL;
- }
- else{
- auxEM->anterior->seguinte = auxEM->seguinte;
- }
- }
- if (auxEM->seguinte == NULL){
- (*fimListaEM) = auxEM->anterior;
- if ((*fimListaEM) != NULL){
- (*fimListaEM)->seguinte = NULL;
- }
- else{
- auxEM->seguinte->anterior = auxEM->anterior;
- }
- }
- free (auxEM);
- }
- void removerPerguntasVF (ELEMENTO_VF **iniListaVF, ELEMENTO_VF **fimListaVF, int numeroVF){
- ELEMENTO_VF *auxVF = NULL;
- auxVF = (ELEMENTO_VF *) malloc (1 * sizeof (ELEMENTO_VF *));
- if (auxVF == NULL){
- printf ("ERRO ao reservar memoria. \n \a");
- return;
- }
- auxVF = *iniListaVF;
- if (*iniListaVF == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- while (auxVF != NULL && auxVF->infoVF.numero != numeroVF){
- auxVF = auxVF->seguinte;
- }
- if (auxVF == NULL){
- printf ("Numero da pergunta NAO EXISTE. \n");
- return;
- }
- if (auxVF->anterior == NULL){
- (*iniListaVF) = auxVF->seguinte;
- if ((*iniListaVF) != NULL){
- (*iniListaVF)->anterior = NULL;
- }
- else{
- auxVF->anterior->seguinte = auxVF->seguinte;
- }
- }
- if (auxVF->seguinte == NULL){
- (*fimListaVF) = auxVF->anterior;
- if ((*fimListaVF) != NULL){
- (*fimListaVF)->seguinte = NULL;
- }
- else{
- auxVF->seguinte->anterior = auxVF->anterior;
- }
- }
- free (auxVF);
- }
- void removerPerguntasO (ELEMENTO_O **iniListaO, ELEMENTO_O **fimListaO, int numeroO){
- ELEMENTO_O *auxO = NULL;
- auxO = (ELEMENTO_O *) malloc (1 * sizeof (ELEMENTO_O *));
- if (auxO == NULL){
- printf ("ERRO ao reservar memoria. \n \a");
- return;
- }
- auxO = *iniListaO;
- if (*iniListaO == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- while (auxO != NULL && auxO->infoO.numero != numeroO){
- auxO = auxO->seguinte;
- }
- if (auxO == NULL){
- printf ("Numero da pergunta NAO EXISTE. \n");
- return;
- }
- if (auxO->anterior == NULL){
- (*iniListaO) = auxO->seguinte;
- if ((*iniListaO) != NULL){
- (*iniListaO)->anterior = NULL;
- }
- else{
- auxO->anterior->seguinte = auxO->seguinte;
- }
- }
- if (auxO->seguinte == NULL){
- (*fimListaO) = auxO->anterior;
- if ((*fimListaO) != NULL){
- (*fimListaO)->seguinte = NULL;
- }
- else{
- auxO->seguinte->anterior = auxO->anterior;
- }
- }
- free (auxO);
- }
- void removerPerguntasT (ELEMENTO_T **iniListaT, ELEMENTO_T **fimListaT, int numeroT) {
- ELEMENTO_T *auxT = NULL;
- auxT = (ELEMENTO_T *) malloc (1 * sizeof (ELEMENTO_T *));
- if (auxT == NULL){
- printf ("ERRO ao reservar memoria. \n \a");
- return;
- }
- auxT = *iniListaT;
- if (iniListaT == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- while (auxT != NULL && auxT->infoT.numero != numeroT){
- auxT = auxT->seguinte;
- }
- if (auxT == NULL){
- printf ("Numero da pergunta NAO EXISTE. \n");
- return;
- }
- if (auxT->anterior == NULL){
- (*iniListaT) = auxT->seguinte;
- if ((*iniListaT) != NULL){
- (*iniListaT)->anterior = NULL;
- }
- else{
- auxT->anterior->seguinte = auxT->seguinte;
- }
- }
- if (auxT->seguinte == NULL){
- (*fimListaT) = auxT->anterior;
- if ((*fimListaT) != NULL){
- (*fimListaT)->seguinte = NULL;
- }
- else{
- auxT->seguinte->anterior = auxT->anterior;
- }
- }
- free (auxT);
- }
- void removerPerguntas (){
- int opcao = 0;
- int numeroEM = 0;
- int numeroVF = 0;
- int numeroO = 0;
- int numeroT = 0;
- int resultadoEM = 0;
- int resultadoVF = 0;
- int resultadoO = 0;
- int resultadoT = 0;
- INFO_EM infoEMTemp;
- INFO_VF infoVFTemp;
- INFO_O infoOTemp;
- INFO_T infoTTemp;
- FILE *registoDePerguntasEM;
- FILE *registoDePerguntasVF;
- FILE *registoDePerguntasO;
- FILE *registoDePerguntasT;
- printf ("***** REMOCAO DE PERGUNTAS ***** \n");
- printf ("******************************** \n\n");
- do {
- printf ("Que tipo de pergunta pretende remover? \n");
- printf ("1. Escolha Multipla \n");
- printf ("2. Verdadeiro ou Falso \n");
- printf ("3. Ordenacao \n");
- printf ("4. Texto \n");
- printf ("0. Sair \n");
- fflush (stdin);
- scanf ("%i", &opcao);
- switch (opcao){
- case 1 : printf ("Ira remover uma pergunta do tipo <Escolha Multipla>. \n");
- listarCrescentePerguntasEM (iniListaEM);
- printf ("Qual o numero da pergunta de <Escolha Multipla> que pretende remover? \n");
- fflush (stdin);
- scanf ("%i", &numeroEM);
- removerPerguntasEM (&iniListaEM, &fimListaEM, numeroEM);
- break;
- case 2 : printf ("Ira remover uma pergunta do tipo <Verdadeiro ou Falso>. \n");
- listarCrescentePerguntasVF (iniListaVF);
- printf ("Qual o numero da pergunta de <Verdadeiro ou Falso> que pretende remover? \n");
- fflush (stdin);
- scanf ("%i", &numeroVF);
- removerPerguntasVF (&iniListaVF, &fimListaVF, numeroVF);
- break;
- case 3 : printf ("Ira remover uma pergunta do tipo <Ordenacao>. \n");
- listarCrescentePerguntasO (iniListaO);
- printf ("Qual o numero da pergunta de <Ordenacao> que pretende remover? \n");
- fflush (stdin);
- scanf ("%i", &numeroO);
- removerPerguntasO (&iniListaO, &fimListaO, numeroO);
- break;
- case 4 : printf ("Ira remover uma pergunta do tipo <Escolha Multipla>. \n");
- listarCrescentePerguntasT (iniListaT);
- printf ("Qual o numero da pergunta de <Ordenacao> que pretende remover? \n");
- fflush (stdin);
- scanf ("%i", &numeroT);
- removerPerguntasT (&iniListaT, &fimListaT, numeroT);
- break;
- }
- } while (opcao != 0);
- }
- void menuAdministrador (ADMINISTRADOR administrador, JOGADOR jogador){
- int opcao;
- INFO_EM newInfoEM;
- INFO_VF newInfoVF;
- INFO_O newInfoO;
- INFO_T newInfoT;
- static int numTotalEM = 0;
- static int numTotalVF = 0;
- static int numTotalT = 0;
- static int numTotalO = 0;
- do{
- printf ("***** MENU DE ADMINISTRACAO ***** \n");
- printf ("********************************* \n");
- printf ("Introduza a opcao pretendida: \n");
- printf ("1. Acrescentar perguntas \n");
- printf ("2. Alterar perguntas \n");
- printf ("3. Remover perguntas \n");
- printf ("4. Criar Administrador \n");
- printf ("5. Listar Administradores \n");
- printf ("6. Listar Jogadores \n");
- printf ("0. Sair \n");
- fflush(stdin);
- scanf ("%i", &opcao);
- switch (opcao){
- case 1 : acrescentarPerguntas (&numTotalEM, &numTotalVF, &numTotalO, &numTotalT);
- break;
- case 2 : alterarPerguntas ();
- break;
- case 3 : removerPerguntas ();
- break;
- case 4 : criarAdministrador (administrador);
- break;
- case 5 : listarAdministradores (administrador);
- break;
- case 6 : listarJogadores (jogador);
- break;
- }
- } while (opcao != 0);
- }
- int jogoSmall (int novaPontuacao, ELEMENTO_EM *iniListaEM, ELEMENTO_VF *iniListaVF, ELEMENTO_O *iniListaO, ELEMENTO_T *iniListaT){
- char opcao2Utilizador[200];
- char opcao1Utilizador[10];
- ELEMENTO_EM *auxEM = NULL;
- ELEMENTO_VF *auxVF = NULL;
- ELEMENTO_O *auxO = NULL;
- ELEMENTO_T *auxT = NULL;
- printf ("***** JOGO DO TIPO S ***** \n");
- printf ("************************** \n\n");
- printf ("O jogo do tipo <Small> encontra-se indisponivel.\n");
- printf ("Pretende continuar e jogar com todas as perguntas existentes nos ficheiros armazenados? Sim/Nao \n");
- fflush(stdin);
- scanf ("%s", &opcao1Utilizador);
- if (strcmp (opcao1Utilizador, "NAO") == 0 ||
- strcmp (opcao1Utilizador, "nao") == 0 ||
- strcmp (opcao1Utilizador, "Nao") == 0 ||
- strcmp (opcao1Utilizador, "n") == 0 ){
- novaPontuacao = 0;
- }
- else {
- printf ("Perguntas do tipo <Escolha Multipla> \n");
- printf ("Escreva a resposta pretendida como esta presente no enunciado. \n");
- if (iniListaEM == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxEM = iniListaEM; auxEM != NULL; auxEM = auxEM->seguinte){
- printf ("Enunciado: %s \n", auxEM->infoEM.enunciado);
- printf ("%s: \n", auxEM->infoEM.respostaCorreta);
- printf ("%s: \n", auxEM->infoEM.respostaIncorreta1);
- printf ("%s: \n", auxEM->infoEM.respostaIncorreta2);
- printf ("%s: \n", auxEM->infoEM.respostaIncorreta3);
- scanf ("%s", &opcao2Utilizador);
- if (strcmp(opcao2Utilizador, auxEM->infoEM.respostaCorreta) == 0){
- novaPontuacao = novaPontuacao + 15;
- }
- else{
- if (strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta1) == 0 ||
- strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta2) == 0 ||
- strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta3) == 0){
- novaPontuacao = novaPontuacao - 10;
- }
- else{
- printf ("Resposta INEXISTENTE! \n \a");
- return;
- }
- }
- }
- printf ("Perguntas do tipo <Verdadeiro ou Falso>");
- printf ("Escreva a resposta apenas com <Verdadeiro> ou <Falso>. \n");
- if (iniListaVF == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxVF = iniListaVF; auxVF != NULL; auxVF = auxVF->seguinte){
- printf ("Enunciado: %s \n", auxVF->infoVF.enunciado);
- printf ("%s: \n", auxVF->infoVF.respostaCorreta);
- printf ("%s: \n", auxVF->infoVF.respostaIncorreta);
- scanf ("%s", &opcao2Utilizador);
- if (strcmp(opcao2Utilizador, auxVF->infoVF.respostaCorreta) == 0){
- novaPontuacao = novaPontuacao + 30;
- }
- else{
- if (strcmp(opcao2Utilizador, auxVF->infoVF.respostaIncorreta) == 0){
- novaPontuacao = novaPontuacao - 30;
- }
- else{
- printf ("Resposta INEXISTENTE! \n \a");
- return;
- }
- }
- }
- printf ("Perguntas do tipo <Ordenacao>");
- printf ("Escreva a resposta apenas ordenando com os numeros. \n");
- if (iniListaO == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxO = iniListaO; auxO != NULL; auxO = auxO->seguinte){
- printf ("Enunciado: %s \n", auxO->infoO.enunciado);
- printf ("%s: \n", auxO->infoO.respostaCorreta);
- fflush(stdin);
- scanf ("%s", &opcao2Utilizador);
- if (strcmp(opcao2Utilizador, auxO->infoO.respostaCorreta) == 0){
- novaPontuacao = novaPontuacao + 50;
- }
- else{
- novaPontuacao = novaPontuacao - 20;
- }
- }
- printf ("Perguntas do tipo <T>");
- printf ("Escreva a resposta apenas com um pequeno texto que ache que esteja correto. \n");
- if (iniListaT == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxT = iniListaT; auxT != NULL; auxT = auxT->seguinte){
- printf ("Enunciado: %s \n", auxT->infoT.enunciado);
- printf ("%s: \n", auxT->infoT.respostaCorreta);
- fflush(stdin);
- scanf ("%s", &opcao2Utilizador);
- if (strcmp(opcao2Utilizador, auxT->infoT.respostaCorreta) == 0){
- novaPontuacao = novaPontuacao + 10;
- }
- else{
- novaPontuacao = 0;
- }
- }
- }
- return novaPontuacao;
- }
- int jogoMedium (int novaPontuacao, ELEMENTO_EM *iniListaEM, ELEMENTO_VF *iniListaVF, ELEMENTO_O *iniListaO, ELEMENTO_T *iniListaT){
- char opcao2Utilizador[200];
- char opcao1Utilizador[10];
- ELEMENTO_EM *auxEM = NULL;
- ELEMENTO_VF *auxVF = NULL;
- ELEMENTO_O *auxO = NULL;
- ELEMENTO_T *auxT = NULL;
- printf ("***** JOGO DO TIPO M ***** \n");
- printf ("************************** \n\n");
- printf ("O jogo do tipo <Medium> encontra-se indisponivel.\n");
- printf ("Pretende continuar e jogar com todas as perguntas existentes nos ficheiros armazenados? Sim/Nao \n");
- scanf ("%s", &opcao1Utilizador);
- if (strcmp (opcao1Utilizador, "NAO") == 0 ||
- strcmp (opcao1Utilizador, "nao") == 0 ||
- strcmp (opcao1Utilizador, "Nao") == 0 ||
- strcmp (opcao1Utilizador, "n") == 0 ){
- novaPontuacao = 0;
- }
- else {
- printf ("Perguntas do tipo <Escolha Multipla> \n");
- printf ("Escreva a resposta pretendida como esta presente no enunciado. \n");
- if (iniListaEM == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxEM = iniListaEM; auxEM != NULL; auxEM = auxEM->seguinte){
- printf ("Enunciado: %s \n", auxEM->infoEM.enunciado);
- printf ("%s: \n", auxEM->infoEM.respostaCorreta);
- printf ("%s: \n", auxEM->infoEM.respostaIncorreta1);
- printf ("%s: \n", auxEM->infoEM.respostaIncorreta2);
- printf ("%s: \n", auxEM->infoEM.respostaIncorreta3);
- fflush(stdin);
- scanf ("%s", &opcao2Utilizador);
- if (strcmp(opcao2Utilizador, auxEM->infoEM.respostaCorreta) == 0){
- novaPontuacao = novaPontuacao + 15;
- }
- else{
- if (strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta1) == 0 ||
- strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta2) == 0 ||
- strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta3) == 0){
- novaPontuacao = novaPontuacao - 10;
- }
- else{
- printf ("Resposta INEXISTENTE! \n \a");
- return;
- }
- }
- }
- printf ("Perguntas do tipo <Verdadeiro ou Falso>");
- printf ("Escreva a resposta apenas com <Verdadeiro> ou <Falso>. \n");
- if (iniListaVF == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxVF = iniListaVF; auxVF != NULL; auxVF = auxVF->seguinte){
- printf ("Enunciado: %s \n", auxVF->infoVF.enunciado);
- printf ("%s: \n", auxVF->infoVF.respostaCorreta);
- printf ("%s: \n", auxVF->infoVF.respostaIncorreta);
- fflush(stdin);
- scanf ("%s", &opcao2Utilizador);
- if (strcmp(opcao2Utilizador, auxVF->infoVF.respostaCorreta) == 0){
- novaPontuacao = novaPontuacao + 30;
- }
- else{
- if (strcmp(opcao2Utilizador, auxVF->infoVF.respostaIncorreta) == 0){
- novaPontuacao = novaPontuacao - 30;
- }
- else{
- printf ("Resposta INEXISTENTE! \n \a");
- return;
- }
- }
- }
- printf ("Perguntas do tipo <Ordenacao>");
- printf ("Escreva a resposta apenas ordenando com os numeros. \n");
- if (iniListaO == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxO = iniListaO; auxO != NULL; auxO = auxO->seguinte){
- printf ("Enunciado: %s \n", auxO->infoO.enunciado);
- printf ("%s: \n", auxO->infoO.respostaCorreta);
- fflush(stdin);
- scanf ("%s", &opcao2Utilizador);
- if (strcmp(opcao2Utilizador, auxO->infoO.respostaCorreta) == 0){
- novaPontuacao = novaPontuacao + 50;
- }
- else{
- novaPontuacao = novaPontuacao - 20;
- }
- }
- printf ("Perguntas do tipo <T>");
- printf ("Escreva a resposta apenas com um pequeno texto que ache que esteja correto. \n");
- if (iniListaT == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxT = iniListaT; auxT != NULL; auxT = auxT->seguinte){
- printf ("Enunciado: %s \n", auxT->infoT.enunciado);
- printf ("%s: \n", auxT->infoT.respostaCorreta);
- fflush(stdin);
- scanf ("%s", &opcao2Utilizador);
- if (strcmp(opcao2Utilizador, auxT->infoT.respostaCorreta) == 0){
- novaPontuacao = novaPontuacao + 10;
- }
- else{
- novaPontuacao = 0;
- }
- }
- }
- return novaPontuacao;
- }
- int jogoLarge (int novaPontuacao, ELEMENTO_EM *iniListaEM, ELEMENTO_VF *iniListaVF, ELEMENTO_O *iniListaO, ELEMENTO_T *iniListaT){
- char opcao2Utilizador[200];
- char opcao1Utilizador[10];
- ELEMENTO_EM *auxEM = NULL;
- ELEMENTO_VF *auxVF = NULL;
- ELEMENTO_O *auxO = NULL;
- ELEMENTO_T *auxT = NULL;
- printf ("***** JOGO DO TIPO L ***** \n");
- printf ("************************** \n\n");
- printf ("O jogo do tipo <Large> encontra-se indisponivel.\n");
- printf ("Pretende continuar e jogar com todas as perguntas existentes nos ficheiros armazenados? Sim/Nao \n");
- scanf ("%s", &opcao1Utilizador);
- if (strcmp (opcao1Utilizador, "NAO") == 0 ||
- strcmp (opcao1Utilizador, "nao") == 0 ||
- strcmp (opcao1Utilizador, "Nao") == 0 ||
- strcmp (opcao1Utilizador, "n") == 0 ){
- novaPontuacao = 0;
- }
- else {
- printf ("Perguntas do tipo <Escolha Multipla> \n");
- printf ("Escreva a resposta pretendida como esta presente no enunciado. \n");
- if (iniListaEM == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxEM = iniListaEM; auxEM != NULL; auxEM = auxEM->seguinte){
- printf ("Enunciado: %s \n", auxEM->infoEM.enunciado);
- printf ("%s: \n", auxEM->infoEM.respostaCorreta);
- printf ("%s: \n", auxEM->infoEM.respostaIncorreta1);
- printf ("%s: \n", auxEM->infoEM.respostaIncorreta2);
- printf ("%s: \n", auxEM->infoEM.respostaIncorreta3);
- fflush(stdin);
- scanf ("%s", &opcao2Utilizador);
- if (strcmp(opcao2Utilizador, auxEM->infoEM.respostaCorreta) == 0){
- novaPontuacao = novaPontuacao + 15;
- }
- else{
- if (strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta1) == 0 ||
- strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta2) == 0 ||
- strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta3) == 0){
- novaPontuacao = novaPontuacao - 10;
- }
- else{
- printf ("Resposta INEXISTENTE! \n \a");
- return;
- }
- }
- }
- printf ("Perguntas do tipo <Verdadeiro ou Falso>");
- printf ("Escreva a resposta apenas com <Verdadeiro> ou <Falso>. \n");
- if (iniListaVF == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxVF = iniListaVF; auxVF != NULL; auxVF = auxVF->seguinte){
- printf ("Enunciado: %s \n", auxVF->infoVF.enunciado);
- printf ("%s: \n", auxVF->infoVF.respostaCorreta);
- printf ("%s: \n", auxVF->infoVF.respostaIncorreta);
- fflush(stdin);
- scanf ("%s", &opcao2Utilizador);
- if (strcmp(opcao2Utilizador, auxVF->infoVF.respostaCorreta) == 0){
- novaPontuacao = novaPontuacao + 30;
- }
- else{
- if (strcmp(opcao2Utilizador, auxVF->infoVF.respostaIncorreta) == 0){
- novaPontuacao = novaPontuacao - 30;
- }
- else{
- printf ("Resposta INEXISTENTE! \n \a");
- return;
- }
- }
- }
- printf ("Perguntas do tipo <Ordenacao>");
- printf ("Escreva a resposta apenas ordenando com os numeros. \n");
- if (iniListaO == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxO = iniListaO; auxO != NULL; auxO = auxO->seguinte){
- printf ("Enunciado: %s \n", auxO->infoO.enunciado);
- printf ("%s: \n", auxO->infoO.respostaCorreta);
- fflush(stdin);
- scanf ("%s", &opcao2Utilizador);
- if (strcmp(opcao2Utilizador, auxO->infoO.respostaCorreta) == 0){
- novaPontuacao = novaPontuacao + 50;
- }
- else{
- novaPontuacao = novaPontuacao - 20;
- }
- }
- printf ("Perguntas do tipo <T>");
- printf ("Escreva a resposta apenas com um pequeno texto que ache que esteja correto. \n");
- if (iniListaT == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxT = iniListaT; auxT != NULL; auxT = auxT->seguinte){
- printf ("Enunciado: %s \n", auxT->infoT.enunciado);
- printf ("%s: \n", auxT->infoT.respostaCorreta);
- fflush(stdin);
- scanf ("%s", &opcao2Utilizador);
- if (strcmp(opcao2Utilizador, auxT->infoT.respostaCorreta) == 0){
- novaPontuacao = novaPontuacao + 10;
- }
- else{
- novaPontuacao = 0;
- }
- }
- }
- return novaPontuacao;
- }
- int jogoXL (int novaPontuacao, ELEMENTO_EM *iniListaEM, ELEMENTO_VF *iniListaVF, ELEMENTO_O *iniListaO, ELEMENTO_T *iniListaT){
- char opcao2Utilizador[200];
- char opcao1Utilizador[10];
- ELEMENTO_EM *auxEM = NULL;
- ELEMENTO_VF *auxVF = NULL;
- ELEMENTO_O *auxO = NULL;
- ELEMENTO_T *auxT = NULL;
- printf ("***** JOGO DO TIPO XL ***** \n");
- printf ("************************** \n\n");
- printf ("O jogo do tipo <Extra Large> encontra-se indisponivel.\n");
- printf ("Pretende continuar e jogar com todas as perguntas existentes nos ficheiros armazenados? Sim/Nao \n");
- scanf ("%s", &opcao1Utilizador);
- if (strcmp (opcao1Utilizador, "NAO") == 0 ||
- strcmp (opcao1Utilizador, "nao") == 0 ||
- strcmp (opcao1Utilizador, "Nao") == 0 ||
- strcmp (opcao1Utilizador, "n") == 0 ){
- novaPontuacao = 0;
- }
- else {
- printf ("Perguntas do tipo <Escolha Multipla> \n");
- printf ("Escreva a resposta pretendida como esta presente no enunciado. \n");
- if (iniListaEM == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxEM = iniListaEM; auxEM != NULL; auxEM = auxEM->seguinte){
- printf ("Enunciado: %s \n", auxEM->infoEM.enunciado);
- printf ("%s: \n", auxEM->infoEM.respostaCorreta);
- printf ("%s: \n", auxEM->infoEM.respostaIncorreta1);
- printf ("%s: \n", auxEM->infoEM.respostaIncorreta2);
- printf ("%s: \n", auxEM->infoEM.respostaIncorreta3);
- fflush(stdin);
- scanf ("%s", &opcao2Utilizador);
- if (strcmp(opcao2Utilizador, auxEM->infoEM.respostaCorreta) == 0){
- novaPontuacao = novaPontuacao + 15;
- }
- else{
- if (strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta1) == 0 ||
- strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta2) == 0 ||
- strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta3) == 0){
- novaPontuacao = novaPontuacao - 10;
- }
- else{
- printf ("Resposta INEXISTENTE! \n \a");
- return;
- }
- }
- }
- printf ("Perguntas do tipo <Verdadeiro ou Falso>");
- printf ("Escreva a resposta apenas com <Verdadeiro> ou <Falso>. \n");
- if (iniListaVF == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxVF = iniListaVF; auxVF != NULL; auxVF = auxVF->seguinte){
- printf ("Enunciado: %s \n", auxVF->infoVF.enunciado);
- printf ("%s: \n", auxVF->infoVF.respostaCorreta);
- printf ("%s: \n", auxVF->infoVF.respostaIncorreta);
- fflush(stdin);
- scanf ("%s", &opcao2Utilizador);
- if (strcmp(opcao2Utilizador, auxVF->infoVF.respostaCorreta) == 0){
- novaPontuacao = novaPontuacao + 30;
- }
- else{
- if (strcmp(opcao2Utilizador, auxVF->infoVF.respostaIncorreta) == 0){
- novaPontuacao = novaPontuacao - 30;
- }
- else{
- printf ("Resposta INEXISTENTE! \n \a");
- return;
- }
- }
- }
- printf ("Perguntas do tipo <Ordenacao>");
- printf ("Escreva a resposta apenas ordenando com os numeros. \n");
- if (iniListaO == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxO = iniListaO; auxO != NULL; auxO = auxO->seguinte){
- printf ("Enunciado: %s \n", auxO->infoO.enunciado);
- printf ("%s: \n", auxO->infoO.respostaCorreta);
- fflush(stdin);
- scanf ("%s", &opcao2Utilizador);
- if (strcmp(opcao2Utilizador, auxO->infoO.respostaCorreta) == 0){
- novaPontuacao = novaPontuacao + 50;
- }
- else{
- novaPontuacao = novaPontuacao - 20;
- }
- }
- printf ("Perguntas do tipo <T>");
- printf ("Escreva a resposta apenas com um pequeno texto que ache que esteja correto. \n");
- if (iniListaT == NULL){
- printf ("Lista VAZIA! \n \a");
- return;
- }
- for (auxT = iniListaT; auxT != NULL; auxT = auxT->seguinte){
- printf ("Enunciado: %s \n", auxT->infoT.enunciado);
- printf ("%s: \n", auxT->infoT.respostaCorreta);
- fflush(stdin);
- scanf ("%s", &opcao2Utilizador);
- if (strcmp(opcao2Utilizador, auxT->infoT.respostaCorreta) == 0){
- novaPontuacao = novaPontuacao + 10;
- }
- else{
- novaPontuacao = 0;
- }
- }
- }
- return novaPontuacao;
- }
- void instrucoesJogador (){
- printf ("***** PAINEL DE INSTRUCOES ***** \n");
- printf ("******************************** \n");
- printf ("S - <Small> : 3 perguntas de cada grupo \n");
- printf ("M - <Medium> : 6 perguntas de cada grupo \n");
- printf ("L - <Large> : 12 perguntas de cada grupo \n");
- printf ("X - <Extra Large> : 24 perguntas de cada grupo \n\n");
- printf ("O jogo e constituido por 4 grupos de perguntas de cultura geral:\n");
- printf ("um grupo de escolha multipla, um grupo de verdadeiro ou falso,\n");
- printf ("um grupo de ordenacao e um grupo de quem perde sai. \n\n");
- printf ("- No 1o grupo, de escolha multipla, o jogador deve selecionar a \n");
- printf (" resposta correta entre as 4 opcoes de resposta possiveis. Cada \n");
- printf (" resposta correta acresce a pontuacao do jogador em 15 pontos. \n");
- printf (" Se errar, sao-lhe retirados 10 pontos ao total de pontos. \n\n");
- printf ("- No 2o grupo, verdadeiro ou falso, cada pergunta tem apenas duas \n");
- printf (" possiveis respostas: Verdadeiro ou Falso. Se o jogador acertar \n");
- printf (" soma 30 pontos a pontua��o global, sen�o sao-lhe retirados 30 pontos. \n\n");
- printf ("- No 3o grupo, ordenacao, o jogador devera ordenar as 3 opcoes \n");
- printf (" apresentadas. Se a ordenacao estiver correta sao-lhe somada \n");
- printf (" 50 pontos a pontuacao total, senao sao-lhe retirados 20 pontos. \n\n");
- printf ("- No 4o grupo, quem perde sai, as perguntas devem ser de resposta curta.\n");
- printf (" Se o jogador errar uma reposta sai do grupo com 0 pontos e n�o responde \n");
- printf (" a mais perguntas do grupo. Se acertar em todas as respostas, soma 10 \n");
- printf (" pontos por cada pergunta ao total de pontos. \n");
- }
- void alteraPontuacao (int novaPontuacao, JOGADOR jogador){
- int resultado = 0;
- char userName[100];
- JOGADOR jogadorTemp;
- FILE *registoJogadores;
- registoJogadores = fopen ("registoJogadores.dat", "r+b");
- if (registoJogadores == NULL){
- printf ("ERRO na abertura do ficheiro <registoJogadores.dat>. \n \a");
- return;
- }
- while (!feof(registoJogadores)){
- resultado = fread (&jogadorTemp, sizeof (JOGADOR), 1, registoJogadores);
- if (resultado){
- printf ("Username: %s \n", &jogadorTemp.userName);
- printf ("Pontuacao: %i \n", &jogadorTemp.pontuacao);
- }
- }
- printf ("Introduza o seu username novamente: \n");
- fflush (stdin);
- gets (jogador.userName);
- novaPontuacao = jogador.pontuacao;
- printf ("Nova Pontuacao do jogador <%s>: %i \n", jogador.userName, novaPontuacao);
- fwrite (&jogador, sizeof (JOGADOR), 1, registoJogadores);
- fclose (registoJogadores);
- }
- void gravarDataEHora (char novaData[], char novaHora[], JOGADOR jogador){
- int resultado = 0;
- FILE *registoJogadores;
- registoJogadores = fopen ("registoJogadores.dat", "ab");
- if (registoJogadores == NULL){
- printf ("ERRO na abertura do ficheiro binario <registoJogadores.dat>. \n \a");
- return;
- }
- printf ("Introduza o seu username novamente: \n");
- fflush (stdin);
- gets (jogador.userName);
- novaData = jogador.data;
- novaHora = jogador.hora;
- printf ("O jogador %s jogou a ultima vez no dia %s as %s. \n", jogador.userName, jogador.data, jogador.hora);
- fwrite (&jogador, sizeof (JOGADOR), 1, registoJogadores);
- fclose (registoJogadores);
- }
- void menuJogador (JOGADOR jogador){
- int opcao = 0;
- int novaPontuacao = 0;
- FILE *registoJogadores;
- char novaHora[20];
- char novaData[20];
- do {
- printf ("***** MENU DO JOGO ***** \n");
- printf ("************************ \n");
- printf ("NOTA: Nao se esqueca que antes de sair tem de introduzir as informacoes sobre a <data> e a <hora> da ultima vez que jogou. \n");
- printf ("Introduza o tipo de jogo que pretende iniciar: \n");
- printf ("1. Small \n");
- printf ("2. Medium \n");
- printf ("3. Large \n");
- printf ("4. Extra Large \n");
- printf ("5. Gravar data e hora \n");
- printf ("6. Listar Jogadores por Ordem Alfabetica \n");
- printf ("7. Listar Jogadores por Ordem Decrescente de Pontuacao \n");
- printf ("8. Top5 de Jogadores \n");
- printf ("9. Instrucoes e outras informacoes importantes \n");
- printf ("0. Sair \n");
- fflush (stdin);
- scanf ("%i", &opcao);
- switch (opcao){
- case 1 : jogoSmall (novaPontuacao, iniListaEM, iniListaVF, iniListaO, iniListaT);
- alteraPontuacao (novaPontuacao, jogador);
- printf ("Nova pontuacao do jogador: %i. \n", novaPontuacao);
- break;
- case 2 : jogoMedium (novaPontuacao, iniListaEM, iniListaVF, iniListaO, iniListaT);
- alteraPontuacao (novaPontuacao, jogador);
- printf ("Nova pontuacao do jogador: %i. \n", novaPontuacao);
- break;
- case 3 : jogoLarge (novaPontuacao, iniListaEM, iniListaVF, iniListaO, iniListaT);
- alteraPontuacao (novaPontuacao, jogador);
- printf ("Nova pontuacao do jogador: %i. \n", novaPontuacao);
- break;
- case 4 : jogoXL (novaPontuacao, iniListaEM, iniListaVF, iniListaO, iniListaT);
- alteraPontuacao (novaPontuacao, jogador);
- printf ("Nova pontuacao do jogador: %i. \n", novaPontuacao);
- break;
- case 5 : printf ("Introduza a ultima hora que jogou: \n");
- fflush(stdin);
- scanf ("%s", &novaHora);
- printf ("Introduza a ultima hora que jogou: \n");
- fflush(stdin);
- scanf ("%s", &novaData);
- gravarDataEHora (novaHora, novaData, jogador);
- break;
- case 6 :
- break;
- case 7 :
- break;
- case 8 :
- break;
- case 9 : instrucoesJogador ();
- break;
- }
- } while (opcao != 0);
- }
- int main(int argc, char *argv[]) {
- ADMINISTRADOR administrador;
- JOGADOR jogador;
- int opcao;
- int administradorExiste = 0;
- int jogadorExiste = 0;
- do {
- printf ("**************************** QUEM SABE, SABE! ******************************\n");
- printf ("****************************** MENU INICIAL ********************************\n");
- printf ("****************************************************************************\n");
- printf ("Introduza a opcao pretendida: \n");
- printf ("1. Entrar como Administrador \n");
- printf ("2. Entrar como Jogador \n");
- printf ("0. Sair \n");
- fflush(stdin);
- scanf ("%i", &opcao);
- switch (opcao){
- case 1 : administradorExiste = existeAdministrador (administrador);
- if (administradorExiste == 2){
- printf ("Aprovado como ADMINISTRADOR. \n");
- menuAdministrador (administrador, jogador);
- }
- if (administradorExiste == 1){
- printf ("Identificacao ERRADA. \n");
- continue; // permite reiniciar o ciclo
- }
- if (administradorExiste == 0){
- printf ("Reprovado como ADMINISTRADOR. \n");
- printf ("Tente entrar como JOGADOR. \n");
- }
- break;
- case 2 : jogadorExiste = existeJogador (jogador);
- if (jogadorExiste == 2){
- printf ("Aprovado como JOGADOR. \n");
- menuJogador (jogador);
- }
- if (jogadorExiste == 1){
- printf ("Identificacao ERRADA. \n");
- continue; // permite reiniciar o ciclo
- }
- if (jogadorExiste == 0) {
- printf ("Sera introduzido como novo JOGADOR. \n");
- criarJogador (jogador);
- }
- break;
- case 3 : criarAdministrador (administrador);
- break;
- }
- } while (opcao != 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement