Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- #include <stdlib.h>
- #include "Pokedex.h"
- #include "Pokemon.h"
- #define MAX 10 //Numero maximo de pokemon na pokedex
- /*Inicialização da pokedex*/
- bool initPokedex(tPokedex* p) {
- int i=0;
- p->v = (tPokedex*) malloc (MAX*sizeof(tPokedex));
- if (p == NULL)
- return false;
- else {
- p->tamMax = MAX;
- p->numElems = 0;
- for (i=0;i<MAX;i++) { //Iniciando a pokedex com nenhum pokemon registrado.
- p->v[i].reg = false;
- p->v[i].ID = i+1;
- p->v[i].candy = 0;
- }
- return true;
- }
- return false;
- }
- /*Zerar pokedex e liberar memoria*/
- void limparPokedex (tPokedex* p) {
- free(p->v);
- initPokedex(p);
- }
- /*Função para gerar valor aleatorio de candy necessario para evolução semelhante ao próprio jogo*/
- int CandyEvolucao () {
- int x = rand() % 401;
- while (x != 12 && x != 25 && x != 50 && x != 100 && x != 400)
- x = rand() % 401;
- return x;
- }
- /*Função que insere na pokedex. Um vetor alocado dinamicamente, onde se o pokemon ja estiver registrado, terá o valor true*/
- bool inserirPokemon(tPokedex* p, int valor) {
- if (p->v[valor-1].reg == false) {
- p->numElems++;
- p->v[valor-1].reg = true;
- p->v[valor-1].ID = valor;
- p->v[valor-1].candy = p->v[valor-1].candy + 3;
- p->v[valor-1].evolve = CandyEvolucao();
- printf("Pokemon %d registrado com sucesso na Pokedex\n", valor);
- return true;
- }
- p->v[valor-1].candy = p->v[valor-1].candy + 3;
- return false;
- }
- /*Função para imprimir na tela a pokedex*/ /*ERRO*/
- void imprimirPokedex(tPokedex p) {
- int i=0;
- printf("%d Pokemon registrados\n", tamPokedex(p));
- printf("Impressão da Pokedex:\n");
- while (i<MAX) {
- if (p.v[i].reg == true)
- printf("Pokemon %d consta na Pokedex\n", p.v[i].ID);
- else
- printf("Pokemon %d nao consta na Pokedex\n", p.v[i].ID);
- i++;
- }
- }
- /*Numero de pokemon registrados*/
- int tamPokedex(tPokedex p) {
- return p.numElems;
- }
- /*Função de busca, para saber se o pokemon ja foi registrad*/
- bool buscaPokemon (tPokedex p, int valor) {
- int i=0;
- for (i=0;i<MAX;i++) {
- if (p.v[i].ID == valor);
- return true;
- }
- return false;
- }
- /*Função para mostrar na tela as informações de um Pokemon da pokedex*/
- bool InfoPokemon (tPokedex p, int valor) {
- int i=0;
- if (!buscaPokemon(p, valor))
- return false;
- while (i<MAX) {
- if (p.v[i].ID == valor) {
- printf("Dados do Pokemon %d:\n", valor);
- printf("Numero de candys: %d\n", p.v[i].candy);
- printf("Candys necessarios para evolucao: %d\n", p.v[i].evolve);
- printf("\n\n\n");
- return true;
- }
- i++;
- }
- }
Add Comment
Please, Sign In to add comment