Commit bd0d4a69 authored by elijah vasquez's avatar elijah vasquez 🦍

finalmaybe

parent f6c18628
// Structs and functions placed here // Structs and functions placed here
// Pokemon List // Pokemon List
typedef struct PokemonNode typedef struct PokemonNode
{ {
char name[100]; char name[20];
char type[100]; char type[20];
char ability[100]; char ability[30];
struct PokemonNode *next; struct PokemonNode *next;
} PokemonNode; } PokemonNode;
// Player List // Player List
typedef struct PlayerNode typedef struct PlayerNode
{ {
char name[100]; char name[50];
int totalPokemon; int totalPokemon;
PokemonNode* PokemonArray[100]; //Array of players PokemonNode* PokemonArray[20]; //Array of players
struct PlayerNode *next; struct PlayerNode *next;
} PlayerNode; } PlayerNode;
...@@ -26,22 +27,23 @@ typedef struct Pokedex ...@@ -26,22 +27,23 @@ typedef struct Pokedex
// Pokemon List functions // Pokemon List functions
PokemonNode* NewPokemonNode(char name[100], char type[100], char ability[100]); PokemonNode* NewPokemonNode(char name[20], char type[20], char ability[30]);
void AddPokemonToList(Pokedex* funct, char name[100], char type[100], char ability[100]); void AddPokemonToList(Pokedex* funct, char name[20], char type[20], char ability[30]);
PokemonNode* FindPokemon(Pokedex* funct, char name[100]); PokemonNode* FindPokemon(Pokedex* funct, char name[20]);
// Player List functions // Player List functions
PlayerNode* NewPlayerNode(char name[100]); // Create new node, return pointer to node PlayerNode* NewPlayerNode(char name[50]); // Create new node, return pointer to node
void AddPlayerToList(Pokedex* funct, char name[100]); // Check if name already exists in Player list. void AddPlayerToList(Pokedex* funct, char name[50]); // Check if name already exists in Player list.
PlayerNode* FindPlayer(Pokedex* funct, char name[100]); // Searches Player list for name. PlayerNode* FindPlayer(Pokedex* funct, char name[50]); // Searches Player list for name.
void AddPokemonToPlayer(Pokedex* funct, Pokedex* funct2, char playerName[100], char pokemonName[100]); // Adds Pokemon to player's Pokemon list void AddPokemonToPlayer(Pokedex* funct, Pokedex* funct2, char playerName[50], char pokemonName[20]); // Adds Pokemon to player's Pokemon list
// Additional functions for the pokedex // Additional functions for the pokedex
// Pokemon details functs // Pokemon details functs
void DisplayPokemonDetails(Pokedex* funct, char name[100]); // Output details of pokemon void DisplayPokemonDetails(Pokedex* funct, char name[20]); // Output details of pokemon
PokemonNode* ListPokemon(Pokedex* funct); //output list of names of all POKEMON in pokedex PokemonNode* ListPokemon(Pokedex* funct); //output list of names of all POKEMON in pokedex
// Pokemon players functs // Pokemon players functs
void DisplayPlayerDetails(Pokedex* funct, char name[100]); // output details of players, incl. list of names of pokemon owned void DisplayPlayerDetails(Pokedex* funct, char name[50]); // output details of players, incl. list of names of pokemon owned
PlayerNode * ListPlayers(Pokedex* funct); //output list of names of all PLAYERS in pokedex PlayerNode * ListPlayers(Pokedex* funct); //output list of names of all PLAYERS in pokedex
// Calling of functions and setting up nodes // Calling of functions and setting up nodes
#include "functions.h" #include "functions.h"
int main(void) int main(void)
{ // Adding Pokemon to list { // Adding Pokemon to list
...@@ -17,11 +16,10 @@ int main(void) ...@@ -17,11 +16,10 @@ int main(void)
// Adding pokemon to player // Adding pokemon to player
AddPokemonToPlayer(pokeHead, playerHead, "armin", "blastoise"); AddPokemonToPlayer(pokeHead, playerHead, "armin", "blastoise");
AddPokemonToPlayer(pokeHead, playerHead, "armin", "dragapult"); AddPokemonToPlayer(pokeHead, playerHead, "armin", "dragapult");
AddPokemonToPlayer(pokeHead, playerHead, "chase", "dragapult");
AddPokemonToPlayer(pokeHead, playerHead, "chase", "regieleki");
AddPokemonToPlayer(pokeHead, playerHead, "chase", "volcarona"); AddPokemonToPlayer(pokeHead, playerHead, "chase", "volcarona");
AddPokemonToPlayer(pokeHead, playerHead, "ziggy", "regieleki"); AddPokemonToPlayer(pokeHead, playerHead, "ziggy", "regieleki");
// To display all of both pokemon and players // To display all of both pokemon and players
ListPokemon(pokeHead); ListPokemon(pokeHead);
ListPlayers(playerHead); ListPlayers(playerHead);
......
// Main: setting up nodes and printing #include <stdbool.h>
#include "functioncall.c" #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "liststructure.c"
#include"functions.h"
// Details of Pokemon
void DisplayPokemonDetails(Pokedex* pokedex, char name[50]) {
PokemonNode* headPoke = pokedex;
while (headPoke != NULL) {
if (strcmp(headPoke->name, name) == 0) {
printf("\nPOKEMON DETAILS\nname: %s\n", headPoke->name);
printf("type: %s\n", headPoke->type);
printf("primary ability: %s\n", headPoke->ability);
return;
}
headPoke = headPoke->next;
}
}
// Details of Player
void DisplayPlayerDetails(Pokedex* pokedex, char name[50]) {
PlayerNode *playerHead = FindPlayer(pokedex, name);
printf("\nPLAYER DETAILS\nname: %s\n", playerHead->name);
printf("pokemon owned: %d\n", playerHead->totalPokemon);
printf("pokemon they have:\n");
if (playerHead->totalPokemon > 0) {
for (int i = 0; i < playerHead->totalPokemon; i++) {
printf("%s\n", playerHead->PokemonArray[i]);
}
}
}
// List ALL Pokemon
PokemonNode* ListPokemon(Pokedex* pokedex) {
PokemonNode* headPoke = pokedex;
printf("\nALL POKEMON\n");
while (headPoke != NULL) {
printf("%s\n", headPoke->name);
headPoke = headPoke->next;
}
return headPoke;
}
// List ALL Players
PlayerNode* ListPlayers(Pokedex* pokedex) {
PlayerNode* playerHead = pokedex;
printf("\nALL PLAYERS:\n");
while (playerHead != NULL) {
printf("%s\n", playerHead->name);
playerHead = playerHead->next;
}
return playerHead;
}
// Creates a new pokemon node and returns a pointer to said node
PokemonNode* NewPokemonNode(char name[50], char type[50], char ability[50]) {
PokemonNode* newPoke = NULL;
newPoke = malloc(sizeof(PokemonNode));
if (newPoke != NULL) {
strcpy(newPoke->name, name);
strcpy(newPoke->type, type);
strcpy(newPoke->ability, ability);
newPoke->next = NULL;
}
return newPoke;
}
// Checks if Pokemon name already exists, if not a new node is created
void AddPokemonToList(Pokedex* pokedex, char name[20], char type[20],
char ability[50]) {
PokemonNode* ptr = pokedex;
bool exists = false;
while (ptr->next != NULL) {
if (strcmp(ptr->name, name) == 0) {
exists = true;
break;
}
ptr = ptr->next;
}
if (exists == true) {
return;
}
ptr->next = NewPokemonNode(name, type, ability);
}
// Searches Pokemon List for name, if the name is not found NULL is returned
PokemonNode *FindPokemon(Pokedex *pokedex, char name[20]) {
PokemonNode *pointer = pokedex;
while (pointer != NULL) {
if (strcmp(pointer->name, name) == 0) {
return pointer;
}
pointer = pointer->next;
}
return NULL;
}
// Creates a new player node and returns a pointer to said node
PlayerNode *NewPlayerNode(char name[50]) {
PlayerNode *new_player = NULL;
new_player = malloc(sizeof(PlayerNode));
if (new_player != NULL) {
strcpy(new_player->name, name);
new_player->totalPokemon = 0;
new_player->next = NULL;
}
return new_player;
}
// Checks if Player name already exists, if not a new node is created
void AddPlayerToList(Pokedex *pokedex, char name[50]) {
PlayerNode *pointer = pokedex;
bool already_exists = false;
while (pointer->next != NULL) {
if (strcmp(pointer->name, name) == 0) {
already_exists = true;
break;
}
pointer = pointer->next;
}
if (already_exists == true) {
return;
}
pointer->next = NewPlayerNode(name);
}
// Searches Player List for name, if the name is not found NULL is returned
PlayerNode *FindPlayer(Pokedex *pokedex, char name[50]) {
PlayerNode *pointer = pokedex;
while (pointer != NULL) {
if (strcmp(pointer->name, name) == 0) {
return pointer;
}
pointer = pointer->next;
}
return NULL;
}
// Adds the Pokemon to a players list and updates the counter
void AddPokemonToPlayer(Pokedex *player, Pokedex *pokemon, char playerName[50], char pokemonName[20]) {
PlayerNode *playerptr = FindPlayer(player, playerName);
PokemonNode *pokemonptr = FindPokemon(pokemon, pokemonName);
if (playerptr->totalPokemon < 50) {
playerptr->PokemonArray[playerptr->totalPokemon] =
pokemonptr;
playerptr->totalPokemon++;
}
}
// Creates a new pokemon node and returns a pointer to said node
PokemonNode* NewPokemonNode(char name[50], char type[50], char ability[50]) {
PokemonNode* newPoke = NULL;
newPoke = malloc(sizeof(PokemonNode));
if (newPoke != NULL) {
strcpy(newPoke->name, name);
strcpy(newPoke->type, type);
strcpy(newPoke->ability, ability);
newPoke->next = NULL;
}
return newPoke;
}
// Checks if Pokemon name already exists, if not a new node is created
void AddPokemonToList(Pokedex* pokedex, char name[20], char type[20],
char ability[50]) {
PokemonNode* ptr = pokedex;
bool exists = false;
while (ptr->next != NULL) {
if (strcmp(ptr->name, name) == 0) {
exists = true;
break;
}
ptr = ptr->next;
}
if (exists == true) {
return;
}
ptr->next = NewPokemonNode(name, type, ability);
}
// Searches Pokemon List for name, if the name is not found NULL is returned
PokemonNode *FindPokemon(Pokedex *pokedex, char name[20]) {
PokemonNode *pointer = pokedex;
while (pointer != NULL) {
if (strcmp(pointer->name, name) == 0) {
return pointer;
}
pointer = pointer->next;
}
return NULL;
}
// Creates a new player node and returns a pointer to said node
PlayerNode *NewPlayerNode(char name[50]) {
PlayerNode *new_player = NULL;
new_player = malloc(sizeof(PlayerNode));
if (new_player != NULL) {
strcpy(new_player->name, name);
new_player->totalPokemon = 0;
new_player->next = NULL;
}
return new_player;
}
// Checks if Player name already exists, if not a new node is created
void AddPlayerToList(Pokedex *pokedex, char name[50]) {
PlayerNode *pointer = pokedex;
bool already_exists = false;
while (pointer->next != NULL) {
if (strcmp(pointer->name, name) == 0) {
already_exists = true;
break;
}
pointer = pointer->next;
}
if (already_exists == true) {
return;
}
pointer->next = NewPlayerNode(name);
}
// Searches Player List for name, if the name is not found NULL is returned
PlayerNode *FindPlayer(Pokedex *pokedex, char name[50]) {
PlayerNode *pointer = pokedex;
while (pointer != NULL) {
if (strcmp(pointer->name, name) == 0) {
return pointer;
}
pointer = pointer->next;
}
return NULL;
}
// Adds the Pokemon to a players list and updates the counter
void AddPokemonToPlayer(Pokedex *player, Pokedex *pokemon, char playerName[50], char pokemonName[20]) {
PlayerNode *playerptr = FindPlayer(player, playerName);
PokemonNode *pokemonptr = FindPokemon(pokemon, pokemonName);
if (playerptr->totalPokemon < 50) {
playerptr->PokemonArray[playerptr->totalPokemon] =
pokemonptr;
playerptr->totalPokemon++;
}
}
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