Commit 8e533737 authored by elijah vasquez's avatar elijah vasquez 🦍

idkanymore

parent 99d556d8
No preview for this file type
// Structs and functions placed here
// Pokemon List
typedef struct PokemonNode
{
char name[20];
typedef struct PokemonNode // typedef struct to create alias for data type
{ // in combination with struct for struct type
char name[20]; // kept at 20 as pokemon names don't exceed higher than value
char type[20];
char ability[30];
struct PokemonNode *next;
struct PokemonNode *next; // used for traversing singly linked list from pokemon
} PokemonNode;
// Player List
typedef struct PlayerNode
{
typedef struct PlayerNode // Player node will include name, pokemon owned and is placed
{ // in an array
char name[50];
int totalPokemon;
PokemonNode* PokemonArray[20]; //Array of players
struct PlayerNode *next;
int totalPokemon; // total number of pokemon owned by players
PokemonNode* PokemonArray[20]; // Array of players
struct PlayerNode *next; // used for traversing singly linked list
} PlayerNode;
// Pokedex structure
typedef struct Pokedex
typedef struct Pokedex // To house the header nodes to start single linked lists
{
PokemonNode *pokeHead;
PlayerNode *playerHead;
PokemonNode* pokeHead; // pokemon node used to create head pointer variable
PlayerNode* playerHead; //player node used to create head pointer variable
} Pokedex;
// Pokemon List functions
// Pokemon List
PokemonNode* NewPokemonNode(char name[20], char type[20], char ability[30]);
void AddPokemonToList(Pokedex* pokedex, char name[20], char type[20], char ability[30]);
PokemonNode* FindPokemon(Pokedex* pokedex, char name[20]);
// Player List functions
// Player List
PlayerNode* NewPlayerNode(char name[50]); // Create new node, return pointer to node
void AddPlayerToList(Pokedex* pokedex, char name[50]); // Check if name already exists in Player list.
PlayerNode* FindPlayer(Pokedex* pokedex, char name[50]); // Searches Player list for name.
void AddPokemonToPlayer(Pokedex* player, Pokedex* pokemon, char playerName[50], char pokemonName[20]); // Adds Pokemon to player's Pokemon list
// Additional functions for the pokedex
// Pokemon details functs
// Additional
// Pokemon details
void DisplayPokemonDetails(Pokedex* pokedex, char name[20]); // Output details of pokemon
PokemonNode* ListPokemon(Pokedex* pokedex); //output list of names of all POKEMON in pokedex
// Pokemon players functs
// Pokemon players
void DisplayPlayerDetails(Pokedex* pokedex, char name[50]); // output details of players, incl. list of names of pokemon owned
PlayerNode * ListPlayers(Pokedex* pokedex); //output list of names of all PLAYERS in pokedex
// Calling of functions and setting up nodes
#include "functions.h"
int main(void)
{ // Adding Pokemon to list
int main(void)
{ // Adding Pokemon nodes to list
Pokedex* pokeHead = NewPokemonNode("blastoise", "water", "torrent"); //Creation of node to introduce head of single linked list
AddPokemonToList(pokeHead, "dragapult", "dragon", "infiltrator");
AddPokemonToList(pokeHead, "volcarona", "fire", "flame body");
AddPokemonToList(pokeHead, "regieleki", "electric", "transistor");
// Adding player to player list
// Adding player nodes to player list
Pokedex* playerHead = NewPlayerNode("armin");
AddPlayerToList(playerHead, "chase");
AddPlayerToList(playerHead, "ziggy");
// Adding pokemon to player
// Linking pokemon with players
AddPokemonToPlayer(pokeHead, playerHead, "armin", "blastoise");
AddPokemonToPlayer(pokeHead, playerHead, "armin", "dragapult");
AddPokemonToPlayer(pokeHead, playerHead, "chase", "volcarona");
AddPokemonToPlayer(pokeHead, playerHead, "ziggy", "regieleki");
// To display all of both pokemon and players
// Displays and lists all pokemon and players present in program
ListPokemon(pokeHead);
ListPlayers(playerHead);
......@@ -34,4 +34,5 @@ int main(void)
DisplayPokemonDetails(pokeHead, "dragapult");
DisplayPokemonDetails(pokeHead, "volcarona");
DisplayPokemonDetails(pokeHead, "regieleki");
}
\ No newline at end of file
}
// Main file, RUN FROM HERE!!!
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -5,16 +6,16 @@
#include "liststructure.c"
// Details of Pokemon
void DisplayPokemonDetails(Pokedex* pokedex, char name[50]) {
void DisplayPokemonDetails(Pokedex* pokedex, char name[20]) {
PokemonNode* headPoke = pokedex;
while (headPoke != NULL) {
if (strcmp(headPoke->name, name) == 0) {
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;
headPoke = headPoke -> next;
}
}
......@@ -53,8 +54,8 @@ PlayerNode* ListPlayers(Pokedex* pokedex) {
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]) {
// Create new pokemon node, return pointer to it
PokemonNode* NewPokemonNode(char name[20], char type[20], char ability[30]) {
PokemonNode* newPoke = NULL;
newPoke = malloc(sizeof(PokemonNode));
......@@ -67,9 +68,8 @@ PokemonNode* NewPokemonNode(char name[50], char type[50], char ability[50]) {
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]) {
// If pokemon exists check
void AddPokemonToList(Pokedex* pokedex, char name[20], char type[20], char ability[50]) {
PokemonNode* ptr = pokedex;
bool exists = false;
while (ptr->next != NULL) {
......@@ -86,8 +86,8 @@ void AddPokemonToList(Pokedex* pokedex, char name[20], char type[20],
}
// Searches Pokemon List for name, if the name is not found NULL is returned
PokemonNode *FindPokemon(Pokedex *pokedex, char name[20]) {
PokemonNode *pointer = pokedex;
PokemonNode* FindPokemon(Pokedex* pokedex, char name[20]) {
PokemonNode* pointer = pokedex;
while (pointer != NULL) {
if (strcmp(pointer->name, name) == 0) {
return pointer;
......@@ -98,76 +98,21 @@ PokemonNode *FindPokemon(Pokedex *pokedex, char name[20]) {
}
// 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));
PlayerNode* NewPlayerNode(char name[50]) {
PlayerNode* playerNew = NULL;
playerNew = malloc(sizeof(PlayerNode));
if (new_player != NULL) {
strcpy(new_player->name, name);
new_player->totalPokemon = 0;
new_player->next = NULL;
if (playerNew != NULL) {
strcpy(playerNew->name, name);
playerNew->totalPokemon = 0;
playerNew->next = NULL;
}
return new_player;
return playerNew;
}
// 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;
void AddPlayerToList(Pokedex* pokedex, char name[50]) {
PlayerNode* ptr = pokedex;
bool exists = false;
while (ptr->next != NULL) {
if (strcmp(ptr->name, name) == 0) {
......@@ -179,70 +124,29 @@ void AddPokemonToList(Pokedex* pokedex, char name[20], char type[20],
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);
ptr->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;
PlayerNode* FindPlayer(Pokedex* pokedex, char name[50]) {
PlayerNode* ptr = pokedex;
while (ptr != NULL) {
if (strcmp(ptr->name, name) == 0) {
return ptr;
}
pointer = pointer->next;
ptr = ptr->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);
//ARRAY SECTION
// Add pokemon to player array, updates increment
void AddPokemonToPlayer(Pokedex* player, Pokedex* poke, char playerName[50], char pokemonName[20]) {
PlayerNode* playerptr = FindPlayer(player, playerName);
PokemonNode* pokeptr = FindPokemon(poke, pokemonName);
if (playerptr->totalPokemon < 50) {
playerptr->PokemonArray[playerptr->totalPokemon] =
pokemonptr;
pokeptr;
playerptr->totalPokemon++;
}
}
File added
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