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

submit

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