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

fgsf

parents
{
"configurations": [
{
"name": "C/C++: gcc build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
],
"version": "2.0.0"
}
\ No newline at end of file
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
\ No newline at end of file
void AddPokemonToList(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){
printf("Sorry! This Pokemon seems to already be in our Pokedex.\n");
return;
}
current = current -> next;
}
if (current == NULL){
struct PokemonNode* newNode = NewPokemonNode(name, type, ability);
newNode -> next = pokemon -> pokemon_head;
pokemon -> pokemon_head = newNode;
printf("Your Pokemon has successfully been added to the Pokedex!\n");
}
}
void AddPlayerToList(struct Pokedex *player, char name[16])
{
struct PlayerNode *current = (struct PlayerNode *)player->player_head;
while (current != NULL)
{
if (strcmp(current->name, name) == 0)
{
printf("Sorry! This player seems to already be in our Pokedex.\n");
return;
}
current = current->next;
}
if (current == NULL)
{
struct PlayerNode *newNode = NewPlayerNode(name, 0);
newNode->next = player->player_head;
player->player_head = newNode;
printf("Your player has successfully been added to the Pokedex!\n");
}
}
void AddPokemonToPlayer(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;
}
if(currentPlayer == NULL){
printf("Sorry! I don't think I recognise that player.\n");
return;
}
struct PokemonNode *currentPokemon = (struct PokemonNode *)currentPlayer -> pokemon_head;
if(currentPokemon == NULL){
while (currentPokemon != NULL){
if(strcmp(currentPokemon-> name, pokemonName) == 0){
printf("Sorry! It seems that this player already owns this Pokemon. Perhaps you meant a different Pokemon?\n");
return;
}
currentPokemon = currentPokemon -> next;
}
}
struct PokemonNode *newNode = NewPokemonNode(pokemonName, pokemonType, pokemonAbility);
newNode -> next = currentPlayer -> pokemon_head;
currentPlayer -> pokemon_head = newNode;
int pokemonCount = currentPlayer->pokemonCount;
currentPlayer -> pokemonCount++;
printf("Successfully added %s to %s's Pokemon list\n", pokemonName, playerName);
}
void DisplayPokemonDetails(struct Pokedex *pokedex, char name[12]){
struct PokemonNode *current = (struct PokemonNode *) pokedex -> pokemon_head;
while(current != NULL){
if(strcmp(current -> name, name) == 0){
printf("Pokemon Name: %s\n", current -> name);
printf("Pokemon Type: %s\n", current -> type);
printf("Pokemon Ability: %s\n", current -> ability);
return;
}
current = current -> next;
}
printf("Sorry! I don't seem to have any record of this Pokemon.\n");
}
void DisplayPlayerDetails(struct Pokedex *pokedex, char name[12]){
struct PlayerNode *current = (struct PlayerNode *) pokedex -> player_head;
while(current != NULL){
if(strcmp(current -> name, name) == 0){
printf("Player Name: %s\n", current -> name);
printf("Player Pokemon Count: %i\n", current -> pokemonCount);
return;
}
current = current -> next;
}
if(current == NULL){
printf("Sorry! I don't seem to have any record of that person.\n");
}
}
void ListPokemon(struct Pokedex *pokedex)
{
struct PokemonNode *current = (struct PokemonNode *)pokedex->pokemon_head;
while (current != NULL)
{
if (current == NULL)
{
return;
}
printf("name: ");
printf("%s\n", current->name);
printf("Type: ");
printf("%s\n",current->type);
printf("Ability: ");
printf("%s\n", current->ability);
printf("\n");
current = current->next;
}
}
void ListPlayers(struct Pokedex *pokedex){
struct PlayerNode *current = (struct PlayerNode*) pokedex -> player_head;
while (current != NULL){
if(current == NULL){
return;
}
printf("%s\n", current -> name);
current = current -> next;
}
}
struct Pokedex {
struct PlayerNode *player_head;
struct PokemonNode *pokemon_head;
};
struct PokemonNode{
char name[16];
char type[12];
char ability[12];
struct PokemonNode *next;
};
struct PlayerNode{
char name[16];
int pokemonCount;
struct PokemonNode *pokemon_head;
struct PlayerNode *next;
};
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);
strcpy(newNode -> type, type);
strcpy(newNode -> ability, ability);
newNode -> next = NULL;
return newNode;
}
struct PokemonNode* FindPokemon(struct Pokedex *pokedex, char name[16]){
struct PokemonNode *current = (struct PokemonNode *) pokedex -> pokemon_head;
while(current != NULL){
if (strcmp(current -> name, name) == 0){
return current;
}
current = current -> next;
}
printf("Sorry, I cant seem to find that pokemon. Perhaps it is still yet to be discovered?\n");
return NULL;
}
struct PlayerNode* NewPlayerNode(char name[16], int pokemonCount){
struct PlayerNode *newNode = (struct PlayerNode *) malloc(sizeof(struct PlayerNode));
strcpy(newNode -> name, name);
newNode -> pokemonCount = pokemonCount;
newNode -> next = NULL;
return newNode;
}
struct PlayerNode* FindPlayer(struct Pokedex *pokedex, char name[16]){
struct PlayerNode *current = (struct PlayerNode *) pokedex -> player_head;
while(current != NULL){
if (strcmp(current -> name, name) == 0){
return current;
}
current = current -> next;
}
printf("Sorry, I cant seem to find that person.\n");
return NULL;
}
File added
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "linklist.c"
#include "functions.c"
int main(){
struct Pokedex pokedex;
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);
if (user_input==1){
printf("Add pokemon\n");
char name[16];
char type[12];
char ability[12];
printf("Name of pokemon\n");
scanf("%s",&name);
printf("Type of pokemon\n");
scanf("%s",&type);
printf("Ability of pokemon\n");
scanf("%s",&ability);
AddPokemonToList(&pokedex, name ,type ,ability);
}
else if(user_input==2){
printf("\n");
printf("All pokemons in pokedex\n");
ListPokemon(&pokedex);
printf("\n");
}
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);
printf("\n");
}
else if(user_input==4){
printf("\n");
char username[16];
printf("Enter username: ");
scanf("%s",username);
AddPlayerToList(&pokedex,username);
}
else if(user_input==5){
printf("\n");
printf("All Players:\n");
ListPlayers(&pokedex);
printf("\n");
}
else if(user_input==6){
char player_name_in[16];
char poke_name[16];
char poke_Type[12];
char poke_Ability[12];
printf("Enter player name: ");
scanf("%s",&player_name_in);
printf("Enter pokemon name: ");
scanf("%s",&poke_name);
printf("Enter pokemon type: ");
scanf("%s",&poke_Type);
printf("Enter pokemon ability: ");
scanf("%s",&poke_Ability);
AddPokemonToPlayer(&pokedex,player_name_in,poke_name,poke_Type,poke_Ability);
}
else if(user_input==7){
printf("\n");
printf("Enter player name: ");
char player_name[12];
scanf("%s",&player_name);
DisplayPlayerDetails(&pokedex,player_name);
}
//quits
else if(user_input==8){
break;
}
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