Commit 4ef7e6c8 authored by austin.blanke's avatar austin.blanke

Initial commit

parents
File added
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "pokedexStructs.h"
#include "pokedexFunctions.h"
int main(void) {
Pokedex pokedex;
pokedex.pokemonHead = NULL;
pokedex.playerHead = NULL;
AddPokemonToList(&pokedex, "Tepig", "Fire", "Tackle");
AddPokemonToList(&pokedex, "Oshawott", "Water", "Tackle");
AddPokemonToList(&pokedex, "Snivy", "Grass", "Screen");
AddPlayerToList(&pokedex,"Austin");
AddPlayerToList(&pokedex,"Ashe");
AddPlayerToList(&pokedex,"Joey");
AddPlayerToList(&pokedex,"Pranav");
ListPlayers(pokedex);
ListPokemon(pokedex);
AddPokemonToPlayer(pokedex, "Austin", "Tepig");
DisplayPokemonDetails(pokedex, "Tepig");
DisplayPlayerDetails(pokedex,"Austin");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "pokedexStructs.h"
#include "pokedexFunctions.h"
//NewPokemonNode Function
struct PokemonNode *NewPokemonNode(char name[], char type[], char ability[] ) {
struct PokemonNode *newNode = NULL;
newNode = malloc(sizeof(struct PokemonNode));
if (newNode != NULL) {
strcpy(newNode->name,name);
strcpy(newNode->type,type);
strcpy(newNode->ability,ability);
newNode->next = NULL;
}
return newNode;
}
//FindPokemon Function
struct PokemonNode * FindPokemon(struct Pokedex pokedex, char name[]) {
PokemonNode *current = pokedex.pokemonHead;
while (current != NULL) {
if (strcmp(current->name,name) == 0) {
return current;
}
current = current->next;
}
return NULL;
}
void AddPokemonToList(Pokedex *pokedex,char name[],char type[],char ability[]){
PokemonNode *newNode = NewPokemonNode(name, type, ability);
PokemonNode *current = pokedex->pokemonHead;
if(pokedex->pokemonHead == NULL){
pokedex->pokemonHead = newNode;
newNode->next = NULL;
return;
}
while (current != NULL){
if(strcmp(current->name, name) == 0){
return;
}
if(current->next == NULL){
current->next = newNode;
newNode->next = NULL;
return;
}
current = current->next;
}
}
//NewPlayerNode Function
struct PlayerNode *NewPlayerNode(char name[]) {
PlayerNode *newNode = NULL;
newNode = malloc(sizeof(struct PlayerNode));
if (newNode != NULL) {
strcpy(newNode->name,name);
newNode->next = NULL;
}
return newNode;
}
//FindPlayer Function
struct PlayerNode *FindPlayer(Pokedex pokedex,char name[]) {
PlayerNode *current = pokedex.playerHead;
while (current != NULL) {
if (strcmp(current->name,name) == 0) {
return current;
}
current = current->next;
}
return NULL;
}
//AddPlayerToList Function
void AddPlayerToList(Pokedex *pokedex,char name[]){
PlayerNode *newNode = NewPlayerNode(name);
PlayerNode *current = pokedex->playerHead;
if(pokedex->playerHead == NULL){
pokedex->playerHead = newNode;
newNode->next = NULL;
return;
}
while (current != NULL){
if(strcmp(current->name, name) == 0){
return;
}
if(current->next == NULL){
current->next = newNode;
newNode->next = NULL;
return;
}
current = current->next;
}
}
//AddPokemonToPlayer Function
void AddPokemonToPlayer(Pokedex pokedex, char playerName[], char pokemonName[]) {
PlayerNode *player = FindPlayer(pokedex,playerName);
PokemonNode *pokemon = FindPokemon(pokedex,pokemonName);
if (player == NULL || pokemon == NULL) {
return;
}
for (int i = 0; i < (player->pokemonCount) + 1; i++) {
if (player->pokemonArray[i] == pokemon){
return;
}
}
player->pokemonArray[player->pokemonCount] = pokemon;
player->pokemonCount++;
}
//ListPokemon function
void ListPokemon(Pokedex pokedex) {
PokemonNode *current = pokedex.pokemonHead;
while (current != NULL) {
printf("Pokemon Name: %s\n",current->name);
current = current->next;
}
}
//ListPlayers function
void ListPlayers (Pokedex pokedex) {
PlayerNode *current = pokedex.playerHead;
while (current != NULL) {
printf("Player Name: %s\n",current->name);
current = current->next;
}
}
//DisplayPokemonDetails Function
void DisplayPokemonDetails(Pokedex pokedex, char name[]) {
PokemonNode *pokemon = FindPokemon(pokedex, name);
printf("Name: %s\n" "\tType: %s\n" "\tAbility: %s\n",pokemon->name,pokemon->type,pokemon->ability);
}
//DisplayPlayerDetails Function
void DisplayPlayerDetails(struct Pokedex pokedex, char name[]) {
PlayerNode *player = FindPlayer(pokedex,name);
printf("Name: %s\n" "\tPokemon Count: %i\n" "\tPokemon Owned: ",player->name,player->pokemonCount);
for (int i = 0 ; i < player->pokemonCount ; i++) {
printf("\t\t%s,",player->pokemonArray[i]->name);
}
}
\ No newline at end of file
#include "pokedexStructs.h"
#ifndef _POKEDEXFUNCTIONS_H
#define _POKEDEXFUNCTIONS_H
//Required Functions for Pokemon List
struct PokemonNode * NewPokemonNode(char name[], char type[], char ability[] );
void AddPokemonToList(Pokedex *pokedex,char name[],char type[],char ability[]);
struct PokemonNode * FindPokemon(struct Pokedex pokedex, char name[]);
//Required Functions for Player List
struct PlayerNode * NewPlayerNode(char name[]);
void AddPlayerToList(Pokedex *pokedex,char name[]);
struct PlayerNode * FindPlayer(struct Pokedex pokedex, char name[]);
void AddPokemonToPlayer(struct Pokedex pokedex, char playerName[], char pokemonName[]);
//Required Functions for Pokedex
void DisplayPokemonDetails(struct Pokedex pokedex, char name[]);
void DisplayPlayerDetails(struct Pokedex pokedex, char name[]);
void ListPokemon(struct Pokedex pokedex);
void ListPlayers(struct Pokedex pokedex);
#endif
\ No newline at end of file
#ifndef _POKEDEXSTRUCTS_H
#define _POKEDEXSTRUCTS_H
typedef struct Pokedex {
struct PokemonNode * pokemonHead;
struct PlayerNode * playerHead;
}Pokedex;
typedef struct PokemonNode {
char name[30];
char type[20];
char ability[50];
struct PokemonNode *next;
}PokemonNode;
typedef struct PlayerNode {
char name[30];
int pokemonCount;
struct PokemonNode * pokemonArray[20];
struct PlayerNode *next;
}PlayerNode;
#endif
\ 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