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
aurian.foulner
Pokedex
Commits
1c22b684
Unverified
Commit
1c22b684
authored
Jan 17, 2023
by
ozzy308
Committed by
GitHub
Jan 17, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add files via upload
parents
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
147 additions
and
0 deletions
+147
-0
Pokedex.c
c/Pokedex.c
+147
-0
No files found.
c/Pokedex.c
0 → 100644
View file @
1c22b684
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Structs/lists for player, pokemon and joint pokedex
typedef
struct
Player
{
char
name
[
50
];
int
PokemonCount
;
struct
Player
*
next
;
}
Player
;
// Used to add new player node
Player
*
NewPlayerNode
(
char
name
[
50
])
{
struct
Player
*
node
=
NULL
;
node
=
malloc
(
sizeof
(
Player
));
if
(
node
!=
NULL
)
{
// If there is something there, it needs to go next in
// line and not take the first spot.
strcpy
(
node
->
name
,
name
);
node
->
next
=
NULL
;
}
return
node
;
}
// Adding player to list via function
void
AddPlayerToList
(
Player
*
ListOfPlayers
,
char
name
[
50
])
{
Player
*
node1
=
NewPlayerNode
(
name
);
Player
*
node2
=
ListOfPlayers
;
while
(
node2
->
next
!=
NULL
)
{
// If next is NULL then its the last entry
node2
=
node2
->
next
;
}
// Moves to next node in the list, does't reset, just adds
if
(
node2
->
next
==
NULL
)
{
node2
->
next
=
node1
;
return
;
}
return
;
}
// Finding players function
Player
*
FindPlayer
(
Player
*
ListOfPlayers
,
char
name
[
50
])
{
Player
*
node2
=
ListOfPlayers
;
int
value
;
while
(
node2
->
next
!=
NULL
)
{
value
=
strcmp
(
name
,
node2
->
name
);
if
(
value
==
0
)
{
return
node2
;
}
if
(
node2
->
next
==
NULL
)
{
value
=
strcmp
(
name
,
node2
->
name
);
if
(
value
==
0
)
{
return
node2
;
}
if
(
name
==
node2
->
name
)
{
return
node2
;
}
node2
=
node2
->
next
;
}
return
node2
;
}
// Struct for pokemon defined
typedef
struct
Pokemon
{
char
name
[
50
];
char
type
[
50
];
char
ability
[
50
];
struct
Pokemon
*
next
;
}
Pokemon
;
// New pokemon node created
Pokemon
*
NewPokemonNode
(
char
name
[
50
],
char
type
[
50
],
char
ability
[
50
])
{
Pokemon
*
node
=
NULL
;
node
=
malloc
(
sizeof
(
Pokemon
));
// Repeated for all structs for size
if
(
node
!=
NULL
)
{
strcpy
(
node
->
name
,
name
);
strcpy
(
node
->
type
,
type
);
strcpy
(
node
->
ability
,
ability
);
node
->
next
=
NULL
;
}
return
node
;
}
// Adding a pokemon to the list
void
AddPokemonToList
(
Player
*
ListOfPokemon
,
char
name
[
50
],
char
type
[
50
],
char
ability
[
50
])
{
Player
*
node1
=
NewPokemonNode
(
name
,
ability
,
type
);
Player
*
node2
=
ListOfPokemon
;
while
(
node2
->
next
!=
NULL
)
{
// If next is NULL then its the last entry
node2
=
node2
->
next
;
}
// Moves to next node in the list, does't reset, just adds
if
(
node2
->
next
==
NULL
)
{
node2
->
next
=
node1
;
return
;
}
return
;
}
// Listing all players into one
void
ListOfPlayers
(
Player
*
ListOfPlayers
)
{
printf
(
"The players listed in the pokedex: "
);
Player
*
node2
=
ListOfPlayers
;
while
(
node2
->
next
!=
NULL
)
{
printf
(
"Name - %s
\n
"
,
node2
->
name
);
node2
=
node2
->
next
;
}
if
(
node2
->
next
==
NULL
)
{
printf
(
"Name: %s
\n
"
,
node2
->
name
);
return
;
}
}
// Listing all pokemon into one
void
ListOfPokemon
(
Pokemon
*
ListOfPokemon
)
{
printf
(
"The pokemon listed in the pokedex: "
);
Pokemon
*
node2
=
ListOfPokemon
;
while
(
node2
->
next
!=
NULL
)
{
printf
(
"Name - %s
\n
"
,
node2
->
name
);
node2
=
node2
->
next
;
}
if
(
node2
->
next
==
NULL
)
{
printf
(
"Name: %s
\n
"
,
node2
->
name
);
return
;
}
}
// Goes through list and finds all pokemon
void
DisplayPokemonDetails
(
Pokemon
*
ListOfPokemon
,
char
name
[
50
])
{
printf
(
"Pokemon:
\n
"
);
Pokemon
*
Pokem
=
Pokem
(
ListOfPokemon
,
name
);
printf
(
"Name of Pokemon - %s
\n
"
,
Pokem
->
name
)
printf
(
"Type of Pokemon - %s
\n
"
,
Pokem
->
Type
)
printf
(
"Ability of Pokemon - %s
\n
"
,
Pokem
->
Ability
)
}
void
DisplayPlayerDetails
(
Player
*
ListOfPlayers
,
char
name
[
50
])
{
printf
(
"Players:
\n
"
);
Player
*
play
=
Player
(
ListOfPlayers
,
name
);
printf
(
"Name of Players - %s
\n
"
,
Play
->
name
)
}
// Pokedex defined as a struct
typedef
struct
Pokedex
{
Pokemon
ListOfPokemon
;
Player
*
ListOfPlayers
;
}
Pokedex
;
Pokedex
*
node
=
NULL
;
int
main
()
{
// Adding data to lists
AddPokemon
(
ListOfPokemon
,
"Bulbasaur"
,
"Grass"
,
"Overgrow"
);
AddPokemon
(
ListOfPokemon
,
"Charmander"
,
"Fire"
,
"Blaze"
);
AddPlayer
(
ListOfPlayers
,
"Ash"
,
"Misty"
);
printf
(
ListOfPokemon
);
printf
(
ListOfPlayers
);
}
\ No newline at end of file
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