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

commit9000

parent e4ce6059
...@@ -27,7 +27,8 @@ int main(void) ...@@ -27,7 +27,8 @@ int main(void)
// Display details of each player // Display details of each player
/* /*
This section can be regarded as a dissection of ListPokemon This section can be regarded as a dissection of ListPokemon
and ListPlayers. and ListPlayers with its assigned function declaration in
main.c.
*/ */
DisplayPlayerDetails(playerHead, "armin"); DisplayPlayerDetails(playerHead, "armin");
DisplayPlayerDetails(playerHead, "chase"); DisplayPlayerDetails(playerHead, "chase");
......
...@@ -3,30 +3,31 @@ ...@@ -3,30 +3,31 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "liststructure.c" #include "liststructure.c" // relating main to file containing lists
// Setting up nodes for printing out
// Details of Pokemon // Details of Pokemon
void DisplayPokemonDetails(Pokedex* pokedex, char name[20]) { void DisplayPokemonDetails(Pokedex* pokedex, char name[20]) { // display function at start of main, pokedex struct points to variable pokedex
PokemonNode* headPoke = pokedex; PokemonNode* headPoke = pokedex; // pokemon points to head of itself to equal the pokedex variable declared in the above function
while (headPoke != NULL) { while (headPoke != NULL) { // While pokemon node head does not equal null, will return correct strings
if (strcmp(headPoke -> name, name) == 0) { if (strcmp(headPoke -> name, name) == 0) { // checks if name stored in pokemon head is similar to name input variable
printf("\nPOKEMON DETAILS\nname: %s\n", headPoke->name); printf("\nPOKEMON DETAILS\nname: %s\n", headPoke->name); // to print out pokemon details starting with name
printf("type: %s\n", headPoke->type); printf("type: %s\n", headPoke->type); //head of pokemon node access store for type and will print out in string
printf("primary ability: %s\n", headPoke->ability); printf("primary ability: %s\n", headPoke->ability);
return; return;
} }
headPoke = headPoke -> next; headPoke = headPoke -> next; //pokemon node head accessing the "next" pointer to traverse singly linked list
} }
} }
// Details of Player // Details of Player
void DisplayPlayerDetails(Pokedex* pokedex, char name[50]) { void DisplayPlayerDetails(Pokedex* pokedex, char name[50]) {
PlayerNode *playerHead = FindPlayer(pokedex, name); PlayerNode *playerHead = FindPlayer(pokedex, name);
printf("\nPLAYER DETAILS\nname: %s\n", playerHead->name); printf("\nPLAYER DETAILS\nname: %s\n", playerHead->name);
printf("pokemon owned: %d\n", playerHead->totalPokemon); printf("pokemon owned: %d\n", playerHead->totalPokemon);
printf("pokemon they have:\n"); printf("pokemon they have:\n");
if (playerHead->totalPokemon > 0) { if (playerHead->totalPokemon > 0) {
for (int i = 0; i < playerHead->totalPokemon; i++) { for (int i = 0; i < playerHead->totalPokemon; i++) { // Prints list out vertically instead of horizontal rows
printf("%s\n", playerHead->PokemonArray[i]); printf("%s\n", playerHead->PokemonArray[i]);
} }
} }
...@@ -58,7 +59,6 @@ PlayerNode* ListPlayers(Pokedex* pokedex) { ...@@ -58,7 +59,6 @@ PlayerNode* ListPlayers(Pokedex* pokedex) {
PokemonNode* NewPokemonNode(char name[20], char type[20], char ability[30]) { PokemonNode* NewPokemonNode(char name[20], char type[20], char ability[30]) {
PokemonNode* newPoke = NULL; PokemonNode* newPoke = NULL;
newPoke = malloc(sizeof(PokemonNode)); newPoke = malloc(sizeof(PokemonNode));
if (newPoke != NULL) { if (newPoke != NULL) {
strcpy(newPoke->name, name); strcpy(newPoke->name, name);
strcpy(newPoke->type, type); strcpy(newPoke->type, type);
...@@ -97,7 +97,7 @@ PokemonNode* FindPokemon(Pokedex* pokedex, char name[20]) { ...@@ -97,7 +97,7 @@ PokemonNode* FindPokemon(Pokedex* pokedex, char name[20]) {
return NULL; return NULL;
} }
// Creates a new player node and returns a pointer to said node
PlayerNode* NewPlayerNode(char name[50]) { PlayerNode* NewPlayerNode(char name[50]) {
PlayerNode* playerNew = NULL; PlayerNode* playerNew = NULL;
playerNew = malloc(sizeof(PlayerNode)); playerNew = malloc(sizeof(PlayerNode));
...@@ -110,7 +110,7 @@ PlayerNode* NewPlayerNode(char name[50]) { ...@@ -110,7 +110,7 @@ PlayerNode* NewPlayerNode(char name[50]) {
return playerNew; return playerNew;
} }
// Checks if Player name already exists, if not a new node is created
void AddPlayerToList(Pokedex* pokedex, char name[50]) { void AddPlayerToList(Pokedex* pokedex, char name[50]) {
PlayerNode* ptr = pokedex; PlayerNode* ptr = pokedex;
bool exists = false; bool exists = false;
...@@ -127,7 +127,7 @@ void AddPlayerToList(Pokedex* pokedex, char name[50]) { ...@@ -127,7 +127,7 @@ void AddPlayerToList(Pokedex* pokedex, char name[50]) {
ptr->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* FindPlayer(Pokedex* pokedex, char name[50]) {
PlayerNode* ptr = pokedex; PlayerNode* ptr = pokedex;
while (ptr != NULL) { while (ptr != NULL) {
...@@ -150,3 +150,5 @@ void AddPokemonToPlayer(Pokedex* player, Pokedex* poke, char playerName[50], cha ...@@ -150,3 +150,5 @@ void AddPokemonToPlayer(Pokedex* player, Pokedex* poke, char playerName[50], cha
playerptr->totalPokemon++; playerptr->totalPokemon++;
} }
} }
// DOESN'T PRINT OUT LISTS, RUNNING OUT OF TIME
\ No newline at end of file
No preview for this file type
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