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
8a433112
Commit
8a433112
authored
Feb 05, 2023
by
sam.pople
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
submission
parent
afe94017
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
51 deletions
+57
-51
mainpokedex.c
mainpokedex.c
+57
-51
mainpokedex.exe
mainpokedex.exe
+0
-0
No files found.
mainpokedex.c
View file @
8a433112
...
...
@@ -4,11 +4,11 @@
# include "pokedexstructs.h"
//main file. Run from here.
//functions
void
ListPokemon
(
Pokedex
*
pokedex
)
void
ListPokemon
(
Pokedex
*
pokedex
pointer
)
{
// This displays the list of pokemon.
//This assigns a node to be a head for the pokemon list
PokemonNode
*
current
=
pokedex
->
pokemonhead
;
PokemonNode
*
current
=
pokedex
pointer
->
pokemonhead
;
printf
(
"
\n
List of Pokemon:
\n
"
);
while
(
current
!=
NULL
)
{
//The current node is printed and then the next is assigned.
...
...
@@ -18,10 +18,10 @@ void ListPokemon(Pokedex *pokedex)
}
//This displays the list of players
void
ListPlayers
(
Pokedex
*
pokedex
)
void
ListPlayers
(
Pokedex
*
pokedex
pointer
)
{
//The first player item is made the head
PlayerNode
*
current
=
pokedex
->
playerhead
;
PlayerNode
*
current
=
pokedex
pointer
->
playerhead
;
printf
(
"
\n
List of Players:
\n
"
);
while
(
current
!=
NULL
)
{
...
...
@@ -32,87 +32,88 @@ void ListPlayers(Pokedex* pokedex)
}
//This creates each Pokemon node
PokemonNode
*
NewPokemonNode
(
char
name
[
20
],
char
type
[
20
],
char
ability
[
50
])
PokemonNode
*
NewPokemonNode
(
char
pokename
[
20
],
char
poketype
[
20
],
char
poke
ability
[
50
])
{
PokemonNode
*
addnode
=
malloc
(
sizeof
(
PokemonNode
));
strcpy
(
addnode
->
name
,
name
);
strcpy
(
addnode
->
type
,
type
);
strcpy
(
addnode
->
ability
,
ability
);
addnode
->
nextpokemon
=
NULL
;
strcpy
(
addnode
->
name
,
pokename
);
strcpy
(
addnode
->
type
,
poketype
);
strcpy
(
addnode
->
ability
,
pokeability
);
return
addnode
;
}
//This creates each Player node
PlayerNode
*
NewPlayerNode
(
char
name
[
20
])
PlayerNode
*
NewPlayerNode
(
char
player
name
[
20
])
{
PlayerNode
*
addnode
=
malloc
(
sizeof
(
PlayerNode
));
strcpy
(
addnode
->
name
,
name
)
;
addnode
->
nextplayer
=
NULL
;
addnode
->
numofpokemon
=
0
;
memset
(
addnode
->
PokemonArray
,
NULL
,
sizeof
(
addnode
->
PokemonArray
));
strcpy
(
addnode
->
name
,
playername
);
memset
(
addnode
->
PokemonArray
,
0
,
sizeof
(
addnode
->
PokemonArray
));
addnode
->
nextplayer
=
NULL
;
return
addnode
;
}
//This finds the Pokemon in the Pokemon list
PokemonNode
*
FindPokemon
(
PokemonNode
*
head
,
char
name
[
20
])
PokemonNode
*
FindPokemon
(
PokemonNode
*
pokehead
,
char
poke
name
[
20
])
{
PokemonNode
*
current
=
head
;
PokemonNode
*
current
=
poke
head
;
while
(
current
!=
NULL
)
{
//If the current node matches the searched for node,a pointer is returned to it or they move on to the next or return nothing
if
(
strcmp
(
name
,
current
->
name
)
=
=
0
)
if
(
strcmp
(
pokename
,
current
->
name
)
!
=
0
)
{
return
current
;
current
=
current
->
nextpokemon
;
}
else
{
current
=
current
->
nextpokemon
;
return
current
;
}
}
return
0
;
}
//This searches the list for the specific player
PlayerNode
*
FindPlayer
(
PlayerNode
*
playerhead
,
char
name
[
20
])
PlayerNode
*
FindPlayer
(
PlayerNode
*
playerhead
,
char
player
name
[
20
])
{
PlayerNode
*
current
=
playerhead
;
while
(
current
!=
NULL
)
{
if
(
strcmp
(
name
,
current
->
name
)
=
=
0
)
if
(
strcmp
(
playername
,
current
->
name
)
!
=
0
)
{
return
current
;
current
=
current
->
nextplayer
;
}
else
{
current
=
current
->
nextplayer
;
return
current
;
}
}
return
0
;
}
//This adds a new Pokemon to the Pokemon list
void
AddPokemonToList
(
Pokedex
*
pokedex
,
char
name
[
20
],
char
type
[
20
],
char
ability
[
50
])
void
AddPokemonToList
(
Pokedex
*
pokedex
pointer
,
char
pokename
[
20
],
char
poketype
[
20
],
char
poke
ability
[
50
])
{
if
(
FindPokemon
(
pokedex
->
pokemonhead
,
name
)
=
=
0
)
if
(
FindPokemon
(
pokedex
pointer
->
pokemonhead
,
pokename
)
!
=
0
)
{
PokemonNode
*
current
=
NewPokemonNode
(
name
,
type
,
ability
);
current
->
nextpokemon
=
pokedex
->
pokemonhead
;
pokedex
->
pokemonhead
=
current
;
printf
(
"Pokemon %s added
\n
"
,
name
);
printf
(
"Pokemon exists
\n
"
);
}
else
{
printf
(
"Pokemon exists
\n
"
);
PokemonNode
*
current
=
NewPokemonNode
(
pokename
,
poketype
,
pokeability
);
current
->
nextpokemon
=
pokedexpointer
->
pokemonhead
;
pokedexpointer
->
pokemonhead
=
current
;
printf
(
"Pokemon %s added
\n
"
,
pokename
);
}
}
//This adds new players to the player list
void
AddPlayerToList
(
Pokedex
*
pokedex
,
char
name
[
20
])
void
AddPlayerToList
(
Pokedex
*
pokedex
pointer
,
char
player
name
[
20
])
{
if
(
FindPlayer
(
pokedex
->
playerhead
,
name
)
==
0
)
if
(
FindPlayer
(
pokedex
pointer
->
playerhead
,
player
name
)
==
0
)
{
//If the player isnt already in the list, a new node is created
PlayerNode
*
current
=
NewPlayerNode
(
name
);
current
->
nextplayer
=
pokedex
->
playerhead
;
pokedex
->
playerhead
=
current
;
printf
(
"Player %s Added
\n
"
,
name
);
PlayerNode
*
current
=
NewPlayerNode
(
player
name
);
current
->
nextplayer
=
pokedex
pointer
->
playerhead
;
pokedex
pointer
->
playerhead
=
current
;
printf
(
"Player %s Added
\n
"
,
player
name
);
}
else
{
...
...
@@ -120,11 +121,11 @@ void AddPlayerToList(Pokedex* pokedex, char name[20])
}
}
//This assigns Pokemon to players
void
AddPokemonToPlayer
(
Pokedex
*
pokedex
,
char
pokemon
[
20
],
char
player
[
20
])
void
AddPokemonToPlayer
(
Pokedex
*
pokedex
pointer
,
char
pokemon
[
20
],
char
player
[
20
])
{
P
layerNode
*
PlayerPointer
=
FindPlayer
(
pokedex
->
playerhead
,
player
);
P
okemonNode
*
PokemonPointer
=
FindPokemon
(
pokedex
->
pokemonhead
,
pokemon
);
if
((
PokemonPointer
!=
0
)
&&
(
PlayerPointer
!=
0
))
P
okemonNode
*
PokemonPointer
=
FindPokemon
(
pokedexpointer
->
pokemonhead
,
pokemon
);
P
layerNode
*
PlayerPointer
=
FindPlayer
(
pokedexpointer
->
playerhead
,
player
);
if
((
PokemonPointer
!=
NULL
)
&&
(
PlayerPointer
!=
NULL
))
{
for
(
int
x
=
0
;
x
<=
PlayerPointer
->
numofpokemon
;
x
++
)
{
...
...
@@ -137,19 +138,19 @@ void AddPokemonToPlayer(Pokedex* pokedex, char pokemon[20], char player[20])
}
else
if
(
PlayerPointer
->
PokemonArray
[
x
]
==
PokemonPointer
)
{
printf
(
"
\n
%s is already with %s."
,
PokemonPointer
->
name
,
PlayerPointer
->
name
);
printf
(
"
\n
%s is already with %s.
\n
"
,
PokemonPointer
->
name
,
PlayerPointer
->
name
);
break
;
}
}
}
}
//This displays the details of the Pokemon, including their Name, type and primary ability.
void
DisplayPokemonDetails
(
Pokedex
*
pokedex
,
char
name
[
20
])
void
DisplayPokemonDetails
(
Pokedex
*
pokedex
pointer
,
char
poke
name
[
20
])
{
PokemonNode
*
current
=
FindPokemon
(
pokedex
->
pokemonhead
,
name
);
if
(
current
!=
0
)
PokemonNode
*
current
=
FindPokemon
(
pokedex
pointer
->
pokemonhead
,
poke
name
);
if
(
current
!=
NULL
)
{
printf
(
"
\n
Name: %s
\n
"
,
current
->
name
);
printf
(
"
\n
Name: %s
\n
"
,
current
->
name
);
printf
(
"Type: %s
\n
"
,
current
->
type
);
printf
(
"Main ability: %s
\n
"
,
current
->
ability
);
}
...
...
@@ -159,14 +160,14 @@ void DisplayPokemonDetails(Pokedex* pokedex, char name[20])
}
}
//This displays all the details of the current player node
void
DisplayPlayerDetails
(
Pokedex
*
pokedex
,
char
name
[
20
])
void
DisplayPlayerDetails
(
Pokedex
*
pokedex
pointer
,
char
player
name
[
20
])
{
PlayerNode
*
current
=
FindPlayer
(
pokedex
->
playerhead
,
name
);
if
(
current
!=
0
)
{
PlayerNode
*
current
=
FindPlayer
(
pokedex
pointer
->
playerhead
,
player
name
);
if
(
current
!=
NULL
)
{
printf
(
"
\n
Name: %s
\n
"
,
current
->
name
);
printf
(
"Number of Pokemon: %d
\n
"
,
current
->
numofpokemon
);
printf
(
"Pokemon they have:
\n
"
);
if
(
current
!=
0
)
if
(
current
!=
NULL
)
{
if
(
current
->
numofpokemon
>
0
)
{
...
...
@@ -179,14 +180,19 @@ void DisplayPlayerDetails(Pokedex* pokedex, char name[20])
}
}
//testing
int
main
()
int
main
(
void
)
{
// this starts the Pokedex and gives it a head pokemon and player
Pokedex
pokedexvalues
;
PokemonNode
*
pokemonhead
=
NewPokemonNode
(
"Charizard"
,
"Fire"
,
"Blaze"
);
PlayerNode
*
playerhead
=
NewPlayerNode
(
"Alan"
);
PokemonNode
*
pokemonhead
=
NewPokemonNode
(
"Charizard"
,
"Fire"
,
"Blaze"
);
Pokedex
pokedexvalues
;
Pokedex
*
pokedexvaluespointer
=
&
pokedexvalues
;
pokedexvalues
.
playerhead
=
playerhead
;
pokedexvalues
.
pokemonhead
=
pokemonhead
;
Pokedex
*
pokedexvaluespointer
=
&
pokedexvalues
;
//This adds Pokemon to the Pokedex list and sets their values
AddPokemonToList
(
pokedexvaluespointer
,
"Jigglypuff"
,
"Fairy"
,
"Cute Charm"
);
AddPokemonToList
(
pokedexvaluespointer
,
"Venusaur"
,
"Grass"
,
"Overgrow"
);
...
...
mainpokedex.exe
View file @
8a433112
No preview for this file type
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