Commit e11086e4 authored by bryan.quispe's avatar bryan.quispe

Add new file

parents
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Create a structure to hold data on Pokemon.
typedef struct PokemonNode {
char name[20];
char ability[20];
struct PokemonNode *next;
struct PokemonNode *prev;
} Pokemon;
// Create a structure to hold a player's data.
typedef struct PlayerNode {
char name[20];
int pokemonCount;
Pokemon *ownedPokemon[100];
struct PlayerNode *next;
struct PlayerNode *prev;
} Player;
// Establish a structure to hold the Pokedex.
typedef struct {
Pokemon *headPokemon;
Player *headPlayer;
} Pokedex;
// Build a Pokedex.
Pokedex pokedex = { NULL, NULL };
// Create a new Pokemon node with this function.
Pokemon *createPokemonNode(const char *name, const char *ability) {
Pokemon *newNode = malloc(sizeof(Pokemon));
strcpy(newNode->name, name);
strcpy(newNode->ability, ability);
newNode->next = NULL;
newNode->prev = NULL;
return newNode;
}
// Add a new Pokemon to the list feature
void addPokemonToList(Pokemon *newNode) {
if (pokedex.headPokemon == NULL) {
pokedex.headPokemon = newNode;
} else {
Pokemon *current = pokedex.headPokemon;
while (current->next != NULL) {
current = current->next;
}
current->next = newNode;
newNode->prev = current;
}
}
// Ability to look up a Pokemon using its name
Pokemon *searchPokemonByName(const char *name) {
Pokemon *current = pokedex.headPokemon;
while (current != NULL) {
if (strcmp(current->name, name) == 0) {
return current;
}
current = current->next;
}
return NULL;
}
//Create a new Player node function
Player *createPlayerNode(const char *name) {
Player *newNode = malloc(sizeof(Player));
strcpy(newNode->name, name);
newNode->pokemonCount = 0;
newNode->next = NULL;
newNode->prev = NULL;
return newNode;
}
// Adding a new player to the list function
void addPlayerToList(Player *newNode) {
if (pokedex.headPlayer == NULL) {
pokedex.headPlayer = newNode;
} else {
Player *current = pokedex.headPlayer;
while (current->next != NULL) {
current = current->next;
}
current->next = newNode;
newNode->prev = current;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment