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
1c10d31f
Commit
1c10d31f
authored
Feb 03, 2023
by
sam.pople
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
submission
parents
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
266 additions
and
0 deletions
+266
-0
mainpokedex.c
mainpokedex.c
+245
-0
mainpokedex.exe
mainpokedex.exe
+0
-0
pokedexstructs.h
pokedexstructs.h
+21
-0
No files found.
mainpokedex.c
0 → 100644
View file @
1c10d31f
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include "pokedexstructs.h"
//main file. Run from here.
//functions
void
ListPokemon
(
Pokedex
*
pokedex
)
{
// This displays the list of pokemon.
//This assigns a node to be a head for the pokemon list
PokemonNode
*
current
=
pokedex
->
pokemonhead
;
printf
(
"
\n
List of Pokemon:
\n
"
);
while
(
current
!=
NULL
)
{
//The current node is printed and then the next is assigned.
printf
(
"%s
\n
"
,
current
->
name
);
current
=
current
->
Next
;
}
}
//This displays the list of players
void
ListPlayers
(
Pokedex
*
pokedex
)
{
//The first player item is made the head
PlayerNode
*
current
=
pokedex
->
playerhead
;
printf
(
"
\n
List of Players:
\n
"
);
while
(
current
!=
NULL
)
{
printf
(
"%s
\n
"
,
current
->
name
);
current
=
current
->
Next
;
}
}
//This creates each Pokemon node
PokemonNode
*
NewPokemonNode
(
char
name
[
20
],
char
type
[
20
],
char
ability
[
50
])
{
PokemonNode
*
addnode
=
malloc
(
sizeof
(
PokemonNode
));
strcpy
(
addnode
->
name
,
name
);
strcpy
(
addnode
->
type
,
type
);
strcpy
(
addnode
->
ability
,
ability
);
addnode
->
Next
=
NULL
;
return
addnode
;
}
//This creates each Player node
PlayerNode
*
NewPlayerNode
(
char
name
[
20
])
{
PlayerNode
*
addnode
=
malloc
(
sizeof
(
PlayerNode
));
strcpy
(
addnode
->
name
,
name
);
addnode
->
numofpokemon
=
0
;
memset
(
addnode
->
PokemonArray
,
NULL
,
sizeof
(
addnode
->
PokemonArray
));
addnode
->
Next
=
NULL
;
return
addnode
;
}
//This finds the Pokemon in the Pokemon list
PokemonNode
*
FindPokemon
(
PokemonNode
*
head
,
char
name
[
20
])
{
PokemonNode
*
current
=
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
)
{
return
current
;
}
else
{
current
=
current
->
Next
;
}
}
return
0
;
}
//This searches the list for the specific player
PlayerNode
*
FindPlayer
(
PlayerNode
*
playerhead
,
char
name
[
20
])
{
PlayerNode
*
current
=
playerhead
;
while
(
current
!=
NULL
)
{
if
(
strcmp
(
name
,
current
->
name
)
==
0
)
{
return
current
;
}
else
{
current
=
current
->
Next
;
}
}
return
0
;
}
//This adds a new Pokemon to the Pokemon list
void
AddPokemonToList
(
Pokedex
*
pokedex
,
char
name
[
20
],
char
type
[
20
],
char
ability
[
50
])
{
if
(
FindPokemon
(
pokedex
->
pokemonhead
,
name
)
==
0
)
{
PokemonNode
*
current
=
NewPokemonNode
(
name
,
type
,
ability
);
current
->
Next
=
pokedex
->
pokemonhead
;
pokedex
->
pokemonhead
=
current
;
printf
(
"Pokemon %s added
\n
"
,
name
);
}
else
{
printf
(
"Pokemon exists
\n
"
);
}
}
//This adds new players to the player list
void
AddPlayerToList
(
Pokedex
*
pokedex
,
char
name
[
20
])
{
if
(
FindPlayer
(
pokedex
->
playerhead
,
name
)
==
0
)
{
//If the player isnt already in the list, a new node is created
PlayerNode
*
current
=
NewPlayerNode
(
name
);
current
->
Next
=
pokedex
->
playerhead
;
pokedex
->
playerhead
=
current
;
printf
(
"Player %s Added
\n
"
,
name
);
}
else
{
printf
(
"Player already exists
\n
"
);
}
}
//This assigns Pokemon to players
void
AddPokemonToPlayer
(
Pokedex
*
pokedex
,
char
pokemon
[
20
],
char
player
[
20
])
{
PlayerNode
*
PlayerPointer
=
FindPlayer
(
pokedex
->
playerhead
,
player
);
PokemonNode
*
PokemonPointer
=
FindPokemon
(
pokedex
->
pokemonhead
,
pokemon
);
if
((
PokemonPointer
!=
0
)
&&
(
PlayerPointer
!=
0
))
{
for
(
int
x
=
0
;
x
<=
PlayerPointer
->
numofpokemon
;
x
++
)
{
if
(
PlayerPointer
->
PokemonArray
[
x
]
==
NULL
)
{
PlayerPointer
->
PokemonArray
[
x
]
=
PokemonPointer
;
PlayerPointer
->
numofpokemon
+=
1
;
printf
(
"
\n
The Pokemon %s is now with the player %s."
,
PokemonPointer
->
name
,
PlayerPointer
->
name
);
break
;
}
else
if
(
PlayerPointer
->
PokemonArray
[
x
]
==
PokemonPointer
)
{
printf
(
"
\n
%s is already with %s."
,
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
])
{
PokemonNode
*
current
=
FindPokemon
(
pokedex
->
pokemonhead
,
name
);
if
(
current
!=
0
)
{
printf
(
"
\n
Name: %s
\n
"
,
current
->
name
);
printf
(
"Type: %s
\n
"
,
current
->
type
);
printf
(
"Main ability: %s
\n
"
,
current
->
ability
);
}
else
{
printf
(
"Pokemon unavailable
\n
"
);
}
}
//This displays all the details of the current player node
void
DisplayPlayerDetails
(
Pokedex
*
pokedex
,
char
name
[
20
])
{
PlayerNode
*
current
=
FindPlayer
(
pokedex
->
playerhead
,
name
);
if
(
current
!=
0
)
{
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
->
numofpokemon
>
0
)
{
for
(
int
x
=
0
;
x
<
current
->
numofpokemon
;
x
++
)
{
printf
(
" %s
\n
"
,
current
->
PokemonArray
[
x
]
->
name
);
}
}
}
}
}
//testing
int
main
()
{
// this creates the Pokedex and inserts pokemon into it
Pokedex
pokedexvalues
;
PokemonNode
*
pokemonhead
=
NewPokemonNode
(
"Charizard"
,
"Fire"
,
"Blaze"
);
PlayerNode
*
playerhead
=
NewPlayerNode
(
"Alan"
);
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"
);
AddPokemonToList
(
pokedexvaluespointer
,
"Blastoise"
,
"Water"
,
"Torrent"
);
AddPokemonToList
(
pokedexvaluespointer
,
"Bidoof"
,
"Normal"
,
"Simple"
);
AddPokemonToList
(
pokedexvaluespointer
,
"Dialga"
,
"Dragon"
,
"Pressure"
);
AddPokemonToList
(
pokedexvaluespointer
,
"Palkia"
,
"Dragon"
,
"Pressure"
);
AddPokemonToList
(
pokedexvaluespointer
,
"Lopunny"
,
"Normal"
,
"Cute Charm"
);
AddPokemonToList
(
pokedexvaluespointer
,
"Gengar"
,
"Ghost"
,
"Cursed Body"
);
AddPokemonToList
(
pokedexvaluespointer
,
"Onix"
,
"Rock"
,
"Rock Head"
);
AddPokemonToList
(
pokedexvaluespointer
,
"Gardevoir"
,
"Fairy"
,
"Synchronize"
);
AddPokemonToList
(
pokedexvaluespointer
,
"Diglett"
,
"Ground"
,
"Sand Veil"
);
AddPokemonToList
(
pokedexvaluespointer
,
"Lotad"
,
"Water"
,
"Swift Swim"
);
AddPokemonToList
(
pokedexvaluespointer
,
"Darkrai"
,
"Dark"
,
"Bad Dreams"
);
AddPokemonToList
(
pokedexvaluespointer
,
"Pikachu"
,
"Electric"
,
"Static"
);
//This tests a Pokemon that already exists
AddPokemonToList
(
pokedexvaluespointer
,
"Pikachu"
,
"Electric"
,
"Static"
);
//This function adds players to the pokedex
AddPlayerToList
(
pokedexvaluespointer
,
"Alan"
);
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
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Jigglypuff"
,
"Sandra"
);
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Bidoof"
,
"Jack"
);
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Dialga"
,
"Alan"
);
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Darkrai"
,
"Alan"
);
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Pikachu"
,
"Alan"
);
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Gardevoir"
,
"Alan"
);
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Venusaur"
,
"Stephen"
);
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Blastoise"
,
"Stephen"
);
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Palkia"
,
"Jack"
);
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Onix"
,
"Stephen"
);
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Lopunny"
,
"Sandra"
);
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Gengar"
,
"Alan"
);
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Diglett"
,
"Sandra"
);
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Lotad"
,
"Sandra"
);
AddPokemonToPlayer
(
pokedexvaluespointer
,
"Lotad"
,
"Sandra"
);
//Here are examples of pokemon details being displayed
DisplayPokemonDetails
(
pokedexvaluespointer
,
"Pikachu"
);
DisplayPokemonDetails
(
pokedexvaluespointer
,
"Darkrai"
);
DisplayPokemonDetails
(
pokedexvaluespointer
,
"Dialga"
);
DisplayPokemonDetails
(
pokedexvaluespointer
,
"Gengar"
);
DisplayPokemonDetails
(
pokedexvaluespointer
,
"Palkia"
);
//This displays the details of each player
DisplayPlayerDetails
(
pokedexvaluespointer
,
"Alan"
);
DisplayPlayerDetails
(
pokedexvaluespointer
,
"Stephen"
);
DisplayPlayerDetails
(
pokedexvaluespointer
,
"Sandra"
);
DisplayPlayerDetails
(
pokedexvaluespointer
,
"Jack"
);
//This displays the list of players and of pokemon
ListPokemon
(
pokedexvaluespointer
);
ListPlayers
(
pokedexvaluespointer
);
}
\ No newline at end of file
mainpokedex.exe
0 → 100644
View file @
1c10d31f
File added
pokedexstructs.h
0 → 100644
View file @
1c10d31f
//structs
//This sets the structure variables for the PokemonNode (name, type and ability)
typedef
struct
PokemonNode
{
char
name
[
20
];
char
type
[
20
];
char
ability
[
50
];
struct
PokemonNode
*
Next
;
}
PokemonNode
;
//This sets the structure variables for the player node (name, number of pokemon and Pokemon Array)
typedef
struct
PlayerNode
{
char
name
[
20
];
int
numofpokemon
;
PokemonNode
*
PokemonArray
[
30
];
struct
PlayerNode
*
Next
;
}
PlayerNode
;
typedef
struct
Pokedex
{
PokemonNode
*
pokemonhead
;
PlayerNode
*
playerhead
;
}
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