Commit fa0916c0 authored by suleman.hussain's avatar suleman.hussain

finish(i think)

parent e73bb7bf
void AddPokemonToList(struct Pokedex *pokemon, char name[16], char type[12], char ability[12]){
// Theses are all the functions or subprograms needed for main.c
// Adds Pokemon_To_List
void Pokemon_To_list(struct Pokedex *pokemon, char name[16], char type[12], char ability[12]){
struct PokemonNode *current = (struct PokemonNode *) pokemon -> pokemon_head;
while (current != NULL){
if (strcmp(current -> name, name) == 0){
......@@ -15,7 +19,8 @@ void AddPokemonToList(struct Pokedex *pokemon, char name[16], char type[12], cha
}
}
void AddPlayerToList(struct Pokedex *player, char name[16])
// Adds Player to list
void Player_To_List(struct Pokedex *player, char name[16])
{
struct PlayerNode *current = (struct PlayerNode *)player->player_head;
while (current != NULL)
......@@ -36,7 +41,8 @@ void AddPlayerToList(struct Pokedex *player, char name[16])
}
}
void AddPokemonToPlayer(struct Pokedex *pokedex, char playerName[16], char pokemonName[16], char pokemonType[12], char pokemonAbility[12]){
// Adds a pokemon to player
void Pokemon_To_Player(struct Pokedex *pokedex, char playerName[16], char pokemonName[16], char pokemonType[12], char pokemonAbility[12]){
struct PlayerNode *currentPlayer = (struct PlayerNode *) pokedex -> player_head;
while(currentPlayer != NULL && strcmp(currentPlayer -> name, playerName) !=0){
currentPlayer = currentPlayer -> next;
......@@ -64,7 +70,8 @@ void AddPokemonToPlayer(struct Pokedex *pokedex, char playerName[16], char pokem
printf("Successfully added %s to %s's Pokemon list\n", pokemonName, playerName);
}
void DisplayPokemonDetails(struct Pokedex *pokedex, char name[12]){
// Displays the infomation of a pokemon
void Pokemon_Info(struct Pokedex *pokedex, char name[12]){
struct PokemonNode *current = (struct PokemonNode *) pokedex -> pokemon_head;
while(current != NULL){
if(strcmp(current -> name, name) == 0){
......@@ -78,7 +85,8 @@ void DisplayPokemonDetails(struct Pokedex *pokedex, char name[12]){
printf("Sorry! I don't seem to have any record of this Pokemon.\n");
}
void DisplayPlayerDetails(struct Pokedex *pokedex, char name[12]){
// Displays the count of a given player
void Player_count(struct Pokedex *pokedex, char name[12]){
struct PlayerNode *current = (struct PlayerNode *) pokedex -> player_head;
......@@ -99,7 +107,8 @@ void DisplayPlayerDetails(struct Pokedex *pokedex, char name[12]){
}
void ListPokemon(struct Pokedex *pokedex)
// Lists all pokemen in the pokedex
void List_Pokemen(struct Pokedex *pokedex)
{
struct PokemonNode *current = (struct PokemonNode *)pokedex->pokemon_head;
while (current != NULL)
......@@ -122,7 +131,8 @@ void ListPokemon(struct Pokedex *pokedex)
}
}
void ListPlayers(struct Pokedex *pokedex){
// Lists all players in the pokedex
void List_Players(struct Pokedex *pokedex){
struct PlayerNode *current = (struct PlayerNode*) pokedex -> player_head;
while (current != NULL){
if(current == NULL){
......
// Node for pokemon
struct PokemonNode{
char name[16];
char type[12];
......@@ -5,6 +6,7 @@ struct PokemonNode{
struct PokemonNode *next;
};
// Node for player
struct PlayerNode{
char name[16];
int pokemonCount;
......@@ -17,6 +19,7 @@ struct Pokedex {
struct PokemonNode *pokemon_head;
};
struct PokemonNode* NewPokemonNode(char name[16], char type[12], char ability[12]){
struct PokemonNode *newNode = (struct PokemonNode *) malloc(sizeof(struct PokemonNode));
strcpy(newNode -> name, name);
......
No preview for this file type
......@@ -3,6 +3,7 @@
#include <string.h>
#include <stdbool.h>
//Calls theses programs to be used later
#include "linklist.c"
#include "functions.c"
......@@ -11,22 +12,13 @@ int main(){
pokedex.pokemon_head = NULL;
pokedex.player_head = NULL;
AddPokemonToList(&pokedex,"bob","human","cry");
AddPokemonToList(&pokedex,"suleman","sad","sobbing");
AddPlayerToList(&pokedex,"jim");
AddPokemonToPlayer(&pokedex,"jim","bob","human","cry");
AddPokemonToPlayer(&pokedex,"jim","suleman","sad","sobbing");
bool run = true;
while (run=true){
int user_input;
printf("Please select an option: \n1) Add a Pokemon to the pokedex\n2) List pokemon\n3) Pokemon detail \n4) Add player \n5) List Players \n6) Add Pokemon to player \n7) Player details\n8) Quit\n");
scanf("%d",&user_input);
// Adds pokemon to pokedex
if (user_input==1){
printf("Add pokemon\n");
......@@ -43,27 +35,30 @@ int main(){
printf("Ability of pokemon\n");
scanf("%s",&ability);
AddPokemonToList(&pokedex, name ,type ,ability);
Pokemon_To_list(&pokedex, name ,type ,ability);
}
// List all Pokemen
else if(user_input==2){
printf("\n");
printf("All pokemons in pokedex\n");
ListPokemon(&pokedex);
List_Pokemen(&pokedex);
printf("\n");
}
// Displays information about given pokemon
else if(user_input==3){
char pokemon_name[12];
printf("\n");
printf("Enter pokemon name: ");
scanf("%s",&pokemon_name);
printf("\n");
DisplayPokemonDetails(&pokedex,pokemon_name);
Pokemon_Info(&pokedex,pokemon_name);
printf("\n");
}
// Adds given player to pokedex
else if(user_input==4){
printf("\n");
......@@ -71,17 +66,19 @@ int main(){
printf("Enter username: ");
scanf("%s",username);
AddPlayerToList(&pokedex,username);
Player_To_List(&pokedex,username);
}
// Lists all players
else if(user_input==5){
printf("\n");
printf("All Players:\n");
ListPlayers(&pokedex);
List_Players(&pokedex);
printf("\n");
}
// Adds given pokemon to given player
else if(user_input==6){
char player_name_in[16];
char poke_name[16];
......@@ -99,31 +96,33 @@ int main(){
printf("Enter pokemon ability: ");
scanf("%s",&poke_Ability);
AddPokemonToPlayer(&pokedex,player_name_in,poke_name,poke_Type,poke_Ability);
Pokemon_To_Player(&pokedex,player_name_in,poke_name,poke_Type,poke_Ability);
}
// Shows how many a given player has
else if(user_input==7){
printf("\n");
printf("Enter player name: ");
char player_name[12];
scanf("%s",&player_name);
DisplayPlayerDetails(&pokedex,player_name);
Player_count(&pokedex,player_name);
}
//quits
//ends the program
else if(user_input==8){
break;
}
// check if number is applicable
else{
printf("else\n");
}
}
printf("done!\n");
return 0;
}
......
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