Commit 3277127c authored by sam.pople's avatar sam.pople

submit

parent 1c10d31f
...@@ -10,12 +10,12 @@ void ListPokemon(Pokedex *pokedex) ...@@ -10,12 +10,12 @@ void ListPokemon(Pokedex *pokedex)
//This assigns a node to be a head for the pokemon list //This assigns a node to be a head for the pokemon list
PokemonNode *current = pokedex->pokemonhead; PokemonNode *current = pokedex->pokemonhead;
printf("\nList of Pokemon:\n"); printf("\nList of Pokemon:\n");
while (current != NULL) while (current != NULL)
{ //The current node is printed and then the next is assigned. { //The current node is printed and then the next is assigned.
printf("%s\n", current->name); printf("%s\n", current->name);
current = current->Next; current = current->nextpokemon;
} }
} }
//This displays the list of players //This displays the list of players
void ListPlayers(Pokedex* pokedex) void ListPlayers(Pokedex* pokedex)
...@@ -23,12 +23,13 @@ void ListPlayers(Pokedex* pokedex) ...@@ -23,12 +23,13 @@ void ListPlayers(Pokedex* pokedex)
//The first player item is made the head //The first player item is made the head
PlayerNode* current = pokedex->playerhead; PlayerNode* current = pokedex->playerhead;
printf("\nList of Players:\n"); printf("\nList of Players:\n");
while (current != NULL) while (current != NULL)
{ {
printf("%s\n", current->name); printf("%s\n", current->name);
current = current->Next; current = current->nextplayer;
} }
} }
//This creates each Pokemon node //This creates each Pokemon node
PokemonNode* NewPokemonNode(char name[20], char type[20], char ability[50]) PokemonNode* NewPokemonNode(char name[20], char type[20], char ability[50])
...@@ -37,7 +38,7 @@ PokemonNode* NewPokemonNode(char name[20], char type[20], char ability[50]) ...@@ -37,7 +38,7 @@ PokemonNode* NewPokemonNode(char name[20], char type[20], char ability[50])
strcpy(addnode->name, name); strcpy(addnode->name, name);
strcpy(addnode->type, type); strcpy(addnode->type, type);
strcpy(addnode->ability, ability); strcpy(addnode->ability, ability);
addnode->Next = NULL; addnode->nextpokemon = NULL;
return addnode; return addnode;
} }
//This creates each Player node //This creates each Player node
...@@ -48,7 +49,7 @@ PlayerNode *NewPlayerNode(char name[20]) ...@@ -48,7 +49,7 @@ PlayerNode *NewPlayerNode(char name[20])
addnode->numofpokemon = 0; addnode->numofpokemon = 0;
memset(addnode->PokemonArray, NULL, sizeof(addnode->PokemonArray)); memset(addnode->PokemonArray, NULL, sizeof(addnode->PokemonArray));
addnode->Next = NULL; addnode->nextplayer = NULL;
return addnode; return addnode;
} }
//This finds the Pokemon in the Pokemon list //This finds the Pokemon in the Pokemon list
...@@ -65,7 +66,7 @@ PokemonNode* FindPokemon(PokemonNode* head, char name[20]) ...@@ -65,7 +66,7 @@ PokemonNode* FindPokemon(PokemonNode* head, char name[20])
} }
else else
{ {
current = current->Next; current = current->nextpokemon;
} }
} }
return 0; return 0;
...@@ -82,7 +83,7 @@ PlayerNode* FindPlayer(PlayerNode* playerhead, char name[20]) ...@@ -82,7 +83,7 @@ PlayerNode* FindPlayer(PlayerNode* playerhead, char name[20])
} }
else else
{ {
current = current->Next; current = current->nextplayer;
} }
} }
return 0; return 0;
...@@ -93,7 +94,7 @@ void AddPokemonToList(Pokedex* pokedex, char name[20], char type[20], char abili ...@@ -93,7 +94,7 @@ void AddPokemonToList(Pokedex* pokedex, char name[20], char type[20], char abili
if (FindPokemon(pokedex->pokemonhead, name) == 0) if (FindPokemon(pokedex->pokemonhead, name) == 0)
{ {
PokemonNode *current = NewPokemonNode(name, type, ability); PokemonNode *current = NewPokemonNode(name, type, ability);
current->Next = pokedex->pokemonhead; current->nextpokemon = pokedex->pokemonhead;
pokedex->pokemonhead = current; pokedex->pokemonhead = current;
printf("Pokemon %s added\n", name); printf("Pokemon %s added\n", name);
} }
...@@ -109,7 +110,7 @@ void AddPlayerToList(Pokedex* pokedex, char name[20]) ...@@ -109,7 +110,7 @@ void AddPlayerToList(Pokedex* pokedex, char name[20])
if (FindPlayer(pokedex->playerhead, name) == 0) if (FindPlayer(pokedex->playerhead, name) == 0)
{ //If the player isnt already in the list, a new node is created { //If the player isnt already in the list, a new node is created
PlayerNode* current = NewPlayerNode(name); PlayerNode* current = NewPlayerNode(name);
current->Next = pokedex->playerhead; current->nextplayer = pokedex->playerhead;
pokedex->playerhead = current; pokedex->playerhead = current;
printf("Player %s Added\n", name); printf("Player %s Added\n", name);
} }
......
No preview for this file type
...@@ -4,7 +4,7 @@ typedef struct PokemonNode { ...@@ -4,7 +4,7 @@ typedef struct PokemonNode {
char name[20]; char name[20];
char type[20]; char type[20];
char ability[50]; char ability[50];
struct PokemonNode *Next; struct PokemonNode *nextpokemon;
} PokemonNode; } PokemonNode;
//This sets the structure variables for the player node (name, number of pokemon and Pokemon Array) //This sets the structure variables for the player node (name, number of pokemon and Pokemon Array)
...@@ -12,7 +12,7 @@ typedef struct PlayerNode { ...@@ -12,7 +12,7 @@ typedef struct PlayerNode {
char name[20]; char name[20];
int numofpokemon; int numofpokemon;
PokemonNode *PokemonArray[30]; PokemonNode *PokemonArray[30];
struct PlayerNode *Next; struct PlayerNode *nextplayer;
} PlayerNode; } PlayerNode;
typedef struct Pokedex { typedef struct Pokedex {
......
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