Commit eae2176f authored by daniel.pearson's avatar daniel.pearson

Delete main.c

parent e0aa0b6d
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Player {
char name[20];
int PokemonCount;
struct Pokemon *arr[20];
struct Player *next;
};
struct Pokemon {
char name[20];
char type[20];
char ability[20];
struct Pokemon *next;
};
struct Pokedex {
struct Player *playerHead; // Points to a player struct
// Want the playerhead to point to the new node we have made
struct Pokemon *pokemonHead;
};
struct Pokemon *NewPokemonNode(char name[20], char type[20], char ability[20]) {
struct Pokemon *newPokemon = NULL;
newPokemon = malloc(sizeof(struct Pokemon));
if (newPokemon != NULL) {
strcpy(newPokemon->name, name);
strcpy(newPokemon->type, type);
strcpy(newPokemon->ability, ability);
newPokemon->next = NULL;
}
return newPokemon;
}
void AddPokemonToList(struct Pokemon *list, char name1[20], char type1[20],
char ability1[20]) {
struct Pokemon *newPokemon = NewPokemonNode(name1, type1, ability1);
struct Pokemon *temp = list; // list = startlist1 -> playerhead
while (temp->next != NULL) { // has to be a while loop to loop through all
// nodes not just the second node
temp = temp->next;
}
if (temp->next == NULL) {
temp->next = newPokemon;
return;
}
return;
}
struct Pokemon *
FindPokemon(struct Pokemon *list,
char name[20]) { // Need this for adding pokemon to players
struct Pokemon *temp2 = list; // list = start1 -> pokemonHead
int value;
while (temp2->next != NULL) {
value = strcmp(name, temp2->name);
if (value == 0) {
// printf("\nPokemon Found %s\n", temp2->name);
// printf("\nFound Pokemon");
return temp2;
}
if (name == temp2->name) {
return temp2;
}
temp2 = temp2->next;
}
if (temp2->next == NULL) {
value = strcmp(name, temp2->name);
if (value == 0) {
// printf("\nPokemon Found2 %s\n", temp2->name);
// printf("\nFound");
return temp2;
}
}
return temp2;
}
void ListPokemon(struct Pokemon *list) {
struct Pokemon *temp = list;
printf("\nPokemon List:");
while (temp->next != NULL) {
printf("\nPokemon Name: %s", temp->name);
temp = temp->next;
}
if (temp->next == NULL) {
printf("\nPokemon Name: %s", temp->name);
return;
}
return;
}
void DisplayPokemonDetails(struct Pokemon *list) { //CHANGE THISSSSSSS
printf("\nPokemon Details:");
struct Pokemon *temp = list;
while (temp->next != NULL) {
printf("\nPokemon Name: %s", temp->name);
printf("\nPokemons Type: %s", temp->type);
printf("\nPokemons Ability: %s", temp->ability);
printf("\n");
temp = temp->next;
}
if (temp->next == NULL) {
printf("\nPokemon Name: %s", temp->name);
printf("\nPokemons Type: %s", temp->type);
printf("\nPokemons Ability: %s", temp->ability);
return;
}
return;
}
// START OF PLAYER CODE BELOW
struct Player *NewPlayerNode(char name[20]) {
struct Player *newPlayer = NULL;
newPlayer = malloc(sizeof(struct Player));
if (newPlayer != NULL) {
strcpy(newPlayer->name, name);
newPlayer->next = NULL;
}
return newPlayer;
}
void AddPlayerToList(struct Player *Playerlist, char name1[20]) {
struct Player *newPlayer = NewPlayerNode(name1);
struct Player *temp = Playerlist; // list = startlist1 -> playerhead
while (temp->next != NULL) { // has to be a while loop to loop through all
// nodes not just the second node
temp = temp->next;
}
if (temp->next == NULL) {
temp->next = newPlayer;
return;
}
return;
}
struct Player *FindPlayer(struct Player *Playerlist, char name[20]) {
struct Player *temp3 = Playerlist; // list = start1 -> pokemonHead
int value;
while (temp3->next != NULL) {
value = strcmp(name, temp3->name);
if (value == 0) {
// printf("\nFound Player");
return temp3;
}
if (name == temp3->name) {
return temp3;
}
temp3 = temp3->next;
}
if (temp3->next == NULL) {
value = strcmp(name, temp3->name);
if (value == 0) {
// printf("\nFound");
return temp3;
}
}
return temp3;
}
void ListPlayers(struct Player *Playerlist) {
printf("\n\nPlayer List:");
struct Player *temp = Playerlist;
while (temp->next != NULL) {
printf("\nPlayer Name: %s", temp->name);
temp = temp->next;
}
if (temp->next == NULL) {
printf("\nPlayer Name: %s", temp->name);
return;
}
return;
}
void AddPokemonToPlayer(struct Pokemon *list, struct Player *PlayerList,
char PlayerName[20], char PokemonName[20]) {
struct Pokemon *pokemon = FindPokemon(list, PokemonName);
struct Player *player = FindPlayer(PlayerList, PlayerName);
player->PokemonCount += 1;
// printf("\nPlayer Find Name %s\n", player->name);
for (int a = 0; a < 20; a = a + 1) {
if (player->arr[a] == NULL) {
player->arr[a] = pokemon;
break;
} else if (player->arr[a] != NULL) {
player->arr[a + 1] = pokemon;
break;
}
};
}
void DisplayPlayerDetails(struct Player *list, char PlayerName[20]) {
struct Player *player = FindPlayer(list, PlayerName);
struct Pokemon *pokemon;
printf("\n\n%s Pokemon Are:\n", player->name);
for (int i = 0; i < 20; ++i) {
pokemon = player->arr[i];
if (pokemon != NULL) {
printf("%s\n", pokemon->name);
} else {
continue;
}
// printf("\n%s Pokemon Are:", player->name);
// printf("\nPokemon %s\n", pokemon->name);
// printf("\nPokemon Name Added %s\n", pokemon->name);
}
}
int main() {
struct Pokedex *start1 = NULL; // start player list at this address
struct Pokemon *Pikachu = NULL;
Pikachu = malloc(sizeof(struct Pokemon));
if (Pikachu != NULL) {
strcpy(Pikachu->name, "Pikachu");
strcpy(Pikachu->type, "Grass");
strcpy(Pikachu->ability, "Lightning");
Pikachu->next = NULL;
}
// new_node.subject,subject takes subject from the parameters
struct Pokemon *startPokemonList = start1->pokemonHead;
startPokemonList = NULL;
if (startPokemonList == NULL) {
startPokemonList = Pikachu;
}
// FindPokemon(start1, "Charizard");
// START PLAYER MAIN CODE BELOW
struct Player *Ash = NULL;
Ash = malloc(sizeof(struct Player));
if (Ash != NULL) {
strcpy(Ash->name, "Ash");
Ash->next = NULL;
}
// new_node.subject,subject takes subject from the parameters
struct Player *startPlayerList = start1->playerHead;
startPlayerList = NULL;
if (startPlayerList == NULL) {
startPlayerList = Ash;
}
AddPokemonToList(startPokemonList, "Charizard", "Air", "Fire");
AddPokemonToList(startPokemonList, "Benny", "Air", "Fire");
FindPokemon(startPokemonList, "Benny");
ListPokemon(startPokemonList);
printf("\n");
DisplayPokemonDetails(startPokemonList);
AddPlayerToList(startPlayerList, "Jeano");
FindPlayer(startPlayerList, "Ash");
ListPlayers(startPlayerList);
AddPokemonToPlayer(startPokemonList, startPlayerList, "Ash", "Charizard");
AddPokemonToPlayer(startPokemonList, startPlayerList, "Ash", "Pikachu");
DisplayPlayerDetails(startPlayerList, "Ash");
// FindPokemon(startPokemonList,"Pikachu");
return 0;
}
\ 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