Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Pokedex Resit Code
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bryan.quispe
Pokedex Resit Code
Commits
e11086e4
Commit
e11086e4
authored
Apr 06, 2023
by
bryan.quispe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new file
parents
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
0 deletions
+89
-0
Pokedex Resit Code
Pokedex Resit Code
+89
-0
No files found.
Pokedex Resit Code
0 → 100644
View file @
e11086e4
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Create a structure to hold data on Pokemon.
typedef struct PokemonNode {
char name[20];
char ability[20];
struct PokemonNode *next;
struct PokemonNode *prev;
} Pokemon;
// Create a structure to hold a player's data.
typedef struct PlayerNode {
char name[20];
int pokemonCount;
Pokemon *ownedPokemon[100];
struct PlayerNode *next;
struct PlayerNode *prev;
} Player;
// Establish a structure to hold the Pokedex.
typedef struct {
Pokemon *headPokemon;
Player *headPlayer;
} Pokedex;
// Build a Pokedex.
Pokedex pokedex = { NULL, NULL };
// Create a new Pokemon node with this function.
Pokemon *createPokemonNode(const char *name, const char *ability) {
Pokemon *newNode = malloc(sizeof(Pokemon));
strcpy(newNode->name, name);
strcpy(newNode->ability, ability);
newNode->next = NULL;
newNode->prev = NULL;
return newNode;
}
// Add a new Pokemon to the list feature
void addPokemonToList(Pokemon *newNode) {
if (pokedex.headPokemon == NULL) {
pokedex.headPokemon = newNode;
} else {
Pokemon *current = pokedex.headPokemon;
while (current->next != NULL) {
current = current->next;
}
current->next = newNode;
newNode->prev = current;
}
}
// Ability to look up a Pokemon using its name
Pokemon *searchPokemonByName(const char *name) {
Pokemon *current = pokedex.headPokemon;
while (current != NULL) {
if (strcmp(current->name, name) == 0) {
return current;
}
current = current->next;
}
return NULL;
}
//Create a new Player node function
Player *createPlayerNode(const char *name) {
Player *newNode = malloc(sizeof(Player));
strcpy(newNode->name, name);
newNode->pokemonCount = 0;
newNode->next = NULL;
newNode->prev = NULL;
return newNode;
}
// Adding a new player to the list function
void addPlayerToList(Player *newNode) {
if (pokedex.headPlayer == NULL) {
pokedex.headPlayer = newNode;
} else {
Player *current = pokedex.headPlayer;
while (current->next != NULL) {
current = current->next;
}
current->next = newNode;
newNode->prev = current;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment