Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
C Pokedex With C File
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
daniel.pearson
C Pokedex With C File
Commits
033492d4
Commit
033492d4
authored
Jan 16, 2023
by
daniel.pearson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parents
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
279 additions
and
0 deletions
+279
-0
main.c
main.c
+279
-0
No files found.
main.c
0 → 100644
View file @
033492d4
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct
Player
{
char
name
[
20
];
int
PokemonCount
;
struct
Pokemon
*
arr
[
20
];
struct
Player
*
next
;
};
struct
Pokemon
{
char
name
[
20
];
char
type
[
20
];
char
ability
[
20
];
struct
Pokemon
*
next
;
};
struct
Pokedex
{
struct
Player
*
playerHead
;
// Points to a player struct
struct
Pokemon
*
pokemonHead
;
};
//START OF POKEMON CREATION
struct
Pokemon
*
NewPokemonNode
(
char
name
[
20
],
char
type
[
20
],
char
ability
[
20
])
{
struct
Pokemon
*
newPokemon
=
NULL
;
newPokemon
=
malloc
(
sizeof
(
struct
Pokemon
));
if
(
newPokemon
!=
NULL
)
{
strcpy
(
newPokemon
->
name
,
name
);
strcpy
(
newPokemon
->
type
,
type
);
strcpy
(
newPokemon
->
ability
,
ability
);
newPokemon
->
next
=
NULL
;
}
return
newPokemon
;
}
void
AddPokemonToList
(
struct
Pokemon
*
list
,
char
name1
[
20
],
char
type1
[
20
],
char
ability1
[
20
])
{
struct
Pokemon
*
newPokemon
=
NewPokemonNode
(
name1
,
type1
,
ability1
);
struct
Pokemon
*
temp
=
list
;
while
(
temp
->
next
!=
NULL
)
{
temp
=
temp
->
next
;
}
if
(
temp
->
next
==
NULL
)
{
temp
->
next
=
newPokemon
;
return
;
}
return
;
}
struct
Pokemon
*
FindPokemon
(
struct
Pokemon
*
list
,
char
name
[
20
])
{
struct
Pokemon
*
temp2
=
list
;
int
value
;
while
(
temp2
->
next
!=
NULL
)
{
value
=
strcmp
(
name
,
temp2
->
name
);
if
(
value
==
0
)
{
return
temp2
;
}
if
(
name
==
temp2
->
name
)
{
return
temp2
;
}
temp2
=
temp2
->
next
;
}
if
(
temp2
->
next
==
NULL
)
{
value
=
strcmp
(
name
,
temp2
->
name
);
if
(
value
==
0
)
{
return
temp2
;
}
}
return
temp2
;
}
void
ListPokemon
(
struct
Pokemon
*
list
)
{
struct
Pokemon
*
temp
=
list
;
printf
(
"
\n
Pokemon List:"
);
while
(
temp
->
next
!=
NULL
)
{
printf
(
"
\n
Pokemon Name: %s"
,
temp
->
name
);
temp
=
temp
->
next
;
}
if
(
temp
->
next
==
NULL
)
{
printf
(
"
\n
Pokemon Name: %s"
,
temp
->
name
);
return
;
}
return
;
}
void
DisplayPokemonDetails
(
struct
Pokemon
*
list
,
char
name
[
20
])
{
printf
(
"
\n
Pokemon Details:"
);
struct
Pokemon
*
Poke
=
FindPokemon
(
list
,
name
);
printf
(
"
\n
Pokemon Name: %s"
,
Poke
->
name
);
printf
(
"
\n
Pokemons Type: %s"
,
Poke
->
type
);
printf
(
"
\n
Pokemons Ability: %s"
,
Poke
->
ability
);
printf
(
"
\n
"
);
}
// START OF PLAYER CODE BELOW
struct
Player
*
NewPlayerNode
(
char
name
[
20
])
{
struct
Player
*
newPlayer
=
NULL
;
newPlayer
=
malloc
(
sizeof
(
struct
Player
));
if
(
newPlayer
!=
NULL
)
{
strcpy
(
newPlayer
->
name
,
name
);
newPlayer
->
next
=
NULL
;
}
return
newPlayer
;
}
void
AddPlayerToList
(
struct
Player
*
Playerlist
,
char
name1
[
20
])
{
struct
Player
*
newPlayer
=
NewPlayerNode
(
name1
);
struct
Player
*
temp
=
Playerlist
;
while
(
temp
->
next
!=
NULL
)
{
temp
=
temp
->
next
;
}
if
(
temp
->
next
==
NULL
)
{
temp
->
next
=
newPlayer
;
return
;
}
return
;
}
struct
Player
*
FindPlayer
(
struct
Player
*
Playerlist
,
char
name
[
20
])
{
struct
Player
*
temp3
=
Playerlist
;
// list = start1 -> pokemonHead
int
value
;
while
(
temp3
->
next
!=
NULL
)
{
value
=
strcmp
(
name
,
temp3
->
name
);
if
(
value
==
0
)
{
return
temp3
;
}
if
(
name
==
temp3
->
name
)
{
return
temp3
;
}
temp3
=
temp3
->
next
;
}
if
(
temp3
->
next
==
NULL
)
{
value
=
strcmp
(
name
,
temp3
->
name
);
if
(
value
==
0
)
{
return
temp3
;
}
}
return
temp3
;
}
void
ListPlayers
(
struct
Player
*
Playerlist
)
{
printf
(
"
\n\n
Player List:"
);
struct
Player
*
temp
=
Playerlist
;
while
(
temp
->
next
!=
NULL
)
{
printf
(
"
\n
Player Name: %s"
,
temp
->
name
);
temp
=
temp
->
next
;
}
if
(
temp
->
next
==
NULL
)
{
printf
(
"
\n
Player Name: %s"
,
temp
->
name
);
return
;
}
return
;
}
void
AddPokemonToPlayer
(
struct
Pokemon
*
list
,
struct
Player
*
PlayerList
,
char
PlayerName
[
20
],
char
PokemonName
[
20
])
{
struct
Pokemon
*
pokemon
=
FindPokemon
(
list
,
PokemonName
);
struct
Player
*
player
=
FindPlayer
(
PlayerList
,
PlayerName
);
player
->
PokemonCount
+=
1
;
// printf("\nPlayer Find Name %s\n", player->name);
for
(
int
a
=
0
;
a
<
20
;
a
=
a
+
1
)
{
if
(
player
->
arr
[
a
]
==
NULL
)
{
player
->
arr
[
a
]
=
pokemon
;
break
;
}
else
if
(
player
->
arr
[
a
]
!=
NULL
)
{
player
->
arr
[
a
+
1
]
=
pokemon
;
break
;
}
};
}
void
DisplayPlayerDetails
(
struct
Player
*
list
,
char
PlayerName
[
20
])
{
struct
Player
*
player
=
FindPlayer
(
list
,
PlayerName
);
struct
Pokemon
*
pokemon
;
printf
(
"
\n\n
%s Pokemon Are:
\n
"
,
player
->
name
);
for
(
int
i
=
0
;
i
<
20
;
++
i
)
{
pokemon
=
player
->
arr
[
i
];
if
(
pokemon
!=
NULL
)
{
printf
(
"%s
\n
"
,
pokemon
->
name
);
}
else
{
continue
;
}
}
}
int
main
()
{
struct
Pokedex
*
start1
=
NULL
;
//CREATING FIRST NODE IN POKEMON LIST
struct
Pokemon
*
Pikachu
=
NULL
;
Pikachu
=
malloc
(
sizeof
(
struct
Pokemon
));
if
(
Pikachu
!=
NULL
)
{
strcpy
(
Pikachu
->
name
,
"Pikachu"
);
strcpy
(
Pikachu
->
type
,
"Grass"
);
strcpy
(
Pikachu
->
ability
,
"Lightning"
);
Pikachu
->
next
=
NULL
;
}
struct
Pokemon
*
startPokemonList
=
start1
->
pokemonHead
;
startPokemonList
=
NULL
;
if
(
startPokemonList
==
NULL
)
{
startPokemonList
=
Pikachu
;
}
// START PLAYER MAIN CODE BELOW
//CREATING THE FIRST NODE IN THE LIST
struct
Player
*
Ash
=
NULL
;
Ash
=
malloc
(
sizeof
(
struct
Player
));
if
(
Ash
!=
NULL
)
{
strcpy
(
Ash
->
name
,
"Ash"
);
Ash
->
next
=
NULL
;
}
struct
Player
*
startPlayerList
=
start1
->
playerHead
;
startPlayerList
=
NULL
;
if
(
startPlayerList
==
NULL
)
{
startPlayerList
=
Ash
;
}
//TESTING ALL OF THE FUNCTIONS
AddPokemonToList
(
startPokemonList
,
"Charizard"
,
"Air"
,
"Fire"
);
AddPokemonToList
(
startPokemonList
,
"Benny"
,
"Air"
,
"Fire"
);
FindPokemon
(
startPokemonList
,
"Benny"
);
ListPokemon
(
startPokemonList
);
printf
(
"
\n
"
);
DisplayPokemonDetails
(
startPokemonList
,
"Benny"
);
AddPlayerToList
(
startPlayerList
,
"Jeano"
);
FindPlayer
(
startPlayerList
,
"Ash"
);
ListPlayers
(
startPlayerList
);
AddPokemonToPlayer
(
startPokemonList
,
startPlayerList
,
"Ash"
,
"Charizard"
);
AddPokemonToPlayer
(
startPokemonList
,
startPlayerList
,
"Ash"
,
"Pikachu"
);
DisplayPlayerDetails
(
startPlayerList
,
"Ash"
);
return
0
;
}
\ 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