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

reorganisation

parent 0dbf6af5
// Calling of functions and setting up nodes
#include "functions.h"
int main(void)
{ // Adding Pokemon to list
Pokedex* pokeHead = NewPokemonNode("blastoise", "water", "torrent"); //Creation of node to introduce head of single linked list
AddPokemonToList(pokeHead, "dragapult", "dragon", "infiltrator");
AddPokemonToList(pokeHead, "volcarona", "fire", "flame body");
AddPokemonToList(pokeHead, "regieleki", "electric", "transistor");
// Adding player to player list
Pokedex* playerHead = NewPlayerNode("armin");
AddPlayerToList(playerHead, "chase");
AddPlayerToList(playerHead, "ziggy");
// Adding pokemon to player
AddPokemonToPlayer(pokeHead, playerHead, "armin", "blastoise");
AddPokemonToPlayer(pokeHead, playerHead, "armin", "dragapult");
AddPokemonToPlayer(pokeHead, playerHead, "chase", "dragapult");
AddPokemonToPlayer(pokeHead, playerHead, "chase", "regieleki");
AddPokemonToPlayer(pokeHead, playerHead, "chase", "volcarona");
AddPokemonToPlayer(pokeHead, playerHead, "ziggy", "regieleki");
// To display all of both pokemon and players
ListPokemon(pokeHead);
ListPlayers(playerHead);
// Display details of each player
DisplayPlayerDetails(playerHead, "armin");
DisplayPlayerDetails(playerHead, "chase");
DisplayPlayerDetails(playerHead, "ziggy");
// Details of each pokemon
DisplayPokemonDetails(pokeHead, "blastoise");
DisplayPokemonDetails(pokeHead, "dragapult");
DisplayPokemonDetails(pokeHead, "volcarona");
DisplayPokemonDetails(pokeHead, "regieleki");
return 0;
}
// Structs and functions placed here
// Pokemon List
typedef struct PokemonNode
{
char name[12];
char type[20];
char ability[25];
char name[100];
char type[100];
char ability[100];
struct PokemonNode *next;
} PokemonNode;
// Player List
typedef struct PlayerNode
{
char name[25];
char name[100];
int totalPokemon;
PokemonNode* PokemonArray[20];
PokemonNode* PokemonArray[100]; //Array of players
struct PlayerNode *next;
} PlayerNode;
// Pokedex structure
typedef struct Pokedex
{
PokemonNode *pokemonNodehead;
PlayerNode *PlayerNodehead;
PokemonNode *pokeHead;
PlayerNode *playerHead;
} Pokedex;
// Pokemon List functions
PokemonNode* NewPokemonNode(Pokedex* pokedex, char name[25], char type[25], char ability[30]);
void AddPokemonToList(Pokedex** pokedex, char name[25], char type[25], char ability[30]);
PokemonNode* FindPokemon(Pokedex* pokedex, char name[25]);
PokemonNode* NewPokemonNode(char name[100], char type[100], char ability[100]);
void AddPokemonToList(Pokedex* funct, char name[100], char type[100], char ability[100]);
PokemonNode* FindPokemon(Pokedex* funct, char name[100]);
// Player List functions
PlayerNode* NewPlayerNode(char name[50]); // Create new node, return pointer to node
void AddPlayerToList(Pokedex* pokedex, char name[50]); // Check if name already exists in Player list.
PlayerNode* FindPlayer(Pokedex* pokedex, char name[50]); // Searches Player list for name.
// Additional functions
void AddPokemonToPlayer(Pokedex* pokedex, char playerName[50], char pokemonName[20]); // Adds Pokemon to player's Pokemon list
void DisplayPokemonDetails(Pokedex* pokedex, char name[20]); // Output details of pokemon
void DisplayPlayerDetails(Pokedex* pokedex, char name[20]); // output details of players, incl. list of names of pokemon owned
void ListPokemon(Pokedex* pokedex); //output list of names of all POKEMON in pokedex
void ListPlayers(Pokedex* pokedex); //output list of names of all PLAYERS in pokedex
void AddToPokemonArray(Pokedex* pokedex, char namePoke[20], char namePlayer[50]);
PlayerNode* NewPlayerNode(char name[100]); // Create new node, return pointer to node
void AddPlayerToList(Pokedex* funct, char name[100]); // Check if name already exists in Player list.
PlayerNode* FindPlayer(Pokedex* funct, char name[100]); // Searches Player list for name.
void AddPokemonToPlayer(Pokedex* funct, Pokedex* funct2, char playerName[100], char pokemonName[100]); // Adds Pokemon to player's Pokemon list
// Additional functions for the pokedex
// Pokemon details functs
void DisplayPokemonDetails(Pokedex* funct, char name[100]); // Output details of pokemon
PokemonNode* ListPokemon(Pokedex* funct); //output list of names of all POKEMON in pokedex
// Pokemon players functs
void DisplayPlayerDetails(Pokedex* funct, char name[100]); // output details of players, incl. list of names of pokemon owned
PlayerNode * ListPlayers(Pokedex* funct); //output list of names of all PLAYERS in pokedex
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "functions.h"
int main(void)
{
Pokedex *pokedex = NULL;
pokedex = malloc(sizeof(pokedex));
pokedex -> pokemonNodehead = NULL;
pokedex -> PlayerNodehead = NULL;
// Adding Pokemon to list
AddPokemonToList(&pokedex, "blastoise", "water", "torrent");
AddPokemonToList(&pokedex, "dragapult", "dragon", "infiltrator");
AddPokemonToList(&pokedex, "volcarona", "fire", "flame body");
AddPokemonToList(&pokedex, "regieleki", "electric", "transistor");
// Adding player to player list
AddPlayerToList(&pokedex, "armin");
AddPlayerToList(&pokedex, "chase");
AddPlayerToList(&pokedex, "ziggy");
// Adding pokemon to player
AddPokemonToPlayer(pokedex, "armin", "blastoise");
AddPokemonToPlayer(pokedex, "armin", "dragapult");
AddPokemonToPlayer(pokedex, "chase", "dragapult");
AddPokemonToPlayer(pokedex, "chase", "regieleki");
AddPokemonToPlayer(pokedex, "chase", "volcarona");
AddPokemonToPlayer(pokedex, "ziggy", "regieleki");
ListPokemon(pokedex);
ListPlayers(pokedex);
return 0;
}
// Main: setting up nodes and printing
#include "functioncall.c"
har name[20]);
void DisplayPlayerDetails(Pokedex *pokedex, ch
\ No newline at end of file
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