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

update

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