Commit 4e382470 authored by sam.pople's avatar sam.pople

update

parent 8a433112
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
# include <stdlib.h> # include <stdlib.h>
# include <string.h> # include <string.h>
# include "pokedexstructs.h" # include "pokedexstructs.h"
//main file. Run from here. //main file. Run from here. Click Run Code on VSC to run.
//functions //functions
void ListPokemon(Pokedex *pokedexpointer) void ListPokemon(Pokedex *pokedexpointer)
{ {
// This displays the list of pokemon. // This displays the list of pokemon.
//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 = pokedexpointer->pokemonhead; PokemonNode* current = pokedexpointer->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.
...@@ -39,7 +39,6 @@ PokemonNode* NewPokemonNode(char pokename[20], char poketype[20], char pokeabili ...@@ -39,7 +39,6 @@ PokemonNode* NewPokemonNode(char pokename[20], char poketype[20], char pokeabili
strcpy(addnode->name, pokename); strcpy(addnode->name, pokename);
strcpy(addnode->type, poketype); strcpy(addnode->type, poketype);
strcpy(addnode->ability, pokeability); strcpy(addnode->ability, pokeability);
return addnode; return addnode;
} }
//This creates each Player node //This creates each Player node
...@@ -54,9 +53,8 @@ PlayerNode *NewPlayerNode(char playername[20]) ...@@ -54,9 +53,8 @@ PlayerNode *NewPlayerNode(char playername[20])
return addnode; return addnode;
} }
//This finds the Pokemon in the Pokemon list //This finds the Pokemon in the Pokemon list
PokemonNode* FindPokemon(PokemonNode* pokehead, char pokename[20]) PokemonNode* FindPokemon(PokemonNode *pokehead, char pokename[20])
{ {
PokemonNode *current = pokehead; PokemonNode *current = pokehead;
while (current != NULL) while (current != NULL)
{ {
...@@ -70,7 +68,7 @@ PokemonNode* FindPokemon(PokemonNode* pokehead, char pokename[20]) ...@@ -70,7 +68,7 @@ PokemonNode* FindPokemon(PokemonNode* pokehead, char pokename[20])
return current; return current;
} }
} }
return 0; return NULL;
} }
//This searches the list for the specific player //This searches the list for the specific player
PlayerNode* FindPlayer(PlayerNode* playerhead, char playername[20]) PlayerNode* FindPlayer(PlayerNode* playerhead, char playername[20])
...@@ -92,13 +90,15 @@ PlayerNode* FindPlayer(PlayerNode* playerhead, char playername[20]) ...@@ -92,13 +90,15 @@ PlayerNode* FindPlayer(PlayerNode* playerhead, char playername[20])
//This adds a new Pokemon to the Pokemon list //This adds a new Pokemon to the Pokemon list
void AddPokemonToList(Pokedex* pokedexpointer, char pokename[20], char poketype[20], char pokeability[50]) void AddPokemonToList(Pokedex* pokedexpointer, char pokename[20], char poketype[20], char pokeability[50])
{ {
if (FindPokemon(pokedexpointer->pokemonhead, pokename) != 0) //This checks if the Pokemon already exists
if (FindPokemon(pokedexpointer->pokemonhead, pokename) != NULL)
{ {
printf("Pokemon exists\n"); printf("Pokemon exists\n");
} }
else else
//This adds new node and adds the Pokemon to the list
{ {
PokemonNode *current = NewPokemonNode(pokename, poketype, pokeability); PokemonNode* current = NewPokemonNode(pokename, poketype, pokeability);
current->nextpokemon = pokedexpointer->pokemonhead; current->nextpokemon = pokedexpointer->pokemonhead;
pokedexpointer->pokemonhead = current; pokedexpointer->pokemonhead = current;
printf("Pokemon %s added\n", pokename); printf("Pokemon %s added\n", pokename);
...@@ -129,6 +129,7 @@ void AddPokemonToPlayer(Pokedex* pokedexpointer, char pokemon[20], char player[2 ...@@ -129,6 +129,7 @@ void AddPokemonToPlayer(Pokedex* pokedexpointer, char pokemon[20], char player[2
{ {
for (int x=0; x <= PlayerPointer->numofpokemon; x++) for (int x=0; x <= PlayerPointer->numofpokemon; x++)
{ {
//This adds the Pokemon to the player if he isn't already there
if (PlayerPointer->PokemonArray[x] == NULL) if (PlayerPointer->PokemonArray[x] == NULL)
{ {
PlayerPointer->PokemonArray[x] = PokemonPointer; PlayerPointer->PokemonArray[x] = PokemonPointer;
...@@ -136,6 +137,7 @@ void AddPokemonToPlayer(Pokedex* pokedexpointer, char pokemon[20], char player[2 ...@@ -136,6 +137,7 @@ void AddPokemonToPlayer(Pokedex* pokedexpointer, char pokemon[20], char player[2
printf("\nThe Pokemon %s is now with the player %s.", PokemonPointer->name, PlayerPointer->name); printf("\nThe Pokemon %s is now with the player %s.", PokemonPointer->name, PlayerPointer->name);
break; break;
} }
//This checks if the Pokemon already exists with the player
else if (PlayerPointer->PokemonArray[x] == PokemonPointer) else if (PlayerPointer->PokemonArray[x] == PokemonPointer)
{ {
printf("\n%s is already with %s.\n", PokemonPointer->name, PlayerPointer->name); printf("\n%s is already with %s.\n", PokemonPointer->name, PlayerPointer->name);
...@@ -192,7 +194,13 @@ int main(void) ...@@ -192,7 +194,13 @@ int main(void)
pokedexvalues.playerhead = playerhead; pokedexvalues.playerhead = playerhead;
pokedexvalues.pokemonhead = pokemonhead; pokedexvalues.pokemonhead = pokemonhead;
//This function adds players to the pokedex
AddPlayerToList(pokedexvaluespointer, "Stephen");
AddPlayerToList(pokedexvaluespointer, "Sandra");
AddPlayerToList(pokedexvaluespointer, "Jack");
//This tests players that are already added
AddPlayerToList(pokedexvaluespointer, "Sandra");
//This adds Pokemon to the Pokedex list and sets their values //This adds Pokemon to the Pokedex list and sets their values
AddPokemonToList(pokedexvaluespointer, "Jigglypuff", "Fairy", "Cute Charm"); AddPokemonToList(pokedexvaluespointer, "Jigglypuff", "Fairy", "Cute Charm");
AddPokemonToList(pokedexvaluespointer, "Venusaur", "Grass", "Overgrow"); AddPokemonToList(pokedexvaluespointer, "Venusaur", "Grass", "Overgrow");
...@@ -209,13 +217,7 @@ int main(void) ...@@ -209,13 +217,7 @@ int main(void)
AddPokemonToList(pokedexvaluespointer, "Darkrai", "Dark", "Bad Dreams"); AddPokemonToList(pokedexvaluespointer, "Darkrai", "Dark", "Bad Dreams");
AddPokemonToList(pokedexvaluespointer, "Pikachu", "Electric", "Static"); AddPokemonToList(pokedexvaluespointer, "Pikachu", "Electric", "Static");
//This tests a Pokemon that already exists //This tests a Pokemon that already exists
AddPokemonToList(pokedexvaluespointer, "Pikachu", "Electric", "Static"); AddPokemonToList(pokedexvaluespointer, "Pikachu", "Electric", "Static");
//This function adds players to the pokedex
AddPlayerToList(pokedexvaluespointer, "Stephen");
AddPlayerToList(pokedexvaluespointer, "Sandra");
AddPlayerToList(pokedexvaluespointer, "Jack");
//This tests players that are already added
AddPlayerToList(pokedexvaluespointer, "Sandra");
//This assigns the pokemon to players //This assigns the pokemon to players
AddPokemonToPlayer(pokedexvaluespointer, "Jigglypuff", "Sandra"); AddPokemonToPlayer(pokedexvaluespointer, "Jigglypuff", "Sandra");
AddPokemonToPlayer(pokedexvaluespointer, "Bidoof", "Jack"); AddPokemonToPlayer(pokedexvaluespointer, "Bidoof", "Jack");
...@@ -237,6 +239,7 @@ int main(void) ...@@ -237,6 +239,7 @@ int main(void)
DisplayPokemonDetails(pokedexvaluespointer, "Darkrai"); DisplayPokemonDetails(pokedexvaluespointer, "Darkrai");
DisplayPokemonDetails(pokedexvaluespointer, "Dialga"); DisplayPokemonDetails(pokedexvaluespointer, "Dialga");
DisplayPokemonDetails(pokedexvaluespointer, "Gengar"); DisplayPokemonDetails(pokedexvaluespointer, "Gengar");
DisplayPokemonDetails(pokedexvaluespointer, "Bidoof");
DisplayPokemonDetails(pokedexvaluespointer, "Palkia"); DisplayPokemonDetails(pokedexvaluespointer, "Palkia");
//This displays the details of each player //This displays the details of each player
DisplayPlayerDetails(pokedexvaluespointer, "Alan"); DisplayPlayerDetails(pokedexvaluespointer, "Alan");
......
No preview for this file type
...@@ -16,6 +16,6 @@ typedef struct PlayerNode { ...@@ -16,6 +16,6 @@ typedef struct PlayerNode {
} PlayerNode; } PlayerNode;
//This sets the structure for the pokedex and gives it two headers //This sets the structure for the pokedex and gives it two headers
typedef struct Pokedex { typedef struct Pokedex {
PokemonNode *pokemonhead; PlayerNode* playerhead;
PlayerNode *playerhead; PokemonNode* pokemonhead;
} Pokedex; } 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