Guest User

pokedex.c

a guest
Sep 18th, 2016
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <stdlib.h>
  4. #include "Pokedex.h"
  5. #include "Pokemon.h"
  6.  
  7. #define MAX 10 //Numero maximo de pokemon na pokedex
  8.  
  9. /*Inicialização da pokedex*/
  10. bool initPokedex(tPokedex* p) {
  11. int i=0;
  12. p->v = (tPokedex*) malloc (MAX*sizeof(tPokedex));
  13. if (p == NULL)
  14. return false;
  15. else {
  16. p->tamMax = MAX;
  17. p->numElems = 0;
  18. for (i=0;i<MAX;i++) { //Iniciando a pokedex com nenhum pokemon registrado.
  19. p->v[i].reg = false;
  20. p->v[i].ID = i+1;
  21. p->v[i].candy = 0;
  22. }
  23. return true;
  24. }
  25.  
  26. return false;
  27. }
  28.  
  29. /*Zerar pokedex e liberar memoria*/
  30. void limparPokedex (tPokedex* p) {
  31. free(p->v);
  32. initPokedex(p);
  33. }
  34.  
  35. /*Função para gerar valor aleatorio de candy necessario para evolução semelhante ao próprio jogo*/
  36. int CandyEvolucao () {
  37. int x = rand() % 401;
  38. while (x != 12 && x != 25 && x != 50 && x != 100 && x != 400)
  39. x = rand() % 401;
  40. return x;
  41. }
  42.  
  43. /*Função que insere na pokedex. Um vetor alocado dinamicamente, onde se o pokemon ja estiver registrado, terá o valor true*/
  44. bool inserirPokemon(tPokedex* p, int valor) {
  45. if (p->v[valor-1].reg == false) {
  46. p->numElems++;
  47. p->v[valor-1].reg = true;
  48. p->v[valor-1].ID = valor;
  49. p->v[valor-1].candy = p->v[valor-1].candy + 3;
  50. p->v[valor-1].evolve = CandyEvolucao();
  51. printf("Pokemon %d registrado com sucesso na Pokedex\n", valor);
  52. return true;
  53. }
  54. p->v[valor-1].candy = p->v[valor-1].candy + 3;
  55. return false;
  56. }
  57.  
  58. /*Função para imprimir na tela a pokedex*/ /*ERRO*/
  59. void imprimirPokedex(tPokedex p) {
  60. int i=0;
  61. printf("%d Pokemon registrados\n", tamPokedex(p));
  62. printf("Impressão da Pokedex:\n");
  63. while (i<MAX) {
  64. if (p.v[i].reg == true)
  65. printf("Pokemon %d consta na Pokedex\n", p.v[i].ID);
  66. else
  67. printf("Pokemon %d nao consta na Pokedex\n", p.v[i].ID);
  68. i++;
  69. }
  70. }
  71.  
  72. /*Numero de pokemon registrados*/
  73. int tamPokedex(tPokedex p) {
  74. return p.numElems;
  75. }
  76.  
  77. /*Função de busca, para saber se o pokemon ja foi registrad*/
  78. bool buscaPokemon (tPokedex p, int valor) {
  79. int i=0;
  80. for (i=0;i<MAX;i++) {
  81. if (p.v[i].ID == valor);
  82. return true;
  83. }
  84. return false;
  85. }
  86.  
  87. /*Função para mostrar na tela as informações de um Pokemon da pokedex*/
  88. bool InfoPokemon (tPokedex p, int valor) {
  89. int i=0;
  90. if (!buscaPokemon(p, valor))
  91. return false;
  92. while (i<MAX) {
  93. if (p.v[i].ID == valor) {
  94. printf("Dados do Pokemon %d:\n", valor);
  95. printf("Numero de candys: %d\n", p.v[i].candy);
  96. printf("Candys necessarios para evolucao: %d\n", p.v[i].evolve);
  97. printf("\n\n\n");
  98. return true;
  99. }
  100. i++;
  101. }
  102. }
Add Comment
Please, Sign In to add comment