Advertisement
Guest User

sougay mas seu c

a guest
May 4th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 56.32 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. typedef struct jogador{
  7.  
  8. char userName[50];
  9. char password[50];
  10. char nome[100];
  11. int idade;
  12. int pontuacao;
  13. char data[50];
  14. char hora[50];
  15.  
  16. } JOGADOR;
  17.  
  18. typedef struct administrador{
  19.  
  20. char userName[50];
  21. char password[50];
  22.  
  23. } ADMINISTRADOR;
  24.  
  25. typedef struct infoEM {
  26.  
  27. int numero;
  28. char enunciado[200];
  29. char respostaCorreta[200];
  30. char respostaIncorreta1[200];
  31. char respostaIncorreta2[200];
  32. char respostaIncorreta3[200];
  33.  
  34. } INFO_EM;
  35.  
  36. typedef struct infoVF {
  37.  
  38. int numero;
  39. char enunciado[200];
  40. char respostaCorreta[200];
  41. char respostaIncorreta[200];
  42.  
  43. } INFO_VF;
  44.  
  45. typedef struct infoO {
  46.  
  47. int numero;
  48. char enunciado[2000];
  49. char respostaCorreta[20];
  50.  
  51. } INFO_O;
  52.  
  53. typedef struct infoT {
  54.  
  55. int numero;
  56. char enunciado[2000];
  57. char respostaCorreta[500];
  58.  
  59. } INFO_T;
  60.  
  61. typedef struct elemEM {
  62.  
  63. INFO_EM infoEM;
  64. struct elemEM *seguinte;
  65. struct elemEM *anterior;
  66.  
  67. } ELEMENTO_EM;
  68.  
  69. typedef struct elemVF {
  70.  
  71. INFO_VF infoVF;
  72. struct elemVF *seguinte;
  73. struct elemVF *anterior;
  74.  
  75. } ELEMENTO_VF;
  76.  
  77. typedef struct elemO {
  78.  
  79. INFO_O infoO;
  80. struct elemO *seguinte;
  81. struct elemO *anterior;
  82.  
  83. } ELEMENTO_O;
  84.  
  85. typedef struct elemT {
  86.  
  87. INFO_T infoT;
  88. struct elemT *seguinte;
  89. struct elemT *anterior;
  90.  
  91. } ELEMENTO_T;
  92.  
  93. ELEMENTO_EM *iniListaEM = NULL;
  94. ELEMENTO_EM *fimListaEM = NULL;
  95. ELEMENTO_VF *iniListaVF = NULL;
  96. ELEMENTO_VF *fimListaVF = NULL;
  97. ELEMENTO_O *iniListaO = NULL;
  98. ELEMENTO_O *fimListaO = NULL;
  99. ELEMENTO_T *iniListaT = NULL;
  100. ELEMENTO_T *fimListaT = NULL;
  101.  
  102. void criarAdministrador (ADMINISTRADOR administrador){
  103.  
  104. FILE *registoAdministradores;
  105. registoAdministradores = fopen ("registoAdministradores.dat", "ab");
  106.  
  107. if (registoAdministradores == NULL){
  108. printf ("ERRO na abertura do ficheiro <registoAdministradores.dat>. \n \a");
  109. return;
  110. }
  111.  
  112. printf ("***** CRIACAO DE ADMINISTRADOR ***** \n");
  113. printf ("************************************ \n");
  114.  
  115. printf ("Introduza o username que pretende criar: \n");
  116. fflush(stdin);
  117. scanf ("%s", &administrador.userName);
  118.  
  119. printf ("Introduza a password do novo username: \n ");
  120. fflush(stdin);
  121. scanf ("%s", &administrador.password);
  122.  
  123. fwrite (&administrador, sizeof (ADMINISTRADOR), 1, registoAdministradores);
  124.  
  125. fclose (registoAdministradores);
  126. }
  127.  
  128. void criarJogador (JOGADOR jogador){
  129.  
  130. FILE *registoJogadores;
  131. registoJogadores = fopen ("registoJogadores.dat", "ab");
  132.  
  133. if (registoJogadores == NULL){
  134. printf ("ERRO na abertura do ficheiro <registoJogadores.dat>. \n \a");
  135. return;
  136. }
  137.  
  138. printf ("***** CRIACAO DE JOGADOR ***** \n");
  139. printf ("****************************** \n");
  140.  
  141. printf ("Introduza o username que pretende criar: \n");
  142. fflush(stdin);
  143. scanf ("%s", &jogador.userName);
  144.  
  145. printf ("Introduza a password do novo username: \n ");
  146. fflush(stdin);
  147. scanf ("%s", &jogador.password);
  148.  
  149. printf ("Introduza o seu nome: \n");
  150. fflush(stdin);
  151. scanf ("%s", &jogador.nome);
  152.  
  153. printf ("Introduza a sua idade: \n");
  154. fflush(stdin);
  155. scanf ("%i", &jogador.idade);
  156.  
  157. fwrite (&jogador, sizeof (JOGADOR), 1, registoJogadores);
  158.  
  159. fclose (registoJogadores);
  160. }
  161.  
  162. void listarAdministradores (ADMINISTRADOR administrador){
  163.  
  164. FILE *registoAdministradores;
  165. ADMINISTRADOR administradorTemp;
  166. int resultado = 0;
  167.  
  168. registoAdministradores = fopen ("registoAdministradores.dat", "rb");
  169.  
  170. if (registoAdministradores == NULL){
  171. printf ("ERRO na abertura do ficheiro binario <registoAdministradores.dat>. \n");
  172. return;
  173. }
  174.  
  175. printf ("***** LISTAGEM DE ADMINISTRADORES ***** \n");
  176. printf ("*************************************** \n");
  177.  
  178. while (!feof(registoAdministradores)){
  179. resultado = fread (&administradorTemp, sizeof (ADMINISTRADOR), 1, registoAdministradores);
  180. if (resultado){
  181. printf ("Username: %s\nPassword: %s\n\n",
  182. administradorTemp.userName, administradorTemp.password);
  183. }
  184. }
  185.  
  186. fclose (registoAdministradores);
  187. }
  188.  
  189. int listarJogadores (JOGADOR jogador){
  190.  
  191. JOGADOR jogadorTemp;
  192. char *resultado = 0;
  193. FILE *registoJogadores;
  194. int i=0;
  195.  
  196. registoJogadores = fopen ("registoJogadores.dat", "rb");
  197.  
  198. if (registoJogadores == NULL){
  199. printf ("ERRO na abertura do ficheiro binario <registoJogadores.dat>. \n");
  200. return -1;
  201. }
  202.  
  203. printf ("***** LISTAGEM DE JOGADORES ***** \n");
  204. printf ("********************************* \n");
  205. i=1;
  206. while (!feof(registoJogadores)){
  207. resultado = fread (&jogadorTemp, sizeof (JOGADOR), 1, registoJogadores);
  208. if (resultado){
  209. printf ("Username: %s\nPassword: %s\nNome: %s\nIdade: %i \n\n",
  210. jogadorTemp.userName, jogadorTemp.password, jogadorTemp.nome, jogadorTemp.idade);
  211. i++;
  212. }
  213. }
  214.  
  215. fclose (registoJogadores);
  216.  
  217. return 0;
  218. }
  219.  
  220. // retorna 0 se o utilizador nao existir, 1 se a identificacao estiver errada e 2 se existir
  221.  
  222. int existeAdministrador (ADMINISTRADOR administrador){
  223.  
  224. int resultado = 0;
  225. ADMINISTRADOR administradorTemp;
  226. FILE *registoAdministradores;
  227.  
  228. registoAdministradores = fopen ("registoAdministradores.dat", "rb");
  229.  
  230. if (registoAdministradores == NULL){
  231. printf ("ERRO na abertura do ficheiro binario <registoAdministradores.dat>. \n");
  232. return 0;
  233. }
  234.  
  235. printf ("***** LOGIN COMO ADMINISTRADOR ***** \n");
  236. printf ("************************************ \n");
  237.  
  238. printf ("Introduza o seu username: (NOTA - Maximo de 50 carateres) \n");
  239. fflush(stdin);
  240. scanf ("%s", &administrador.userName);
  241.  
  242. printf ("Introduza a sua password: (NOTA - Maximo de 50 carateres) \n");
  243. fflush(stdin);
  244. scanf ("%s", &administrador.password);
  245.  
  246. while (!feof(registoAdministradores)){
  247. resultado = fread (&administradorTemp, sizeof (ADMINISTRADOR), 1, registoAdministradores);
  248. if (strcmp(administrador.userName, administradorTemp.userName) == 0 && strcmp(administrador.password, administradorTemp.password) == 0){
  249. return 2;
  250. }
  251. if (strcmp(administrador.userName, administradorTemp.userName) == 0 && strcmp(administrador.password, administradorTemp.password) != 0){
  252. return 1;
  253. }
  254. }
  255.  
  256. fclose (registoAdministradores);
  257.  
  258. return 0;
  259. }
  260.  
  261. // retorna 0 se o utilizador nao existir, 1 se a identificacao estiver errada e 2 se existir
  262.  
  263. int existeJogador (JOGADOR jogador){
  264.  
  265. int resultado = 0;
  266. JOGADOR jogadorTemp;
  267. FILE *registoJogadores;
  268.  
  269. registoJogadores = fopen ("registoJogadores.dat", "rb");
  270.  
  271. if (registoJogadores == NULL){
  272. printf ("ERRO na abertura do ficheiro <registoJogadores.dat>. \n \a");
  273. return 0;
  274. }
  275.  
  276. printf ("***** LOGIN COMO JOGADOR ***** \n");
  277. printf ("****************************** \n");
  278.  
  279. printf ("Introduza o seu username: \n");
  280. fflush(stdin);
  281. scanf ("%s", &jogador.userName);
  282.  
  283. printf ("Introduza a sua password: (NOTA - Maximo de 50 carateres) \n");
  284. fflush(stdin);
  285. scanf ("%s", &jogador.password);
  286.  
  287. while (!feof(registoJogadores)){
  288. resultado = fread (&jogadorTemp, sizeof (JOGADOR), 1, registoJogadores);
  289. if (strcmp(jogador.userName, jogadorTemp.userName) == 0 && strcmp(jogador.password, jogadorTemp.password) == 0){
  290. return 2;
  291. }
  292. if (strcmp(jogador.userName, jogadorTemp.userName) == 0 && strcmp(jogador.password, jogadorTemp.password) != 0){
  293. return 1;
  294. }
  295. }
  296.  
  297. fclose (registoJogadores);
  298.  
  299. return 0;
  300. }
  301.  
  302. void acrescentarFimListaEM (ELEMENTO_EM **iniListaEM, ELEMENTO_EM **fimListaEM, INFO_EM newInfoEM){
  303.  
  304. ELEMENTO_EM *novoEM = NULL;
  305.  
  306. novoEM = (ELEMENTO_EM *) malloc (1 * sizeof (ELEMENTO_EM));
  307.  
  308. if (novoEM == NULL){
  309. printf ("ERRO ao reservar memoria. \n \a");
  310. return;
  311. }
  312.  
  313. novoEM->infoEM = newInfoEM;
  314. novoEM->seguinte = NULL;
  315. novoEM->anterior = NULL;
  316.  
  317. if (*fimListaEM == NULL){
  318. *iniListaEM = novoEM;
  319. *fimListaEM = novoEM;
  320. }
  321. else{
  322. novoEM->anterior = (*fimListaEM);
  323. (*fimListaEM)->seguinte = novoEM;
  324. (*fimListaEM) = novoEM;
  325. }
  326.  
  327. free (novoEM);
  328. }
  329.  
  330. void acrescentarFimListaVF (ELEMENTO_VF **iniListaVF, ELEMENTO_VF **fimListaVF, INFO_VF newInfoVF){
  331.  
  332. ELEMENTO_VF *novoVF = NULL;
  333.  
  334. novoVF = (ELEMENTO_VF *) malloc (1 * sizeof (ELEMENTO_VF));
  335.  
  336. if (novoVF == NULL){
  337. printf ("ERRO ao reservar memoria. \n \a");
  338. return;
  339. }
  340.  
  341. novoVF->infoVF = newInfoVF;
  342. novoVF->seguinte = NULL;
  343. novoVF->anterior = NULL;
  344.  
  345. if (*fimListaVF == NULL){
  346. *iniListaVF = novoVF;
  347. *fimListaVF = novoVF;
  348. }
  349. else{
  350. novoVF->anterior = (*fimListaVF);
  351. (*fimListaVF)->seguinte = novoVF;
  352. (*fimListaVF) = novoVF;
  353. }
  354.  
  355. free (novoVF);
  356. }
  357.  
  358. void acrescentarFimListaO (ELEMENTO_O **iniListaO, ELEMENTO_O **fimListaO, INFO_O newInfoO){
  359.  
  360. ELEMENTO_O *novoO = NULL;
  361.  
  362. novoO = (ELEMENTO_O *) malloc (1 * sizeof (ELEMENTO_O));
  363.  
  364. if (novoO == NULL){
  365. printf ("ERRO ao reservar memoria. \n \a");
  366. return;
  367. }
  368.  
  369. novoO->infoO = newInfoO;
  370. novoO->seguinte = NULL;
  371. novoO->anterior = NULL;
  372.  
  373. if (*fimListaO == NULL){
  374. *iniListaO = novoO;
  375. *fimListaO = novoO;
  376. }
  377. else{
  378. novoO->anterior = (*fimListaO);
  379. (*fimListaO)->seguinte = novoO;
  380. (*fimListaO) = novoO;
  381. }
  382.  
  383. free (novoO);
  384. }
  385.  
  386. void acrescentarFimListaT (ELEMENTO_T **iniListaT, ELEMENTO_T **fimListaT, INFO_T newInfoT){
  387.  
  388. ELEMENTO_T *novoT = NULL;
  389.  
  390. novoT = (ELEMENTO_T *) malloc (1 * sizeof (ELEMENTO_T));
  391.  
  392. if (novoT == NULL){
  393. printf ("ERRO ao reservar memoria. \n \a");
  394. return;
  395. }
  396.  
  397. novoT->infoT = newInfoT;
  398. novoT->seguinte = NULL;
  399. novoT->anterior = NULL;
  400.  
  401. if (*fimListaT == NULL){
  402. *iniListaT = novoT;
  403. *fimListaT = novoT;
  404. }
  405. else{
  406. novoT->anterior = (*fimListaT);
  407. (*fimListaT)->seguinte = novoT;
  408. (*fimListaT) = novoT;
  409. }
  410.  
  411. free (novoT);
  412. }
  413.  
  414. void listarCrescentePerguntasEM (ELEMENTO_EM *iniListaEM){
  415.  
  416. ELEMENTO_EM *auxEM = NULL;
  417.  
  418. if (iniListaEM == NULL){
  419. printf ("Lista VAZIA! \n \a");
  420. return;
  421. }
  422.  
  423. for (auxEM = iniListaEM; auxEM != NULL; auxEM = auxEM->seguinte){
  424. printf ("Enunciado: %s \n", auxEM->infoEM.enunciado);
  425. printf ("Resposta Correta: %s \n", auxEM->infoEM.respostaCorreta);
  426. printf ("Resposta Incorreta 1: %s \n", auxEM->infoEM.respostaIncorreta1);
  427. printf ("Resposta Incorreta 2: %s \n", auxEM->infoEM.respostaIncorreta2);
  428. printf ("Resposta Incorreta 3: %s \n", auxEM->infoEM.respostaIncorreta3);
  429. }
  430. }
  431.  
  432. void listarCrescentePerguntasVF (ELEMENTO_VF *iniListaVF){
  433.  
  434. ELEMENTO_VF *auxVF = NULL;
  435.  
  436. if (iniListaVF == NULL){
  437. printf ("Lista VAZIA! \n \a");
  438. return;
  439. }
  440.  
  441. for (auxVF = iniListaVF; auxVF != NULL; auxVF = auxVF->seguinte){
  442. printf ("Enunciado: %s \n", auxVF->infoVF.numero, auxVF->infoVF.enunciado);
  443. printf ("Resposta Correta: %s \n", auxVF->infoVF.respostaCorreta);
  444. printf ("Resposta Incorreta: %s \n", auxVF->infoVF.respostaIncorreta);
  445. }
  446. }
  447.  
  448. void listarCrescentePerguntasO (ELEMENTO_O *iniListaO){
  449.  
  450. ELEMENTO_O *auxO = NULL;
  451.  
  452. if (iniListaO == NULL){
  453. printf ("Lista VAZIA! \n \a");
  454. return;
  455. }
  456.  
  457. for (auxO = iniListaO; auxO != NULL; auxO = auxO->seguinte){
  458. printf ("Enunciado: %s \n", auxO->infoO.enunciado);
  459. printf ("Resposta Correta: %s \n", auxO->infoO.respostaCorreta);
  460. }
  461. }
  462.  
  463. void listarCrescentePerguntasT (ELEMENTO_T *iniListaT){
  464.  
  465. ELEMENTO_T *auxT = NULL;
  466.  
  467. if (iniListaT == NULL){
  468. printf ("Lista VAZIA! \n \a");
  469. return;
  470. }
  471.  
  472. for (auxT = iniListaT; auxT != NULL; auxT = auxT->seguinte){
  473. printf ("Enunciado: %s \n", auxT->infoT.enunciado);
  474. printf ("Resposta Correta: %s \n", auxT->infoT.respostaCorreta);
  475. }
  476. }
  477.  
  478. void lerFicheiroBinarioPerguntasEM (FILE *registoDePerguntasEM){
  479.  
  480. int resultadoEM = 0;
  481. INFO_EM infoEMTemp;
  482.  
  483. registoDePerguntasEM = fopen ("registoDePerguntasEM.dat", "rb");
  484.  
  485. if (registoDePerguntasEM == NULL){
  486. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasEM.dat>. \n \a");
  487. return;
  488. }
  489.  
  490. while (!feof(registoDePerguntasEM)){
  491. resultadoEM = fread (&infoEMTemp, sizeof (INFO_EM), 1, registoDePerguntasEM);
  492. if (resultadoEM){
  493. printf ("Numero da pergunta: %i. \n", infoEMTemp.numero);
  494. printf ("Enunciado: %s \n", infoEMTemp.enunciado);
  495. printf ("Resposta Correta: %s \n", infoEMTemp.respostaCorreta);
  496. printf ("Resposta Incorreta 1: %s \n", infoEMTemp.respostaIncorreta1);
  497. printf ("Resposta Incorreta 2: %s \n", infoEMTemp.respostaIncorreta2);
  498. printf ("Resposta Incorreta 3: %s \n", infoEMTemp.respostaIncorreta3);
  499. }
  500. }
  501.  
  502. fclose (registoDePerguntasEM);
  503. }
  504.  
  505. void lerFicheiroBinarioPerguntasVF (FILE *registoDePerguntasVF){
  506.  
  507. int resultadoVF = 0;
  508. INFO_VF infoVFTemp;
  509.  
  510. registoDePerguntasVF = fopen ("registoDePerguntasVF.dat", "rb");
  511.  
  512. if (registoDePerguntasVF == NULL){
  513. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasVF.dat>. \n \a");
  514. return;
  515. }
  516.  
  517. while (!feof(registoDePerguntasVF)){
  518. resultadoVF = fread (&infoVFTemp, sizeof (INFO_VF), 1, registoDePerguntasVF);
  519. if (resultadoVF){
  520. printf ("Numero da pergunta: %i. \n", infoVFTemp.numero);
  521. printf ("Enunciado: %s \n", infoVFTemp.enunciado);
  522. printf ("Resposta Correta: %s \n", infoVFTemp.respostaCorreta);
  523. printf ("Resposta Incorreta: %s \n", infoVFTemp.respostaIncorreta);
  524. }
  525. }
  526.  
  527. fclose (registoDePerguntasVF);
  528. }
  529.  
  530. void lerFicheiroBinarioPerguntasO (FILE *registoDePerguntasO){
  531.  
  532. int resultadoO = 0;
  533. INFO_O infoOTemp;
  534.  
  535. registoDePerguntasO = fopen ("registoDePerguntasO.dat", "rb");
  536.  
  537. if (registoDePerguntasO == NULL){
  538. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasO.dat>. \n \a");
  539. return;
  540. }
  541.  
  542. while (!feof(registoDePerguntasO)){
  543. resultadoO = fread (&infoOTemp, sizeof (INFO_O), 1, registoDePerguntasO);
  544. if (resultadoO){
  545. printf ("Numero da pergunta: %i. \n", infoOTemp.numero);
  546. printf ("Enunciado: %s \n", infoOTemp.enunciado);
  547. printf ("Resposta Correta: %s \n", infoOTemp.respostaCorreta);
  548. }
  549. }
  550.  
  551. fclose (registoDePerguntasO);
  552. }
  553.  
  554. void lerFicheiroBinarioPerguntasT (FILE *registoDePerguntasT){
  555.  
  556. int resultadoT = 0;
  557. INFO_T infoTTemp;
  558.  
  559. registoDePerguntasT = fopen ("registoDePerguntasT.dat", "rb");
  560.  
  561. if (registoDePerguntasT == NULL){
  562. printf ("ERRO na abertura do ficheiro binario <registoDePerguntasT.dat>. \n \a");
  563. return;
  564. }
  565.  
  566. while (!feof(registoDePerguntasT)){
  567. resultadoT = fread (&infoTTemp, sizeof (INFO_T), 1, registoDePerguntasT);
  568. if (resultadoT){
  569. printf ("Numero da pergunta: %i. \n", infoTTemp.numero);
  570. printf ("Enunciado: %s \n", infoTTemp.enunciado);
  571. printf ("Resposta Correta: %s \n", infoTTemp.respostaCorreta);
  572. }
  573. }
  574.  
  575. fclose (registoDePerguntasT);
  576. }
  577.  
  578. void acrescentarPerguntas (int *numTotalEM, int *numTotalVF, int *numTotalO, int *numTotalT){
  579.  
  580. INFO_EM newInfoEM;
  581. INFO_VF newInfoVF;
  582. INFO_O newInfoO;
  583. INFO_T newInfoT;
  584. FILE *registoDePerguntasEM;
  585. FILE *registoDePerguntasVF;
  586. FILE *registoDePerguntasO;
  587. FILE *registoDePerguntasT;
  588. int opcao;
  589.  
  590. printf ("***** ACRESCIMO DE PERGUNTAS ***** \n");
  591. printf ("********************************** \n\n");
  592.  
  593. do{
  594. printf ("Que tipo de pergunta pretende acrescentar? \n");
  595. printf ("1. Escolha Multipla \n");
  596. printf ("2. Verdadeiro ou Falso \n");
  597. printf ("3. Ordenacao \n");
  598. printf ("4. Texto \n");
  599. printf ("0. Sair \n");
  600. fflush (stdin);
  601. scanf ("%i", &opcao);
  602.  
  603. switch (opcao){
  604. case 1 : *numTotalEM = *numTotalEM + 1;
  605. printf ("Esta pergunta sera o numero %i do tipo <Escolha Multipla>. \n", *numTotalEM);
  606. printf ("Introduza o enunciado da pergunta: \n" );
  607. fflush (stdin);
  608. gets (newInfoEM.enunciado);
  609. printf ("Introduza a resposta correta: \n");
  610. fflush (stdin);
  611. gets (newInfoEM.respostaCorreta);
  612. printf ("Introduza a primeira resposta incorreta: \n");
  613. fflush (stdin);
  614. gets (newInfoEM.respostaIncorreta1);
  615. printf ("Introduza a segunda resposta incorreta: \n");
  616. fflush (stdin);
  617. gets (newInfoEM.respostaIncorreta2);
  618. printf ("Introduza a terceira resposta incorreta: \n");
  619. fflush (stdin);
  620. gets (newInfoEM.respostaIncorreta3);
  621. acrescentarFimListaEM (&iniListaEM, &fimListaEM, newInfoEM);
  622. break;
  623. case 2 : *numTotalVF = *numTotalVF + 1;
  624. printf ("Esta pergunta sera o numero %i do tipo <Verdadeiro ou Falso>. \n", *numTotalVF);
  625. printf ("Introduza o enunciado da pergunta: \n" );
  626. fflush (stdin);
  627. gets (newInfoVF.enunciado);
  628. printf ("Introduza a resposta correta: \n");
  629. fflush (stdin);
  630. gets (newInfoVF.respostaCorreta);
  631. printf ("Introduza a primeira resposta incorreta: \n");
  632. fflush (stdin);
  633. gets (newInfoVF.respostaIncorreta);
  634. acrescentarFimListaVF (&iniListaVF, &fimListaVF, newInfoVF);
  635. break;
  636. case 3 : *numTotalO = *numTotalO + 1;
  637. printf ("Esta pergunta sera o numero %i do tipo <Ordenacao>. \n", *numTotalO);
  638. printf ("Introduza o enunciado da pergunta: \n" );
  639. fflush (stdin);
  640. gets (newInfoO.enunciado);
  641. printf ("Introduza a resposta correta: \n");
  642. fflush (stdin);
  643. gets (newInfoO.respostaCorreta);
  644. acrescentarFimListaO (&iniListaO, &fimListaO, newInfoO);
  645. break;
  646. case 4 : *numTotalT = *numTotalT + 1;
  647. printf ("Esta pergunta sera o numero %i do tipo <Texto>. \n", *numTotalT);
  648. printf ("Introduza o enunciado da pergunta: \n" );
  649. fflush (stdin);
  650. gets (newInfoO.enunciado);
  651. printf ("Introduza a resposta correta:\n");
  652. fflush (stdin);
  653. gets (newInfoO.respostaCorreta);
  654. acrescentarFimListaT (&iniListaT, &fimListaT, newInfoT);
  655. break;
  656. }
  657.  
  658. } while (opcao != 0);
  659. }
  660.  
  661. void alterarPerguntaEM_Enunciado (char enunciadoEM []){
  662.  
  663. ELEMENTO_EM *auxEM = NULL;
  664.  
  665. if (iniListaEM == NULL){
  666. printf ("Lista VAZIA ! \n");
  667. return;
  668. }
  669.  
  670. strcpy (auxEM->infoEM.enunciado, enunciadoEM);
  671. }
  672.  
  673. void alterarPerguntaEM_RC (char respostaCorretaEM []){
  674.  
  675. ELEMENTO_EM *auxEM = NULL;
  676.  
  677. if (iniListaEM == NULL){
  678. printf ("Lista VAZIA ! \n");
  679. return;
  680. }
  681.  
  682. strcpy (auxEM->infoEM.respostaCorreta, respostaCorretaEM);
  683. }
  684.  
  685. void alterarPerguntaEM_RI1 (char respostaIncorreta1EM []){
  686.  
  687. ELEMENTO_EM *auxEM = NULL;
  688.  
  689. if (iniListaEM == NULL){
  690. printf ("Lista VAZIA ! \n");
  691. return;
  692. }
  693.  
  694. strcpy (auxEM->infoEM.respostaIncorreta1, respostaIncorreta1EM);
  695. }
  696.  
  697. void alterarPerguntaEM_RI2 (char respostaIncorreta2EM []){
  698.  
  699. ELEMENTO_EM *auxEM = NULL;
  700.  
  701. if (iniListaEM == NULL){
  702. printf ("Lista VAZIA ! \n");
  703. return;
  704. }
  705.  
  706. strcpy (auxEM->infoEM.respostaIncorreta2, respostaIncorreta2EM);
  707. }
  708.  
  709. void alterarPerguntaEM_RI3 ( char respostaIncorreta3EM []){
  710.  
  711. ELEMENTO_EM *auxEM = NULL;
  712.  
  713. if (iniListaEM == NULL){
  714. printf ("Lista VAZIA ! \n");
  715. return;
  716. }
  717.  
  718. strcpy (auxEM->infoEM.respostaIncorreta3, respostaIncorreta3EM);
  719. }
  720.  
  721. void alterarPerguntaVF_Enunciado (char enunciadoVF []){
  722.  
  723. ELEMENTO_VF *auxVF = NULL;
  724.  
  725. if (iniListaVF == NULL){
  726. printf ("Lista VAZIA ! \n");
  727. return;
  728. }
  729.  
  730. strcpy (auxVF->infoVF.enunciado, enunciadoVF);
  731. }
  732.  
  733. void alterarPerguntaVF_RC (char respostaCorretaVF []){
  734.  
  735. ELEMENTO_VF *auxVF = NULL;
  736.  
  737. if (iniListaVF == NULL){
  738. printf ("Lista VAZIA ! \n");
  739. return;
  740. }
  741.  
  742. strcpy (auxVF->infoVF.respostaCorreta, respostaCorretaVF);
  743. }
  744.  
  745. void alterarPerguntaVF_RI (char respostaIncorretaVF []){
  746.  
  747. ELEMENTO_VF *auxVF = NULL;
  748.  
  749. if (iniListaVF == NULL){
  750. printf ("Lista VAZIA ! \n");
  751. return;
  752. }
  753.  
  754. strcpy (auxVF->infoVF.respostaIncorreta, respostaIncorretaVF);
  755. }
  756.  
  757. void alterarPerguntaO_Enunciado (char enunciadoO []){
  758.  
  759. ELEMENTO_O *auxO = NULL;
  760.  
  761. if (iniListaO == NULL){
  762. printf ("Lista VAZIA ! \n");
  763. return;
  764. }
  765.  
  766. strcpy (auxO->infoO.enunciado, enunciadoO);
  767. }
  768.  
  769. void alterarPerguntaO_RC (char respostaCorretaO []){
  770.  
  771. ELEMENTO_O *auxO = NULL;
  772.  
  773. if (iniListaO == NULL){
  774. printf ("Lista VAZIA ! \n");
  775. return;
  776. }
  777.  
  778. strcpy (auxO->infoO.respostaCorreta, respostaCorretaO);
  779. }
  780.  
  781. void alterarPerguntaT_Enunciado (char enunciadoT []){
  782.  
  783. ELEMENTO_T *auxT = NULL;
  784.  
  785. if (iniListaT == NULL){
  786. printf ("Lista VAZIA ! \n");
  787. return;
  788. }
  789.  
  790. strcpy (auxT->infoT.enunciado, enunciadoT);
  791. }
  792.  
  793. void alterarPerguntaT_RC (char respostaCorretaT []){
  794.  
  795. ELEMENTO_T *auxT = NULL;
  796.  
  797. if (iniListaT == NULL){
  798. printf ("Lista VAZIA ! \n");
  799. return;
  800. }
  801.  
  802. strcpy (auxT->infoT.respostaCorreta, respostaCorretaT);
  803. }
  804.  
  805. void alterarPerguntas (){
  806.  
  807. int opcao = 0;
  808. int opcaoEM = 0;
  809. int opcaoVF = 0;
  810. int opcaoO = 0;
  811. int opcaoT = 0;
  812. char enunciadoEM[200];
  813. char respostaCorretaEM[200];
  814. char respostaIncorreta1EM[200];
  815. char respostaIncorreta2EM[200];
  816. char respostaIncorreta3EM[200];
  817. char enunciadoVF[200];
  818. char respostaCorretaVF[200];
  819. char respostaIncorretaVF[200];
  820. char enunciadoO[200];
  821. char respostaCorretaO[20];
  822. char enunciadoT[200];
  823. char respostaCorretaT[200];
  824. int resultadoEM = 0;
  825. int resultadoVF = 0;
  826. int resultadoO = 0;
  827. int resultadoT = 0;
  828. INFO_EM infoEMTemp;
  829. INFO_VF infoVFTemp;
  830. INFO_O infoOTemp;
  831. INFO_T infoTTemp;
  832. FILE *registoDePerguntasEM;
  833. FILE *registoDePerguntasVF;
  834. FILE *registoDePerguntasO;
  835. FILE *registoDePerguntasT;
  836.  
  837. printf ("***** ALTERACAO DE PERGUNTAS ***** \n");
  838. printf ("********************************** \n\n");
  839.  
  840. do {
  841. printf ("Que tipo de pergunta pretende alterar: \n");
  842. printf ("1. Escolha Multipla \n");
  843. printf ("2. Verdadeiro ou Falso \n");
  844. printf ("3. Ordenacao \n");
  845. printf ("4. Texto \n");
  846. printf ("0. Sair \n");
  847. fflush (stdin);
  848. scanf ("%i", &opcao);
  849.  
  850. switch (opcao) {
  851. case 1 : printf ("Ira alterar uma pergunta do tipo <Escolha Multipla>. \n");
  852. listarCrescentePerguntasEM (iniListaEM);
  853. do{
  854. printf ("Qual a prte da perugn de <Escolha Multipla> que pretende alterar? \n");
  855. printf ("1. Enunciado \n");
  856. printf ("2. Resposta Correta \n");
  857. printf ("3. Resposta Incorreta 1 \n");
  858. printf ("4. Resposta Incorreta 2 \n");
  859. printf ("5. Resposta Incorreta 3 \n");
  860. printf ("0. Sair \n");
  861. fflush (stdin);
  862. scanf ("%i", &opcaoEM);
  863.  
  864. switch (opcaoEM){
  865. case 1 : printf ("Introduza o novo Enunciado: \n");
  866. fflush (stdin);
  867. gets (enunciadoEM);
  868. alterarPerguntaEM_Enunciado (enunciadoEM);
  869. break;
  870. case 2 : printf ("Introduza a nova Resposta Correta: \n");
  871. fflush (stdin);
  872. gets (respostaCorretaEM);
  873. alterarPerguntaEM_RC (respostaCorretaEM);
  874. break;
  875. case 3 : printf ("Introduza a nova Resposta Incorreta 1: \n");
  876. fflush (stdin);
  877. gets (respostaIncorreta1EM);
  878. alterarPerguntaEM_RI1 (respostaIncorreta1EM);
  879. break;
  880. case 4 : printf ("Introduza a nova Resposta Incorreta 2: \n");
  881. fflush (stdin);
  882. gets (respostaIncorreta2EM);
  883. alterarPerguntaEM_RI2 (respostaIncorreta2EM);
  884. break;
  885. case 5 : printf ("Introduza a nova Resposta Incorreta 3: \n");
  886. fflush (stdin);
  887. gets (respostaIncorreta3EM);
  888. alterarPerguntaEM_RI3 (respostaIncorreta3EM);
  889. break;
  890. }
  891. } while (opcaoEM != 0);
  892. break;
  893. case 2 : printf ("Ira alterar uma pergunta do tipo <Verdadeiro ou Falso>. \n");
  894. listarCrescentePerguntasVF (iniListaVF);
  895. do{
  896. printf ("Qual o numero da pergunta de <Verdadeiro ou Falso> que pretende alterar? \n");
  897. printf ("1. Enunciado \n");
  898. printf ("2. Resposta Correta \n");
  899. printf ("3. Resposta Incorreta \n");
  900. printf ("0. Sair \n");
  901. fflush (stdin);
  902. scanf ("%i", &opcaoVF);
  903.  
  904. switch (opcaoVF){
  905. case 1 : printf ("Introduza o novo Enunciado: \n");
  906. fflush (stdin);
  907. gets (enunciadoVF);
  908. alterarPerguntaVF_Enunciado (enunciadoVF);
  909. break;
  910. case 2 : printf ("Introduza a nova Resposta Correta: \n");
  911. fflush (stdin);
  912. gets (respostaCorretaVF);
  913. alterarPerguntaVF_RC (respostaCorretaVF);
  914. break;
  915. case 3 : printf ("Introduza a nova Resposta Incorreta: \n");
  916. fflush (stdin);
  917. gets (respostaIncorretaVF);
  918. alterarPerguntaVF_RI (respostaIncorretaVF);
  919. break;
  920. }
  921. } while (opcaoVF != 0);
  922. break;
  923. case 3 : printf ("Ira alterar uma pergunta do tipo <Ordenacao>. \n");
  924. listarCrescentePerguntasO (iniListaO);
  925. do{
  926. printf ("Qual o numero da pergunta de <Ordenar> que pretende alterar? \n");
  927. printf ("1. Enunciado \n");
  928. printf ("2. Resposta Correta \n");
  929. printf ("0. Sair \n");
  930. fflush (stdin);
  931. scanf ("%i", &opcaoO);
  932.  
  933. switch (opcaoO){
  934. case 1 : printf ("Introduza o novo Enunciado: \n");
  935. fflush (stdin);
  936. gets (enunciadoO);
  937. alterarPerguntaO_Enunciado (enunciadoO);
  938. break;
  939. case 2 : printf ("Introduza a nova Resposta Correta: \n");
  940. fflush (stdin);
  941. gets (respostaCorretaO);
  942. alterarPerguntaO_RC (respostaCorretaO);
  943. break;
  944. }
  945. } while (opcaoO != 0);
  946. break;
  947. case 4 : printf ("Ira remover uma pergunta do tipo <Texto>. \n");
  948. listarCrescentePerguntasT (iniListaT);
  949. do{
  950. printf ("Qual o numero da pergunta de <Ordenar> que pretende alterar? \n");
  951. printf ("1. Enunciado \n");
  952. printf ("2. Resposta Correta \n");
  953. printf ("0. Sair \n");
  954. fflush (stdin);
  955. scanf ("%i", &opcaoT);
  956.  
  957. switch (opcaoVF){
  958. case 1 : printf ("Introduza o novo Enunciado: \n");
  959. fflush (stdin);
  960. gets (enunciadoT);
  961. alterarPerguntaT_Enunciado (enunciadoT);
  962. break;
  963. case 2 : printf ("Introduza a nova Resposta Correta: \n");
  964. fflush (stdin);
  965. gets (respostaCorretaT);
  966. alterarPerguntaT_RC (respostaCorretaT);
  967. break;
  968. }
  969. } while (opcaoT != 0);
  970.  
  971. break;
  972. }
  973. } while (opcao != 0);
  974. }
  975.  
  976. void removerPerguntasEM (ELEMENTO_EM **iniListaEM, ELEMENTO_EM **fimListaEM, int numeroEM){
  977.  
  978. ELEMENTO_EM *auxEM = NULL;
  979.  
  980. auxEM = (ELEMENTO_EM *) malloc (1 * sizeof (ELEMENTO_EM *));
  981.  
  982. if (auxEM == NULL){
  983. printf ("ERRO ao reservar memoria. \n \a");
  984. return;
  985. }
  986.  
  987. auxEM = *iniListaEM;
  988.  
  989.  
  990. if (*iniListaEM == NULL){
  991. printf ("Lista VAZIA! \n \a");
  992. return;
  993. }
  994.  
  995. while (auxEM != NULL && auxEM->infoEM.numero != numeroEM){
  996. auxEM = auxEM->seguinte;
  997. }
  998.  
  999. if (auxEM == NULL){
  1000. printf ("Numero da pergunta NAO EXISTE. \n");
  1001. return;
  1002. }
  1003.  
  1004. if (auxEM->anterior == NULL){
  1005. (*iniListaEM) = auxEM->seguinte;
  1006. if ((*iniListaEM) != NULL){
  1007. (*iniListaEM)->anterior = NULL;
  1008. }
  1009. else{
  1010. auxEM->anterior->seguinte = auxEM->seguinte;
  1011. }
  1012. }
  1013.  
  1014. if (auxEM->seguinte == NULL){
  1015. (*fimListaEM) = auxEM->anterior;
  1016. if ((*fimListaEM) != NULL){
  1017. (*fimListaEM)->seguinte = NULL;
  1018. }
  1019. else{
  1020. auxEM->seguinte->anterior = auxEM->anterior;
  1021. }
  1022. }
  1023.  
  1024. free (auxEM);
  1025. }
  1026.  
  1027. void removerPerguntasVF (ELEMENTO_VF **iniListaVF, ELEMENTO_VF **fimListaVF, int numeroVF){
  1028.  
  1029. ELEMENTO_VF *auxVF = NULL;
  1030.  
  1031. auxVF = (ELEMENTO_VF *) malloc (1 * sizeof (ELEMENTO_VF *));
  1032.  
  1033. if (auxVF == NULL){
  1034. printf ("ERRO ao reservar memoria. \n \a");
  1035. return;
  1036. }
  1037.  
  1038. auxVF = *iniListaVF;
  1039.  
  1040. if (*iniListaVF == NULL){
  1041. printf ("Lista VAZIA! \n \a");
  1042. return;
  1043. }
  1044.  
  1045. while (auxVF != NULL && auxVF->infoVF.numero != numeroVF){
  1046. auxVF = auxVF->seguinte;
  1047. }
  1048.  
  1049. if (auxVF == NULL){
  1050. printf ("Numero da pergunta NAO EXISTE. \n");
  1051. return;
  1052. }
  1053.  
  1054. if (auxVF->anterior == NULL){
  1055. (*iniListaVF) = auxVF->seguinte;
  1056. if ((*iniListaVF) != NULL){
  1057. (*iniListaVF)->anterior = NULL;
  1058. }
  1059. else{
  1060. auxVF->anterior->seguinte = auxVF->seguinte;
  1061. }
  1062. }
  1063.  
  1064. if (auxVF->seguinte == NULL){
  1065. (*fimListaVF) = auxVF->anterior;
  1066. if ((*fimListaVF) != NULL){
  1067. (*fimListaVF)->seguinte = NULL;
  1068. }
  1069. else{
  1070. auxVF->seguinte->anterior = auxVF->anterior;
  1071. }
  1072. }
  1073.  
  1074. free (auxVF);
  1075. }
  1076.  
  1077. void removerPerguntasO (ELEMENTO_O **iniListaO, ELEMENTO_O **fimListaO, int numeroO){
  1078.  
  1079. ELEMENTO_O *auxO = NULL;
  1080.  
  1081. auxO = (ELEMENTO_O *) malloc (1 * sizeof (ELEMENTO_O *));
  1082.  
  1083. if (auxO == NULL){
  1084. printf ("ERRO ao reservar memoria. \n \a");
  1085. return;
  1086. }
  1087.  
  1088. auxO = *iniListaO;
  1089.  
  1090. if (*iniListaO == NULL){
  1091. printf ("Lista VAZIA! \n \a");
  1092. return;
  1093. }
  1094.  
  1095. while (auxO != NULL && auxO->infoO.numero != numeroO){
  1096. auxO = auxO->seguinte;
  1097. }
  1098.  
  1099. if (auxO == NULL){
  1100. printf ("Numero da pergunta NAO EXISTE. \n");
  1101. return;
  1102. }
  1103.  
  1104. if (auxO->anterior == NULL){
  1105. (*iniListaO) = auxO->seguinte;
  1106. if ((*iniListaO) != NULL){
  1107. (*iniListaO)->anterior = NULL;
  1108. }
  1109. else{
  1110. auxO->anterior->seguinte = auxO->seguinte;
  1111. }
  1112. }
  1113.  
  1114. if (auxO->seguinte == NULL){
  1115. (*fimListaO) = auxO->anterior;
  1116. if ((*fimListaO) != NULL){
  1117. (*fimListaO)->seguinte = NULL;
  1118. }
  1119. else{
  1120. auxO->seguinte->anterior = auxO->anterior;
  1121. }
  1122. }
  1123.  
  1124. free (auxO);
  1125. }
  1126.  
  1127. void removerPerguntasT (ELEMENTO_T **iniListaT, ELEMENTO_T **fimListaT, int numeroT) {
  1128.  
  1129. ELEMENTO_T *auxT = NULL;
  1130.  
  1131. auxT = (ELEMENTO_T *) malloc (1 * sizeof (ELEMENTO_T *));
  1132.  
  1133. if (auxT == NULL){
  1134. printf ("ERRO ao reservar memoria. \n \a");
  1135. return;
  1136. }
  1137.  
  1138. auxT = *iniListaT;
  1139.  
  1140. if (iniListaT == NULL){
  1141. printf ("Lista VAZIA! \n \a");
  1142. return;
  1143. }
  1144.  
  1145. while (auxT != NULL && auxT->infoT.numero != numeroT){
  1146. auxT = auxT->seguinte;
  1147. }
  1148.  
  1149. if (auxT == NULL){
  1150. printf ("Numero da pergunta NAO EXISTE. \n");
  1151. return;
  1152. }
  1153.  
  1154. if (auxT->anterior == NULL){
  1155. (*iniListaT) = auxT->seguinte;
  1156. if ((*iniListaT) != NULL){
  1157. (*iniListaT)->anterior = NULL;
  1158. }
  1159. else{
  1160. auxT->anterior->seguinte = auxT->seguinte;
  1161. }
  1162. }
  1163.  
  1164. if (auxT->seguinte == NULL){
  1165. (*fimListaT) = auxT->anterior;
  1166. if ((*fimListaT) != NULL){
  1167. (*fimListaT)->seguinte = NULL;
  1168. }
  1169. else{
  1170. auxT->seguinte->anterior = auxT->anterior;
  1171. }
  1172. }
  1173.  
  1174. free (auxT);
  1175. }
  1176.  
  1177.  
  1178. void removerPerguntas (){
  1179.  
  1180. int opcao = 0;
  1181. int numeroEM = 0;
  1182. int numeroVF = 0;
  1183. int numeroO = 0;
  1184. int numeroT = 0;
  1185. int resultadoEM = 0;
  1186. int resultadoVF = 0;
  1187. int resultadoO = 0;
  1188. int resultadoT = 0;
  1189. INFO_EM infoEMTemp;
  1190. INFO_VF infoVFTemp;
  1191. INFO_O infoOTemp;
  1192. INFO_T infoTTemp;
  1193. FILE *registoDePerguntasEM;
  1194. FILE *registoDePerguntasVF;
  1195. FILE *registoDePerguntasO;
  1196. FILE *registoDePerguntasT;
  1197.  
  1198. printf ("***** REMOCAO DE PERGUNTAS ***** \n");
  1199. printf ("******************************** \n\n");
  1200.  
  1201. do {
  1202. printf ("Que tipo de pergunta pretende remover? \n");
  1203. printf ("1. Escolha Multipla \n");
  1204. printf ("2. Verdadeiro ou Falso \n");
  1205. printf ("3. Ordenacao \n");
  1206. printf ("4. Texto \n");
  1207. printf ("0. Sair \n");
  1208. fflush (stdin);
  1209. scanf ("%i", &opcao);
  1210.  
  1211. switch (opcao){
  1212. case 1 : printf ("Ira remover uma pergunta do tipo <Escolha Multipla>. \n");
  1213. listarCrescentePerguntasEM (iniListaEM);
  1214. printf ("Qual o numero da pergunta de <Escolha Multipla> que pretende remover? \n");
  1215. fflush (stdin);
  1216. scanf ("%i", &numeroEM);
  1217. removerPerguntasEM (&iniListaEM, &fimListaEM, numeroEM);
  1218. break;
  1219. case 2 : printf ("Ira remover uma pergunta do tipo <Verdadeiro ou Falso>. \n");
  1220. listarCrescentePerguntasVF (iniListaVF);
  1221. printf ("Qual o numero da pergunta de <Verdadeiro ou Falso> que pretende remover? \n");
  1222. fflush (stdin);
  1223. scanf ("%i", &numeroVF);
  1224. removerPerguntasVF (&iniListaVF, &fimListaVF, numeroVF);
  1225. break;
  1226. case 3 : printf ("Ira remover uma pergunta do tipo <Ordenacao>. \n");
  1227. listarCrescentePerguntasO (iniListaO);
  1228. printf ("Qual o numero da pergunta de <Ordenacao> que pretende remover? \n");
  1229. fflush (stdin);
  1230. scanf ("%i", &numeroO);
  1231. removerPerguntasO (&iniListaO, &fimListaO, numeroO);
  1232. break;
  1233. case 4 : printf ("Ira remover uma pergunta do tipo <Escolha Multipla>. \n");
  1234. listarCrescentePerguntasT (iniListaT);
  1235. printf ("Qual o numero da pergunta de <Ordenacao> que pretende remover? \n");
  1236. fflush (stdin);
  1237. scanf ("%i", &numeroT);
  1238. removerPerguntasT (&iniListaT, &fimListaT, numeroT);
  1239. break;
  1240. }
  1241. } while (opcao != 0);
  1242. }
  1243.  
  1244. void menuAdministrador (ADMINISTRADOR administrador, JOGADOR jogador){
  1245.  
  1246. int opcao;
  1247. INFO_EM newInfoEM;
  1248. INFO_VF newInfoVF;
  1249. INFO_O newInfoO;
  1250. INFO_T newInfoT;
  1251. static int numTotalEM = 0;
  1252. static int numTotalVF = 0;
  1253. static int numTotalT = 0;
  1254. static int numTotalO = 0;
  1255.  
  1256. do{
  1257. printf ("***** MENU DE ADMINISTRACAO ***** \n");
  1258. printf ("********************************* \n");
  1259. printf ("Introduza a opcao pretendida: \n");
  1260. printf ("1. Acrescentar perguntas \n");
  1261. printf ("2. Alterar perguntas \n");
  1262. printf ("3. Remover perguntas \n");
  1263. printf ("4. Criar Administrador \n");
  1264. printf ("5. Listar Administradores \n");
  1265. printf ("6. Listar Jogadores \n");
  1266. printf ("0. Sair \n");
  1267. fflush(stdin);
  1268. scanf ("%i", &opcao);
  1269.  
  1270. switch (opcao){
  1271. case 1 : acrescentarPerguntas (&numTotalEM, &numTotalVF, &numTotalO, &numTotalT);
  1272. break;
  1273. case 2 : alterarPerguntas ();
  1274. break;
  1275. case 3 : removerPerguntas ();
  1276. break;
  1277. case 4 : criarAdministrador (administrador);
  1278. break;
  1279. case 5 : listarAdministradores (administrador);
  1280. break;
  1281. case 6 : listarJogadores (jogador);
  1282. break;
  1283. }
  1284. } while (opcao != 0);
  1285. }
  1286.  
  1287. int jogoSmall (int novaPontuacao, ELEMENTO_EM *iniListaEM, ELEMENTO_VF *iniListaVF, ELEMENTO_O *iniListaO, ELEMENTO_T *iniListaT){
  1288.  
  1289. char opcao2Utilizador[200];
  1290. char opcao1Utilizador[10];
  1291. ELEMENTO_EM *auxEM = NULL;
  1292. ELEMENTO_VF *auxVF = NULL;
  1293. ELEMENTO_O *auxO = NULL;
  1294. ELEMENTO_T *auxT = NULL;
  1295.  
  1296. printf ("***** JOGO DO TIPO S ***** \n");
  1297. printf ("************************** \n\n");
  1298.  
  1299. printf ("O jogo do tipo <Small> encontra-se indisponivel.\n");
  1300. printf ("Pretende continuar e jogar com todas as perguntas existentes nos ficheiros armazenados? Sim/Nao \n");
  1301. fflush(stdin);
  1302. scanf ("%s", &opcao1Utilizador);
  1303.  
  1304. if (strcmp (opcao1Utilizador, "NAO") == 0 ||
  1305. strcmp (opcao1Utilizador, "nao") == 0 ||
  1306. strcmp (opcao1Utilizador, "Nao") == 0 ||
  1307. strcmp (opcao1Utilizador, "n") == 0 ){
  1308. novaPontuacao = 0;
  1309. }
  1310. else {
  1311. printf ("Perguntas do tipo <Escolha Multipla> \n");
  1312. printf ("Escreva a resposta pretendida como esta presente no enunciado. \n");
  1313.  
  1314. if (iniListaEM == NULL){
  1315. printf ("Lista VAZIA! \n \a");
  1316. return;
  1317. }
  1318.  
  1319. for (auxEM = iniListaEM; auxEM != NULL; auxEM = auxEM->seguinte){
  1320. printf ("Enunciado: %s \n", auxEM->infoEM.enunciado);
  1321. printf ("%s: \n", auxEM->infoEM.respostaCorreta);
  1322. printf ("%s: \n", auxEM->infoEM.respostaIncorreta1);
  1323. printf ("%s: \n", auxEM->infoEM.respostaIncorreta2);
  1324. printf ("%s: \n", auxEM->infoEM.respostaIncorreta3);
  1325. scanf ("%s", &opcao2Utilizador);
  1326.  
  1327. if (strcmp(opcao2Utilizador, auxEM->infoEM.respostaCorreta) == 0){
  1328. novaPontuacao = novaPontuacao + 15;
  1329. }
  1330. else{
  1331. if (strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta1) == 0 ||
  1332. strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta2) == 0 ||
  1333. strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta3) == 0){
  1334. novaPontuacao = novaPontuacao - 10;
  1335. }
  1336. else{
  1337. printf ("Resposta INEXISTENTE! \n \a");
  1338. return;
  1339. }
  1340. }
  1341. }
  1342.  
  1343. printf ("Perguntas do tipo <Verdadeiro ou Falso>");
  1344. printf ("Escreva a resposta apenas com <Verdadeiro> ou <Falso>. \n");
  1345.  
  1346. if (iniListaVF == NULL){
  1347. printf ("Lista VAZIA! \n \a");
  1348. return;
  1349. }
  1350.  
  1351. for (auxVF = iniListaVF; auxVF != NULL; auxVF = auxVF->seguinte){
  1352. printf ("Enunciado: %s \n", auxVF->infoVF.enunciado);
  1353. printf ("%s: \n", auxVF->infoVF.respostaCorreta);
  1354. printf ("%s: \n", auxVF->infoVF.respostaIncorreta);
  1355. scanf ("%s", &opcao2Utilizador);
  1356.  
  1357. if (strcmp(opcao2Utilizador, auxVF->infoVF.respostaCorreta) == 0){
  1358. novaPontuacao = novaPontuacao + 30;
  1359. }
  1360. else{
  1361. if (strcmp(opcao2Utilizador, auxVF->infoVF.respostaIncorreta) == 0){
  1362. novaPontuacao = novaPontuacao - 30;
  1363. }
  1364. else{
  1365. printf ("Resposta INEXISTENTE! \n \a");
  1366. return;
  1367. }
  1368. }
  1369. }
  1370.  
  1371. printf ("Perguntas do tipo <Ordenacao>");
  1372. printf ("Escreva a resposta apenas ordenando com os numeros. \n");
  1373.  
  1374. if (iniListaO == NULL){
  1375. printf ("Lista VAZIA! \n \a");
  1376. return;
  1377. }
  1378.  
  1379. for (auxO = iniListaO; auxO != NULL; auxO = auxO->seguinte){
  1380. printf ("Enunciado: %s \n", auxO->infoO.enunciado);
  1381. printf ("%s: \n", auxO->infoO.respostaCorreta);
  1382. fflush(stdin);
  1383. scanf ("%s", &opcao2Utilizador);
  1384.  
  1385. if (strcmp(opcao2Utilizador, auxO->infoO.respostaCorreta) == 0){
  1386. novaPontuacao = novaPontuacao + 50;
  1387. }
  1388. else{
  1389. novaPontuacao = novaPontuacao - 20;
  1390. }
  1391. }
  1392.  
  1393. printf ("Perguntas do tipo <T>");
  1394. printf ("Escreva a resposta apenas com um pequeno texto que ache que esteja correto. \n");
  1395.  
  1396. if (iniListaT == NULL){
  1397. printf ("Lista VAZIA! \n \a");
  1398. return;
  1399. }
  1400.  
  1401. for (auxT = iniListaT; auxT != NULL; auxT = auxT->seguinte){
  1402. printf ("Enunciado: %s \n", auxT->infoT.enunciado);
  1403. printf ("%s: \n", auxT->infoT.respostaCorreta);
  1404. fflush(stdin);
  1405. scanf ("%s", &opcao2Utilizador);
  1406.  
  1407. if (strcmp(opcao2Utilizador, auxT->infoT.respostaCorreta) == 0){
  1408. novaPontuacao = novaPontuacao + 10;
  1409. }
  1410. else{
  1411. novaPontuacao = 0;
  1412. }
  1413. }
  1414. }
  1415.  
  1416. return novaPontuacao;
  1417. }
  1418.  
  1419. int jogoMedium (int novaPontuacao, ELEMENTO_EM *iniListaEM, ELEMENTO_VF *iniListaVF, ELEMENTO_O *iniListaO, ELEMENTO_T *iniListaT){
  1420.  
  1421. char opcao2Utilizador[200];
  1422. char opcao1Utilizador[10];
  1423. ELEMENTO_EM *auxEM = NULL;
  1424. ELEMENTO_VF *auxVF = NULL;
  1425. ELEMENTO_O *auxO = NULL;
  1426. ELEMENTO_T *auxT = NULL;
  1427.  
  1428. printf ("***** JOGO DO TIPO M ***** \n");
  1429. printf ("************************** \n\n");
  1430.  
  1431. printf ("O jogo do tipo <Medium> encontra-se indisponivel.\n");
  1432. printf ("Pretende continuar e jogar com todas as perguntas existentes nos ficheiros armazenados? Sim/Nao \n");
  1433. scanf ("%s", &opcao1Utilizador);
  1434.  
  1435. if (strcmp (opcao1Utilizador, "NAO") == 0 ||
  1436. strcmp (opcao1Utilizador, "nao") == 0 ||
  1437. strcmp (opcao1Utilizador, "Nao") == 0 ||
  1438. strcmp (opcao1Utilizador, "n") == 0 ){
  1439. novaPontuacao = 0;
  1440. }
  1441. else {
  1442. printf ("Perguntas do tipo <Escolha Multipla> \n");
  1443. printf ("Escreva a resposta pretendida como esta presente no enunciado. \n");
  1444.  
  1445. if (iniListaEM == NULL){
  1446. printf ("Lista VAZIA! \n \a");
  1447. return;
  1448. }
  1449.  
  1450. for (auxEM = iniListaEM; auxEM != NULL; auxEM = auxEM->seguinte){
  1451. printf ("Enunciado: %s \n", auxEM->infoEM.enunciado);
  1452. printf ("%s: \n", auxEM->infoEM.respostaCorreta);
  1453. printf ("%s: \n", auxEM->infoEM.respostaIncorreta1);
  1454. printf ("%s: \n", auxEM->infoEM.respostaIncorreta2);
  1455. printf ("%s: \n", auxEM->infoEM.respostaIncorreta3);
  1456. fflush(stdin);
  1457. scanf ("%s", &opcao2Utilizador);
  1458.  
  1459. if (strcmp(opcao2Utilizador, auxEM->infoEM.respostaCorreta) == 0){
  1460. novaPontuacao = novaPontuacao + 15;
  1461. }
  1462. else{
  1463. if (strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta1) == 0 ||
  1464. strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta2) == 0 ||
  1465. strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta3) == 0){
  1466. novaPontuacao = novaPontuacao - 10;
  1467. }
  1468. else{
  1469. printf ("Resposta INEXISTENTE! \n \a");
  1470. return;
  1471. }
  1472. }
  1473. }
  1474.  
  1475. printf ("Perguntas do tipo <Verdadeiro ou Falso>");
  1476. printf ("Escreva a resposta apenas com <Verdadeiro> ou <Falso>. \n");
  1477.  
  1478. if (iniListaVF == NULL){
  1479. printf ("Lista VAZIA! \n \a");
  1480. return;
  1481. }
  1482.  
  1483. for (auxVF = iniListaVF; auxVF != NULL; auxVF = auxVF->seguinte){
  1484. printf ("Enunciado: %s \n", auxVF->infoVF.enunciado);
  1485. printf ("%s: \n", auxVF->infoVF.respostaCorreta);
  1486. printf ("%s: \n", auxVF->infoVF.respostaIncorreta);
  1487. fflush(stdin);
  1488. scanf ("%s", &opcao2Utilizador);
  1489.  
  1490. if (strcmp(opcao2Utilizador, auxVF->infoVF.respostaCorreta) == 0){
  1491. novaPontuacao = novaPontuacao + 30;
  1492. }
  1493. else{
  1494. if (strcmp(opcao2Utilizador, auxVF->infoVF.respostaIncorreta) == 0){
  1495. novaPontuacao = novaPontuacao - 30;
  1496. }
  1497. else{
  1498. printf ("Resposta INEXISTENTE! \n \a");
  1499. return;
  1500. }
  1501. }
  1502. }
  1503.  
  1504. printf ("Perguntas do tipo <Ordenacao>");
  1505. printf ("Escreva a resposta apenas ordenando com os numeros. \n");
  1506.  
  1507. if (iniListaO == NULL){
  1508. printf ("Lista VAZIA! \n \a");
  1509. return;
  1510. }
  1511.  
  1512. for (auxO = iniListaO; auxO != NULL; auxO = auxO->seguinte){
  1513. printf ("Enunciado: %s \n", auxO->infoO.enunciado);
  1514. printf ("%s: \n", auxO->infoO.respostaCorreta);
  1515. fflush(stdin);
  1516. scanf ("%s", &opcao2Utilizador);
  1517.  
  1518. if (strcmp(opcao2Utilizador, auxO->infoO.respostaCorreta) == 0){
  1519. novaPontuacao = novaPontuacao + 50;
  1520. }
  1521. else{
  1522. novaPontuacao = novaPontuacao - 20;
  1523. }
  1524. }
  1525.  
  1526. printf ("Perguntas do tipo <T>");
  1527. printf ("Escreva a resposta apenas com um pequeno texto que ache que esteja correto. \n");
  1528.  
  1529. if (iniListaT == NULL){
  1530. printf ("Lista VAZIA! \n \a");
  1531. return;
  1532. }
  1533.  
  1534. for (auxT = iniListaT; auxT != NULL; auxT = auxT->seguinte){
  1535. printf ("Enunciado: %s \n", auxT->infoT.enunciado);
  1536. printf ("%s: \n", auxT->infoT.respostaCorreta);
  1537. fflush(stdin);
  1538. scanf ("%s", &opcao2Utilizador);
  1539.  
  1540. if (strcmp(opcao2Utilizador, auxT->infoT.respostaCorreta) == 0){
  1541. novaPontuacao = novaPontuacao + 10;
  1542. }
  1543. else{
  1544. novaPontuacao = 0;
  1545. }
  1546. }
  1547. }
  1548.  
  1549. return novaPontuacao;
  1550. }
  1551.  
  1552. int jogoLarge (int novaPontuacao, ELEMENTO_EM *iniListaEM, ELEMENTO_VF *iniListaVF, ELEMENTO_O *iniListaO, ELEMENTO_T *iniListaT){
  1553.  
  1554. char opcao2Utilizador[200];
  1555. char opcao1Utilizador[10];
  1556. ELEMENTO_EM *auxEM = NULL;
  1557. ELEMENTO_VF *auxVF = NULL;
  1558. ELEMENTO_O *auxO = NULL;
  1559. ELEMENTO_T *auxT = NULL;
  1560.  
  1561. printf ("***** JOGO DO TIPO L ***** \n");
  1562. printf ("************************** \n\n");
  1563.  
  1564. printf ("O jogo do tipo <Large> encontra-se indisponivel.\n");
  1565. printf ("Pretende continuar e jogar com todas as perguntas existentes nos ficheiros armazenados? Sim/Nao \n");
  1566. scanf ("%s", &opcao1Utilizador);
  1567.  
  1568. if (strcmp (opcao1Utilizador, "NAO") == 0 ||
  1569. strcmp (opcao1Utilizador, "nao") == 0 ||
  1570. strcmp (opcao1Utilizador, "Nao") == 0 ||
  1571. strcmp (opcao1Utilizador, "n") == 0 ){
  1572. novaPontuacao = 0;
  1573. }
  1574. else {
  1575. printf ("Perguntas do tipo <Escolha Multipla> \n");
  1576. printf ("Escreva a resposta pretendida como esta presente no enunciado. \n");
  1577.  
  1578. if (iniListaEM == NULL){
  1579. printf ("Lista VAZIA! \n \a");
  1580. return;
  1581. }
  1582.  
  1583. for (auxEM = iniListaEM; auxEM != NULL; auxEM = auxEM->seguinte){
  1584. printf ("Enunciado: %s \n", auxEM->infoEM.enunciado);
  1585. printf ("%s: \n", auxEM->infoEM.respostaCorreta);
  1586. printf ("%s: \n", auxEM->infoEM.respostaIncorreta1);
  1587. printf ("%s: \n", auxEM->infoEM.respostaIncorreta2);
  1588. printf ("%s: \n", auxEM->infoEM.respostaIncorreta3);
  1589. fflush(stdin);
  1590. scanf ("%s", &opcao2Utilizador);
  1591.  
  1592. if (strcmp(opcao2Utilizador, auxEM->infoEM.respostaCorreta) == 0){
  1593. novaPontuacao = novaPontuacao + 15;
  1594. }
  1595. else{
  1596. if (strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta1) == 0 ||
  1597. strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta2) == 0 ||
  1598. strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta3) == 0){
  1599. novaPontuacao = novaPontuacao - 10;
  1600. }
  1601. else{
  1602. printf ("Resposta INEXISTENTE! \n \a");
  1603. return;
  1604. }
  1605. }
  1606. }
  1607.  
  1608. printf ("Perguntas do tipo <Verdadeiro ou Falso>");
  1609. printf ("Escreva a resposta apenas com <Verdadeiro> ou <Falso>. \n");
  1610.  
  1611. if (iniListaVF == NULL){
  1612. printf ("Lista VAZIA! \n \a");
  1613. return;
  1614. }
  1615.  
  1616. for (auxVF = iniListaVF; auxVF != NULL; auxVF = auxVF->seguinte){
  1617. printf ("Enunciado: %s \n", auxVF->infoVF.enunciado);
  1618. printf ("%s: \n", auxVF->infoVF.respostaCorreta);
  1619. printf ("%s: \n", auxVF->infoVF.respostaIncorreta);
  1620. fflush(stdin);
  1621. scanf ("%s", &opcao2Utilizador);
  1622.  
  1623. if (strcmp(opcao2Utilizador, auxVF->infoVF.respostaCorreta) == 0){
  1624. novaPontuacao = novaPontuacao + 30;
  1625. }
  1626. else{
  1627. if (strcmp(opcao2Utilizador, auxVF->infoVF.respostaIncorreta) == 0){
  1628. novaPontuacao = novaPontuacao - 30;
  1629. }
  1630. else{
  1631. printf ("Resposta INEXISTENTE! \n \a");
  1632. return;
  1633. }
  1634. }
  1635. }
  1636.  
  1637. printf ("Perguntas do tipo <Ordenacao>");
  1638. printf ("Escreva a resposta apenas ordenando com os numeros. \n");
  1639.  
  1640. if (iniListaO == NULL){
  1641. printf ("Lista VAZIA! \n \a");
  1642. return;
  1643. }
  1644.  
  1645. for (auxO = iniListaO; auxO != NULL; auxO = auxO->seguinte){
  1646. printf ("Enunciado: %s \n", auxO->infoO.enunciado);
  1647. printf ("%s: \n", auxO->infoO.respostaCorreta);
  1648. fflush(stdin);
  1649. scanf ("%s", &opcao2Utilizador);
  1650.  
  1651. if (strcmp(opcao2Utilizador, auxO->infoO.respostaCorreta) == 0){
  1652. novaPontuacao = novaPontuacao + 50;
  1653. }
  1654. else{
  1655. novaPontuacao = novaPontuacao - 20;
  1656. }
  1657. }
  1658.  
  1659. printf ("Perguntas do tipo <T>");
  1660. printf ("Escreva a resposta apenas com um pequeno texto que ache que esteja correto. \n");
  1661.  
  1662. if (iniListaT == NULL){
  1663. printf ("Lista VAZIA! \n \a");
  1664. return;
  1665. }
  1666.  
  1667. for (auxT = iniListaT; auxT != NULL; auxT = auxT->seguinte){
  1668. printf ("Enunciado: %s \n", auxT->infoT.enunciado);
  1669. printf ("%s: \n", auxT->infoT.respostaCorreta);
  1670. fflush(stdin);
  1671. scanf ("%s", &opcao2Utilizador);
  1672.  
  1673. if (strcmp(opcao2Utilizador, auxT->infoT.respostaCorreta) == 0){
  1674. novaPontuacao = novaPontuacao + 10;
  1675. }
  1676. else{
  1677. novaPontuacao = 0;
  1678. }
  1679. }
  1680. }
  1681.  
  1682. return novaPontuacao;
  1683. }
  1684.  
  1685. int jogoXL (int novaPontuacao, ELEMENTO_EM *iniListaEM, ELEMENTO_VF *iniListaVF, ELEMENTO_O *iniListaO, ELEMENTO_T *iniListaT){
  1686.  
  1687. char opcao2Utilizador[200];
  1688. char opcao1Utilizador[10];
  1689. ELEMENTO_EM *auxEM = NULL;
  1690. ELEMENTO_VF *auxVF = NULL;
  1691. ELEMENTO_O *auxO = NULL;
  1692. ELEMENTO_T *auxT = NULL;
  1693.  
  1694. printf ("***** JOGO DO TIPO XL ***** \n");
  1695. printf ("************************** \n\n");
  1696.  
  1697. printf ("O jogo do tipo <Extra Large> encontra-se indisponivel.\n");
  1698. printf ("Pretende continuar e jogar com todas as perguntas existentes nos ficheiros armazenados? Sim/Nao \n");
  1699. scanf ("%s", &opcao1Utilizador);
  1700.  
  1701. if (strcmp (opcao1Utilizador, "NAO") == 0 ||
  1702. strcmp (opcao1Utilizador, "nao") == 0 ||
  1703. strcmp (opcao1Utilizador, "Nao") == 0 ||
  1704. strcmp (opcao1Utilizador, "n") == 0 ){
  1705. novaPontuacao = 0;
  1706. }
  1707. else {
  1708. printf ("Perguntas do tipo <Escolha Multipla> \n");
  1709. printf ("Escreva a resposta pretendida como esta presente no enunciado. \n");
  1710.  
  1711. if (iniListaEM == NULL){
  1712. printf ("Lista VAZIA! \n \a");
  1713. return;
  1714. }
  1715.  
  1716. for (auxEM = iniListaEM; auxEM != NULL; auxEM = auxEM->seguinte){
  1717. printf ("Enunciado: %s \n", auxEM->infoEM.enunciado);
  1718. printf ("%s: \n", auxEM->infoEM.respostaCorreta);
  1719. printf ("%s: \n", auxEM->infoEM.respostaIncorreta1);
  1720. printf ("%s: \n", auxEM->infoEM.respostaIncorreta2);
  1721. printf ("%s: \n", auxEM->infoEM.respostaIncorreta3);
  1722. fflush(stdin);
  1723. scanf ("%s", &opcao2Utilizador);
  1724.  
  1725. if (strcmp(opcao2Utilizador, auxEM->infoEM.respostaCorreta) == 0){
  1726. novaPontuacao = novaPontuacao + 15;
  1727. }
  1728. else{
  1729. if (strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta1) == 0 ||
  1730. strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta2) == 0 ||
  1731. strcmp(opcao2Utilizador, auxEM->infoEM.respostaIncorreta3) == 0){
  1732. novaPontuacao = novaPontuacao - 10;
  1733. }
  1734. else{
  1735. printf ("Resposta INEXISTENTE! \n \a");
  1736. return;
  1737. }
  1738. }
  1739. }
  1740.  
  1741. printf ("Perguntas do tipo <Verdadeiro ou Falso>");
  1742. printf ("Escreva a resposta apenas com <Verdadeiro> ou <Falso>. \n");
  1743.  
  1744. if (iniListaVF == NULL){
  1745. printf ("Lista VAZIA! \n \a");
  1746. return;
  1747. }
  1748.  
  1749. for (auxVF = iniListaVF; auxVF != NULL; auxVF = auxVF->seguinte){
  1750. printf ("Enunciado: %s \n", auxVF->infoVF.enunciado);
  1751. printf ("%s: \n", auxVF->infoVF.respostaCorreta);
  1752. printf ("%s: \n", auxVF->infoVF.respostaIncorreta);
  1753. fflush(stdin);
  1754. scanf ("%s", &opcao2Utilizador);
  1755.  
  1756. if (strcmp(opcao2Utilizador, auxVF->infoVF.respostaCorreta) == 0){
  1757. novaPontuacao = novaPontuacao + 30;
  1758. }
  1759. else{
  1760. if (strcmp(opcao2Utilizador, auxVF->infoVF.respostaIncorreta) == 0){
  1761. novaPontuacao = novaPontuacao - 30;
  1762. }
  1763. else{
  1764. printf ("Resposta INEXISTENTE! \n \a");
  1765. return;
  1766. }
  1767. }
  1768. }
  1769.  
  1770. printf ("Perguntas do tipo <Ordenacao>");
  1771. printf ("Escreva a resposta apenas ordenando com os numeros. \n");
  1772.  
  1773. if (iniListaO == NULL){
  1774. printf ("Lista VAZIA! \n \a");
  1775. return;
  1776. }
  1777.  
  1778. for (auxO = iniListaO; auxO != NULL; auxO = auxO->seguinte){
  1779. printf ("Enunciado: %s \n", auxO->infoO.enunciado);
  1780. printf ("%s: \n", auxO->infoO.respostaCorreta);
  1781. fflush(stdin);
  1782. scanf ("%s", &opcao2Utilizador);
  1783.  
  1784. if (strcmp(opcao2Utilizador, auxO->infoO.respostaCorreta) == 0){
  1785. novaPontuacao = novaPontuacao + 50;
  1786. }
  1787. else{
  1788. novaPontuacao = novaPontuacao - 20;
  1789. }
  1790. }
  1791.  
  1792. printf ("Perguntas do tipo <T>");
  1793. printf ("Escreva a resposta apenas com um pequeno texto que ache que esteja correto. \n");
  1794.  
  1795. if (iniListaT == NULL){
  1796. printf ("Lista VAZIA! \n \a");
  1797. return;
  1798. }
  1799.  
  1800. for (auxT = iniListaT; auxT != NULL; auxT = auxT->seguinte){
  1801. printf ("Enunciado: %s \n", auxT->infoT.enunciado);
  1802. printf ("%s: \n", auxT->infoT.respostaCorreta);
  1803. fflush(stdin);
  1804. scanf ("%s", &opcao2Utilizador);
  1805.  
  1806. if (strcmp(opcao2Utilizador, auxT->infoT.respostaCorreta) == 0){
  1807. novaPontuacao = novaPontuacao + 10;
  1808. }
  1809. else{
  1810. novaPontuacao = 0;
  1811. }
  1812. }
  1813. }
  1814.  
  1815. return novaPontuacao;
  1816. }
  1817.  
  1818. void instrucoesJogador (){
  1819.  
  1820. printf ("***** PAINEL DE INSTRUCOES ***** \n");
  1821. printf ("******************************** \n");
  1822.  
  1823. printf ("S - <Small> : 3 perguntas de cada grupo \n");
  1824. printf ("M - <Medium> : 6 perguntas de cada grupo \n");
  1825. printf ("L - <Large> : 12 perguntas de cada grupo \n");
  1826. printf ("X - <Extra Large> : 24 perguntas de cada grupo \n\n");
  1827.  
  1828. printf ("O jogo e constituido por 4 grupos de perguntas de cultura geral:\n");
  1829. printf ("um grupo de escolha multipla, um grupo de verdadeiro ou falso,\n");
  1830. printf ("um grupo de ordenacao e um grupo de quem perde sai. \n\n");
  1831.  
  1832. printf ("- No 1o grupo, de escolha multipla, o jogador deve selecionar a \n");
  1833. printf (" resposta correta entre as 4 opcoes de resposta possiveis. Cada \n");
  1834. printf (" resposta correta acresce a pontuacao do jogador em 15 pontos. \n");
  1835. printf (" Se errar, sao-lhe retirados 10 pontos ao total de pontos. \n\n");
  1836.  
  1837. printf ("- No 2o grupo, verdadeiro ou falso, cada pergunta tem apenas duas \n");
  1838. printf (" possiveis respostas: Verdadeiro ou Falso. Se o jogador acertar \n");
  1839. printf (" soma 30 pontos a pontua��o global, sen�o sao-lhe retirados 30 pontos. \n\n");
  1840.  
  1841. printf ("- No 3o grupo, ordenacao, o jogador devera ordenar as 3 opcoes \n");
  1842. printf (" apresentadas. Se a ordenacao estiver correta sao-lhe somada \n");
  1843. printf (" 50 pontos a pontuacao total, senao sao-lhe retirados 20 pontos. \n\n");
  1844.  
  1845. printf ("- No 4o grupo, quem perde sai, as perguntas devem ser de resposta curta.\n");
  1846. printf (" Se o jogador errar uma reposta sai do grupo com 0 pontos e n�o responde \n");
  1847. printf (" a mais perguntas do grupo. Se acertar em todas as respostas, soma 10 \n");
  1848. printf (" pontos por cada pergunta ao total de pontos. \n");
  1849.  
  1850. }
  1851.  
  1852. void alteraPontuacao (int novaPontuacao, JOGADOR jogador){
  1853.  
  1854. int resultado = 0;
  1855. char userName[100];
  1856. JOGADOR jogadorTemp;
  1857. FILE *registoJogadores;
  1858.  
  1859. registoJogadores = fopen ("registoJogadores.dat", "r+b");
  1860.  
  1861. if (registoJogadores == NULL){
  1862. printf ("ERRO na abertura do ficheiro <registoJogadores.dat>. \n \a");
  1863. return;
  1864. }
  1865.  
  1866. while (!feof(registoJogadores)){
  1867. resultado = fread (&jogadorTemp, sizeof (JOGADOR), 1, registoJogadores);
  1868. if (resultado){
  1869. printf ("Username: %s \n", &jogadorTemp.userName);
  1870. printf ("Pontuacao: %i \n", &jogadorTemp.pontuacao);
  1871. }
  1872. }
  1873.  
  1874. printf ("Introduza o seu username novamente: \n");
  1875. fflush (stdin);
  1876. gets (jogador.userName);
  1877.  
  1878. novaPontuacao = jogador.pontuacao;
  1879. printf ("Nova Pontuacao do jogador <%s>: %i \n", jogador.userName, novaPontuacao);
  1880. fwrite (&jogador, sizeof (JOGADOR), 1, registoJogadores);
  1881.  
  1882. fclose (registoJogadores);
  1883. }
  1884.  
  1885. void gravarDataEHora (char novaData[], char novaHora[], JOGADOR jogador){
  1886.  
  1887. int resultado = 0;
  1888. FILE *registoJogadores;
  1889.  
  1890. registoJogadores = fopen ("registoJogadores.dat", "ab");
  1891.  
  1892. if (registoJogadores == NULL){
  1893. printf ("ERRO na abertura do ficheiro binario <registoJogadores.dat>. \n \a");
  1894. return;
  1895. }
  1896.  
  1897. printf ("Introduza o seu username novamente: \n");
  1898. fflush (stdin);
  1899. gets (jogador.userName);
  1900.  
  1901. novaData = jogador.data;
  1902. novaHora = jogador.hora;
  1903.  
  1904. printf ("O jogador %s jogou a ultima vez no dia %s as %s. \n", jogador.userName, jogador.data, jogador.hora);
  1905. fwrite (&jogador, sizeof (JOGADOR), 1, registoJogadores);
  1906. fclose (registoJogadores);
  1907. }
  1908.  
  1909. void menuJogador (JOGADOR jogador){
  1910.  
  1911. int opcao = 0;
  1912. int novaPontuacao = 0;
  1913. FILE *registoJogadores;
  1914. char novaHora[20];
  1915. char novaData[20];
  1916.  
  1917. do {
  1918. printf ("***** MENU DO JOGO ***** \n");
  1919. printf ("************************ \n");
  1920. 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");
  1921. printf ("Introduza o tipo de jogo que pretende iniciar: \n");
  1922. printf ("1. Small \n");
  1923. printf ("2. Medium \n");
  1924. printf ("3. Large \n");
  1925. printf ("4. Extra Large \n");
  1926. printf ("5. Gravar data e hora \n");
  1927. printf ("6. Listar Jogadores por Ordem Alfabetica \n");
  1928. printf ("7. Listar Jogadores por Ordem Decrescente de Pontuacao \n");
  1929. printf ("8. Top5 de Jogadores \n");
  1930. printf ("9. Instrucoes e outras informacoes importantes \n");
  1931. printf ("0. Sair \n");
  1932. fflush (stdin);
  1933. scanf ("%i", &opcao);
  1934.  
  1935. switch (opcao){
  1936. case 1 : jogoSmall (novaPontuacao, iniListaEM, iniListaVF, iniListaO, iniListaT);
  1937. alteraPontuacao (novaPontuacao, jogador);
  1938. printf ("Nova pontuacao do jogador: %i. \n", novaPontuacao);
  1939. break;
  1940. case 2 : jogoMedium (novaPontuacao, iniListaEM, iniListaVF, iniListaO, iniListaT);
  1941. alteraPontuacao (novaPontuacao, jogador);
  1942. printf ("Nova pontuacao do jogador: %i. \n", novaPontuacao);
  1943. break;
  1944. case 3 : jogoLarge (novaPontuacao, iniListaEM, iniListaVF, iniListaO, iniListaT);
  1945. alteraPontuacao (novaPontuacao, jogador);
  1946. printf ("Nova pontuacao do jogador: %i. \n", novaPontuacao);
  1947. break;
  1948. case 4 : jogoXL (novaPontuacao, iniListaEM, iniListaVF, iniListaO, iniListaT);
  1949. alteraPontuacao (novaPontuacao, jogador);
  1950. printf ("Nova pontuacao do jogador: %i. \n", novaPontuacao);
  1951. break;
  1952. case 5 : printf ("Introduza a ultima hora que jogou: \n");
  1953. fflush(stdin);
  1954. scanf ("%s", &novaHora);
  1955. printf ("Introduza a ultima hora que jogou: \n");
  1956. fflush(stdin);
  1957. scanf ("%s", &novaData);
  1958. gravarDataEHora (novaHora, novaData, jogador);
  1959. break;
  1960. case 6 :
  1961. break;
  1962. case 7 :
  1963. break;
  1964. case 8 :
  1965. break;
  1966. case 9 : instrucoesJogador ();
  1967. break;
  1968. }
  1969. } while (opcao != 0);
  1970. }
  1971.  
  1972. int main(int argc, char *argv[]) {
  1973.  
  1974. ADMINISTRADOR administrador;
  1975. JOGADOR jogador;
  1976. int opcao;
  1977. int administradorExiste = 0;
  1978. int jogadorExiste = 0;
  1979.  
  1980. do {
  1981. printf ("**************************** QUEM SABE, SABE! ******************************\n");
  1982. printf ("****************************** MENU INICIAL ********************************\n");
  1983. printf ("****************************************************************************\n");
  1984. printf ("Introduza a opcao pretendida: \n");
  1985. printf ("1. Entrar como Administrador \n");
  1986. printf ("2. Entrar como Jogador \n");
  1987. printf ("0. Sair \n");
  1988. fflush(stdin);
  1989. scanf ("%i", &opcao);
  1990.  
  1991. switch (opcao){
  1992. case 1 : administradorExiste = existeAdministrador (administrador);
  1993. if (administradorExiste == 2){
  1994. printf ("Aprovado como ADMINISTRADOR. \n");
  1995. menuAdministrador (administrador, jogador);
  1996. }
  1997. if (administradorExiste == 1){
  1998. printf ("Identificacao ERRADA. \n");
  1999. continue; // permite reiniciar o ciclo
  2000. }
  2001. if (administradorExiste == 0){
  2002. printf ("Reprovado como ADMINISTRADOR. \n");
  2003. printf ("Tente entrar como JOGADOR. \n");
  2004. }
  2005. break;
  2006. case 2 : jogadorExiste = existeJogador (jogador);
  2007. if (jogadorExiste == 2){
  2008. printf ("Aprovado como JOGADOR. \n");
  2009. menuJogador (jogador);
  2010. }
  2011.  
  2012. if (jogadorExiste == 1){
  2013. printf ("Identificacao ERRADA. \n");
  2014. continue; // permite reiniciar o ciclo
  2015. }
  2016. if (jogadorExiste == 0) {
  2017. printf ("Sera introduzido como novo JOGADOR. \n");
  2018. criarJogador (jogador);
  2019. }
  2020. break;
  2021. case 3 : criarAdministrador (administrador);
  2022. break;
  2023. }
  2024. } while (opcao != 0);
  2025.  
  2026. return 0;
  2027. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement