Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pokedex 2
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
suleman.hussain
pokedex 2
Commits
fa0916c0
Commit
fa0916c0
authored
Jan 23, 2023
by
suleman.hussain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finish(i think)
parent
e73bb7bf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
27 deletions
+39
-27
functions.c
functions.c
+17
-7
linklist.c
linklist.c
+3
-0
main
main
+0
-0
main.c
main.c
+19
-20
No files found.
functions.c
View file @
fa0916c0
void
AddPokemonToList
(
struct
Pokedex
*
pokemon
,
char
name
[
16
],
char
type
[
12
],
char
ability
[
12
]){
// Theses are all the functions or subprograms needed for main.c
// Adds Pokemon_To_List
void
Pokemon_To_list
(
struct
Pokedex
*
pokemon
,
char
name
[
16
],
char
type
[
12
],
char
ability
[
12
]){
struct
PokemonNode
*
current
=
(
struct
PokemonNode
*
)
pokemon
->
pokemon_head
;
while
(
current
!=
NULL
){
if
(
strcmp
(
current
->
name
,
name
)
==
0
){
...
...
@@ -15,7 +19,8 @@ void AddPokemonToList(struct Pokedex *pokemon, char name[16], char type[12], cha
}
}
void
AddPlayerToList
(
struct
Pokedex
*
player
,
char
name
[
16
])
// Adds Player to list
void
Player_To_List
(
struct
Pokedex
*
player
,
char
name
[
16
])
{
struct
PlayerNode
*
current
=
(
struct
PlayerNode
*
)
player
->
player_head
;
while
(
current
!=
NULL
)
...
...
@@ -36,7 +41,8 @@ void AddPlayerToList(struct Pokedex *player, char name[16])
}
}
void
AddPokemonToPlayer
(
struct
Pokedex
*
pokedex
,
char
playerName
[
16
],
char
pokemonName
[
16
],
char
pokemonType
[
12
],
char
pokemonAbility
[
12
]){
// Adds a pokemon to player
void
Pokemon_To_Player
(
struct
Pokedex
*
pokedex
,
char
playerName
[
16
],
char
pokemonName
[
16
],
char
pokemonType
[
12
],
char
pokemonAbility
[
12
]){
struct
PlayerNode
*
currentPlayer
=
(
struct
PlayerNode
*
)
pokedex
->
player_head
;
while
(
currentPlayer
!=
NULL
&&
strcmp
(
currentPlayer
->
name
,
playerName
)
!=
0
){
currentPlayer
=
currentPlayer
->
next
;
...
...
@@ -64,7 +70,8 @@ void AddPokemonToPlayer(struct Pokedex *pokedex, char playerName[16], char pokem
printf
(
"Successfully added %s to %s's Pokemon list
\n
"
,
pokemonName
,
playerName
);
}
void
DisplayPokemonDetails
(
struct
Pokedex
*
pokedex
,
char
name
[
12
]){
// Displays the infomation of a pokemon
void
Pokemon_Info
(
struct
Pokedex
*
pokedex
,
char
name
[
12
]){
struct
PokemonNode
*
current
=
(
struct
PokemonNode
*
)
pokedex
->
pokemon_head
;
while
(
current
!=
NULL
){
if
(
strcmp
(
current
->
name
,
name
)
==
0
){
...
...
@@ -78,7 +85,8 @@ void DisplayPokemonDetails(struct Pokedex *pokedex, char name[12]){
printf
(
"Sorry! I don't seem to have any record of this Pokemon.
\n
"
);
}
void
DisplayPlayerDetails
(
struct
Pokedex
*
pokedex
,
char
name
[
12
]){
// Displays the count of a given player
void
Player_count
(
struct
Pokedex
*
pokedex
,
char
name
[
12
]){
struct
PlayerNode
*
current
=
(
struct
PlayerNode
*
)
pokedex
->
player_head
;
...
...
@@ -99,7 +107,8 @@ void DisplayPlayerDetails(struct Pokedex *pokedex, char name[12]){
}
void
ListPokemon
(
struct
Pokedex
*
pokedex
)
// Lists all pokemen in the pokedex
void
List_Pokemen
(
struct
Pokedex
*
pokedex
)
{
struct
PokemonNode
*
current
=
(
struct
PokemonNode
*
)
pokedex
->
pokemon_head
;
while
(
current
!=
NULL
)
...
...
@@ -122,7 +131,8 @@ void ListPokemon(struct Pokedex *pokedex)
}
}
void
ListPlayers
(
struct
Pokedex
*
pokedex
){
// Lists all players in the pokedex
void
List_Players
(
struct
Pokedex
*
pokedex
){
struct
PlayerNode
*
current
=
(
struct
PlayerNode
*
)
pokedex
->
player_head
;
while
(
current
!=
NULL
){
if
(
current
==
NULL
){
...
...
linklist.c
View file @
fa0916c0
// Node for pokemon
struct
PokemonNode
{
char
name
[
16
];
char
type
[
12
];
...
...
@@ -5,6 +6,7 @@ struct PokemonNode{
struct
PokemonNode
*
next
;
};
// Node for player
struct
PlayerNode
{
char
name
[
16
];
int
pokemonCount
;
...
...
@@ -17,6 +19,7 @@ struct Pokedex {
struct
PokemonNode
*
pokemon_head
;
};
struct
PokemonNode
*
NewPokemonNode
(
char
name
[
16
],
char
type
[
12
],
char
ability
[
12
]){
struct
PokemonNode
*
newNode
=
(
struct
PokemonNode
*
)
malloc
(
sizeof
(
struct
PokemonNode
));
strcpy
(
newNode
->
name
,
name
);
...
...
main
View file @
fa0916c0
No preview for this file type
main.c
View file @
fa0916c0
...
...
@@ -3,6 +3,7 @@
#include <string.h>
#include <stdbool.h>
//Calls theses programs to be used later
#include "linklist.c"
#include "functions.c"
...
...
@@ -11,22 +12,13 @@ int main(){
pokedex
.
pokemon_head
=
NULL
;
pokedex
.
player_head
=
NULL
;
AddPokemonToList
(
&
pokedex
,
"bob"
,
"human"
,
"cry"
);
AddPokemonToList
(
&
pokedex
,
"suleman"
,
"sad"
,
"sobbing"
);
AddPlayerToList
(
&
pokedex
,
"jim"
);
AddPokemonToPlayer
(
&
pokedex
,
"jim"
,
"bob"
,
"human"
,
"cry"
);
AddPokemonToPlayer
(
&
pokedex
,
"jim"
,
"suleman"
,
"sad"
,
"sobbing"
);
bool
run
=
true
;
while
(
run
=
true
){
int
user_input
;
printf
(
"Please select an option:
\n
1) Add a Pokemon to the pokedex
\n
2) List pokemon
\n
3) Pokemon detail
\n
4) Add player
\n
5) List Players
\n
6) Add Pokemon to player
\n
7) Player details
\n
8) Quit
\n
"
);
scanf
(
"%d"
,
&
user_input
);
// Adds pokemon to pokedex
if
(
user_input
==
1
){
printf
(
"Add pokemon
\n
"
);
...
...
@@ -43,27 +35,30 @@ int main(){
printf
(
"Ability of pokemon
\n
"
);
scanf
(
"%s"
,
&
ability
);
AddPokemonToL
ist
(
&
pokedex
,
name
,
type
,
ability
);
Pokemon_To_l
ist
(
&
pokedex
,
name
,
type
,
ability
);
}
// List all Pokemen
else
if
(
user_input
==
2
){
printf
(
"
\n
"
);
printf
(
"All pokemons in pokedex
\n
"
);
List
Pokemo
n
(
&
pokedex
);
List
_Pokeme
n
(
&
pokedex
);
printf
(
"
\n
"
);
}
// Displays information about given pokemon
else
if
(
user_input
==
3
){
char
pokemon_name
[
12
];
printf
(
"
\n
"
);
printf
(
"Enter pokemon name: "
);
scanf
(
"%s"
,
&
pokemon_name
);
printf
(
"
\n
"
);
DisplayPokemonDetails
(
&
pokedex
,
pokemon_name
);
Pokemon_Info
(
&
pokedex
,
pokemon_name
);
printf
(
"
\n
"
);
}
// Adds given player to pokedex
else
if
(
user_input
==
4
){
printf
(
"
\n
"
);
...
...
@@ -71,17 +66,19 @@ int main(){
printf
(
"Enter username: "
);
scanf
(
"%s"
,
username
);
AddPlayerTo
List
(
&
pokedex
,
username
);
Player_To_
List
(
&
pokedex
,
username
);
}
// Lists all players
else
if
(
user_input
==
5
){
printf
(
"
\n
"
);
printf
(
"All Players:
\n
"
);
ListPlayers
(
&
pokedex
);
List
_
Players
(
&
pokedex
);
printf
(
"
\n
"
);
}
// Adds given pokemon to given player
else
if
(
user_input
==
6
){
char
player_name_in
[
16
];
char
poke_name
[
16
];
...
...
@@ -99,31 +96,33 @@ int main(){
printf
(
"Enter pokemon ability: "
);
scanf
(
"%s"
,
&
poke_Ability
);
AddPokemonTo
Player
(
&
pokedex
,
player_name_in
,
poke_name
,
poke_Type
,
poke_Ability
);
Pokemon_To_
Player
(
&
pokedex
,
player_name_in
,
poke_name
,
poke_Type
,
poke_Ability
);
}
// Shows how many a given player has
else
if
(
user_input
==
7
){
printf
(
"
\n
"
);
printf
(
"Enter player name: "
);
char
player_name
[
12
];
scanf
(
"%s"
,
&
player_name
);
DisplayPlayerDetails
(
&
pokedex
,
player_name
);
Player_count
(
&
pokedex
,
player_name
);
}
//quits
//ends the program
else
if
(
user_input
==
8
){
break
;
}
// check if number is applicable
else
{
printf
(
"else
\n
"
);
}
}
printf
(
"done!
\n
"
);
return
0
;
}
...
...
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