Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Pokedex
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
sam.pople
Pokedex
Commits
4e382470
Commit
4e382470
authored
Feb 06, 2023
by
sam.pople
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
8a433112
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
18 deletions
+21
-18
mainpokedex.c
mainpokedex.c
+19
-16
mainpokedex.exe
mainpokedex.exe
+0
-0
pokedexstructs.h
pokedexstructs.h
+2
-2
No files found.
mainpokedex.c
View file @
4e382470
...
@@ -2,13 +2,13 @@
...
@@ -2,13 +2,13 @@
# include <stdlib.h>
# include <stdlib.h>
# include <string.h>
# include <string.h>
# include "pokedexstructs.h"
# include "pokedexstructs.h"
//main file. Run from here.
//main file. Run from here.
Click Run Code on VSC to run.
//functions
//functions
void
ListPokemon
(
Pokedex
*
pokedexpointer
)
void
ListPokemon
(
Pokedex
*
pokedexpointer
)
{
{
// This displays the list of pokemon.
// This displays the list of pokemon.
//This assigns a node to be a head for the pokemon list
//This assigns a node to be a head for the pokemon list
PokemonNode
*
current
=
pokedexpointer
->
pokemonhead
;
PokemonNode
*
current
=
pokedexpointer
->
pokemonhead
;
printf
(
"
\n
List of Pokemon:
\n
"
);
printf
(
"
\n
List of Pokemon:
\n
"
);
while
(
current
!=
NULL
)
while
(
current
!=
NULL
)
{
//The current node is printed and then the next is assigned.
{
//The current node is printed and then the next is assigned.
...
@@ -39,7 +39,6 @@ PokemonNode* NewPokemonNode(char pokename[20], char poketype[20], char pokeabili
...
@@ -39,7 +39,6 @@ PokemonNode* NewPokemonNode(char pokename[20], char poketype[20], char pokeabili
strcpy
(
addnode
->
name
,
pokename
);
strcpy
(
addnode
->
name
,
pokename
);
strcpy
(
addnode
->
type
,
poketype
);
strcpy
(
addnode
->
type
,
poketype
);
strcpy
(
addnode
->
ability
,
pokeability
);
strcpy
(
addnode
->
ability
,
pokeability
);
return
addnode
;
return
addnode
;
}
}
//This creates each Player node
//This creates each Player node
...
@@ -54,9 +53,8 @@ PlayerNode *NewPlayerNode(char playername[20])
...
@@ -54,9 +53,8 @@ PlayerNode *NewPlayerNode(char playername[20])
return
addnode
;
return
addnode
;
}
}
//This finds the Pokemon in the Pokemon list
//This finds the Pokemon in the Pokemon list
PokemonNode
*
FindPokemon
(
PokemonNode
*
pokehead
,
char
pokename
[
20
])
PokemonNode
*
FindPokemon
(
PokemonNode
*
pokehead
,
char
pokename
[
20
])
{
{
PokemonNode
*
current
=
pokehead
;
PokemonNode
*
current
=
pokehead
;
while
(
current
!=
NULL
)
while
(
current
!=
NULL
)
{
{
...
@@ -70,7 +68,7 @@ PokemonNode* FindPokemon(PokemonNode* pokehead, char pokename[20])
...
@@ -70,7 +68,7 @@ PokemonNode* FindPokemon(PokemonNode* pokehead, char pokename[20])
return
current
;
return
current
;
}
}
}
}
return
0
;
return
NULL
;
}
}
//This searches the list for the specific player
//This searches the list for the specific player
PlayerNode
*
FindPlayer
(
PlayerNode
*
playerhead
,
char
playername
[
20
])
PlayerNode
*
FindPlayer
(
PlayerNode
*
playerhead
,
char
playername
[
20
])
...
@@ -92,13 +90,15 @@ PlayerNode* FindPlayer(PlayerNode* playerhead, char playername[20])
...
@@ -92,13 +90,15 @@ PlayerNode* FindPlayer(PlayerNode* playerhead, char playername[20])
//This adds a new Pokemon to the Pokemon list
//This adds a new Pokemon to the Pokemon list
void
AddPokemonToList
(
Pokedex
*
pokedexpointer
,
char
pokename
[
20
],
char
poketype
[
20
],
char
pokeability
[
50
])
void
AddPokemonToList
(
Pokedex
*
pokedexpointer
,
char
pokename
[
20
],
char
poketype
[
20
],
char
pokeability
[
50
])
{
{
if
(
FindPokemon
(
pokedexpointer
->
pokemonhead
,
pokename
)
!=
0
)
//This checks if the Pokemon already exists
if
(
FindPokemon
(
pokedexpointer
->
pokemonhead
,
pokename
)
!=
NULL
)
{
{
printf
(
"Pokemon exists
\n
"
);
printf
(
"Pokemon exists
\n
"
);
}
}
else
else
//This adds new node and adds the Pokemon to the list
{
{
PokemonNode
*
current
=
NewPokemonNode
(
pokename
,
poketype
,
pokeability
);
PokemonNode
*
current
=
NewPokemonNode
(
pokename
,
poketype
,
pokeability
);
current
->
nextpokemon
=
pokedexpointer
->
pokemonhead
;
current
->
nextpokemon
=
pokedexpointer
->
pokemonhead
;
pokedexpointer
->
pokemonhead
=
current
;
pokedexpointer
->
pokemonhead
=
current
;
printf
(
"Pokemon %s added
\n
"
,
pokename
);
printf
(
"Pokemon %s added
\n
"
,
pokename
);
...
@@ -129,6 +129,7 @@ void AddPokemonToPlayer(Pokedex* pokedexpointer, char pokemon[20], char player[2
...
@@ -129,6 +129,7 @@ void AddPokemonToPlayer(Pokedex* pokedexpointer, char pokemon[20], char player[2
{
{
for
(
int
x
=
0
;
x
<=
PlayerPointer
->
numofpokemon
;
x
++
)
for
(
int
x
=
0
;
x
<=
PlayerPointer
->
numofpokemon
;
x
++
)
{
{
//This adds the Pokemon to the player if he isn't already there
if
(
PlayerPointer
->
PokemonArray
[
x
]
==
NULL
)
if
(
PlayerPointer
->
PokemonArray
[
x
]
==
NULL
)
{
{
PlayerPointer
->
PokemonArray
[
x
]
=
PokemonPointer
;
PlayerPointer
->
PokemonArray
[
x
]
=
PokemonPointer
;
...
@@ -136,6 +137,7 @@ void AddPokemonToPlayer(Pokedex* pokedexpointer, char pokemon[20], char player[2
...
@@ -136,6 +137,7 @@ void AddPokemonToPlayer(Pokedex* pokedexpointer, char pokemon[20], char player[2
printf
(
"
\n
The Pokemon %s is now with the player %s."
,
PokemonPointer
->
name
,
PlayerPointer
->
name
);
printf
(
"
\n
The Pokemon %s is now with the player %s."
,
PokemonPointer
->
name
,
PlayerPointer
->
name
);
break
;
break
;
}
}
//This checks if the Pokemon already exists with the player
else
if
(
PlayerPointer
->
PokemonArray
[
x
]
==
PokemonPointer
)
else
if
(
PlayerPointer
->
PokemonArray
[
x
]
==
PokemonPointer
)
{
{
printf
(
"
\n
%s is already with %s.
\n
"
,
PokemonPointer
->
name
,
PlayerPointer
->
name
);
printf
(
"
\n
%s is already with %s.
\n
"
,
PokemonPointer
->
name
,
PlayerPointer
->
name
);
...
@@ -193,6 +195,12 @@ int main(void)
...
@@ -193,6 +195,12 @@ int main(void)
pokedexvalues
.
playerhead
=
playerhead
;
pokedexvalues
.
playerhead
=
playerhead
;
pokedexvalues
.
pokemonhead
=
pokemonhead
;
pokedexvalues
.
pokemonhead
=
pokemonhead
;
//This function adds players to the pokedex
AddPlayerToList
(
pokedexvaluespointer
,
"Stephen"
);
AddPlayerToList
(
pokedexvaluespointer
,
"Sandra"
);
AddPlayerToList
(
pokedexvaluespointer
,
"Jack"
);
//This tests players that are already added
AddPlayerToList
(
pokedexvaluespointer
,
"Sandra"
);
//This adds Pokemon to the Pokedex list and sets their values
//This adds Pokemon to the Pokedex list and sets their values
AddPokemonToList
(
pokedexvaluespointer
,
"Jigglypuff"
,
"Fairy"
,
"Cute Charm"
);
AddPokemonToList
(
pokedexvaluespointer
,
"Jigglypuff"
,
"Fairy"
,
"Cute Charm"
);
AddPokemonToList
(
pokedexvaluespointer
,
"Venusaur"
,
"Grass"
,
"Overgrow"
);
AddPokemonToList
(
pokedexvaluespointer
,
"Venusaur"
,
"Grass"
,
"Overgrow"
);
...
@@ -210,12 +218,6 @@ int main(void)
...
@@ -210,12 +218,6 @@ int main(void)
AddPokemonToList
(
pokedexvaluespointer
,
"Pikachu"
,
"Electric"
,
"Static"
);
AddPokemonToList
(
pokedexvaluespointer
,
"Pikachu"
,
"Electric"
,
"Static"
);
//This tests a Pokemon that already exists
//This tests a Pokemon that already exists
AddPokemonToList
(
pokedexvaluespointer
,
"Pikachu"
,
"Electric"
,
"Static"
);
AddPokemonToList
(
pokedexvaluespointer
,
"Pikachu"
,
"Electric"
,
"Static"
);
//This function adds players to the pokedex
AddPlayerToList
(
pokedexvaluespointer
,
"Stephen"
);
AddPlayerToList
(
pokedexvaluespointer
,
"Sandra"
);
AddPlayerToList
(
pokedexvaluespointer
,
"Jack"
);
//This tests players that are already added
AddPlayerToList
(
pokedexvaluespointer
,
"Sandra"
);
//This assigns the pokemon to players
//This assigns the pokemon to players
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Jigglypuff"
,
"Sandra"
);
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Jigglypuff"
,
"Sandra"
);
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Bidoof"
,
"Jack"
);
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Bidoof"
,
"Jack"
);
...
@@ -237,6 +239,7 @@ int main(void)
...
@@ -237,6 +239,7 @@ int main(void)
DisplayPokemonDetails
(
pokedexvaluespointer
,
"Darkrai"
);
DisplayPokemonDetails
(
pokedexvaluespointer
,
"Darkrai"
);
DisplayPokemonDetails
(
pokedexvaluespointer
,
"Dialga"
);
DisplayPokemonDetails
(
pokedexvaluespointer
,
"Dialga"
);
DisplayPokemonDetails
(
pokedexvaluespointer
,
"Gengar"
);
DisplayPokemonDetails
(
pokedexvaluespointer
,
"Gengar"
);
DisplayPokemonDetails
(
pokedexvaluespointer
,
"Bidoof"
);
DisplayPokemonDetails
(
pokedexvaluespointer
,
"Palkia"
);
DisplayPokemonDetails
(
pokedexvaluespointer
,
"Palkia"
);
//This displays the details of each player
//This displays the details of each player
DisplayPlayerDetails
(
pokedexvaluespointer
,
"Alan"
);
DisplayPlayerDetails
(
pokedexvaluespointer
,
"Alan"
);
...
...
mainpokedex.exe
View file @
4e382470
No preview for this file type
pokedexstructs.h
View file @
4e382470
...
@@ -16,6 +16,6 @@ typedef struct PlayerNode {
...
@@ -16,6 +16,6 @@ typedef struct PlayerNode {
}
PlayerNode
;
}
PlayerNode
;
//This sets the structure for the pokedex and gives it two headers
//This sets the structure for the pokedex and gives it two headers
typedef
struct
Pokedex
{
typedef
struct
Pokedex
{
P
okemonNode
*
pokemon
head
;
P
layerNode
*
player
head
;
P
layerNode
*
player
head
;
P
okemonNode
*
pokemon
head
;
}
Pokedex
;
}
Pokedex
;
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