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 // Pokemon List
typedef struct PokemonNode typedef struct PokemonNode
{ {
char name[12]; char name[100];
char type[20]; char type[100];
char ability[25]; char ability[100];
struct PokemonNode *next; struct PokemonNode *next;
} PokemonNode; } PokemonNode;
// Player List // Player List
typedef struct PlayerNode typedef struct PlayerNode
{ {
char name[25]; char name[100];
int totalPokemon; int totalPokemon;
PokemonNode* PokemonArray[20]; PokemonNode* PokemonArray[100]; //Array of players
struct PlayerNode *next; struct PlayerNode *next;
} PlayerNode; } PlayerNode;
// Pokedex structure // Pokedex structure
typedef struct Pokedex typedef struct Pokedex
{ {
PokemonNode *pokemonNodehead; PokemonNode *pokeHead;
PlayerNode *PlayerNodehead; PlayerNode *playerHead;
} Pokedex; } Pokedex;
// Pokemon List functions // Pokemon List functions
PokemonNode* NewPokemonNode(Pokedex* pokedex, char name[25], char type[25], char ability[30]); PokemonNode* NewPokemonNode(char name[100], char type[100], char ability[100]);
void AddPokemonToList(Pokedex** pokedex, char name[25], char type[25], char ability[30]); void AddPokemonToList(Pokedex* funct, char name[100], char type[100], char ability[100]);
PokemonNode* FindPokemon(Pokedex* pokedex, char name[25]); PokemonNode* FindPokemon(Pokedex* funct, char name[100]);
// Player List functions // Player List functions
PlayerNode* NewPlayerNode(char name[50]); // Create new node, return pointer to node PlayerNode* NewPlayerNode(char name[100]); // Create new node, return pointer to node
void AddPlayerToList(Pokedex* pokedex, char name[50]); // Check if name already exists in Player list. void AddPlayerToList(Pokedex* funct, char name[100]); // Check if name already exists in Player list.
PlayerNode* FindPlayer(Pokedex* pokedex, char name[50]); // Searches Player list for name. 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 // Additional functions for the pokedex
void AddPokemonToPlayer(Pokedex* pokedex, char playerName[50], char pokemonName[20]); // Adds Pokemon to player's Pokemon list // Pokemon details functs
void DisplayPokemonDetails(Pokedex* pokedex, char name[20]); // Output details of pokemon void DisplayPokemonDetails(Pokedex* funct, char name[100]); // Output details of pokemon
void DisplayPlayerDetails(Pokedex* pokedex, char name[20]); // output details of players, incl. list of names of pokemon owned PokemonNode* ListPokemon(Pokedex* funct); //output list of names of all POKEMON in pokedex
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 // Pokemon players functs
void AddToPokemonArray(Pokedex* pokedex, char namePoke[20], char namePlayer[50]); 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> // Main: setting up nodes and printing
#include <stdlib.h> #include "functioncall.c"
#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;
}
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