Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
C Pokedex Assignment
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 Assignment
Commits
eae2176f
Commit
eae2176f
authored
Jan 16, 2023
by
daniel.pearson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete main.c
parent
e0aa0b6d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
291 deletions
+0
-291
main.c
main.c
+0
-291
No files found.
main.c
deleted
100644 → 0
View file @
e0aa0b6d
#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
// Want the playerhead to point to the new node we have made
struct
Pokemon
*
pokemonHead
;
};
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
;
// list = startlist1 -> playerhead
while
(
temp
->
next
!=
NULL
)
{
// has to be a while loop to loop through all
// nodes not just the second node
temp
=
temp
->
next
;
}
if
(
temp
->
next
==
NULL
)
{
temp
->
next
=
newPokemon
;
return
;
}
return
;
}
struct
Pokemon
*
FindPokemon
(
struct
Pokemon
*
list
,
char
name
[
20
])
{
// Need this for adding pokemon to players
struct
Pokemon
*
temp2
=
list
;
// list = start1 -> pokemonHead
int
value
;
while
(
temp2
->
next
!=
NULL
)
{
value
=
strcmp
(
name
,
temp2
->
name
);
if
(
value
==
0
)
{
// printf("\nPokemon Found %s\n", temp2->name);
// printf("\nFound Pokemon");
return
temp2
;
}
if
(
name
==
temp2
->
name
)
{
return
temp2
;
}
temp2
=
temp2
->
next
;
}
if
(
temp2
->
next
==
NULL
)
{
value
=
strcmp
(
name
,
temp2
->
name
);
if
(
value
==
0
)
{
// printf("\nPokemon Found2 %s\n", temp2->name);
// printf("\nFound");
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
)
{
//CHANGE THISSSSSSS
printf
(
"
\n
Pokemon Details:"
);
struct
Pokemon
*
temp
=
list
;
while
(
temp
->
next
!=
NULL
)
{
printf
(
"
\n
Pokemon Name: %s"
,
temp
->
name
);
printf
(
"
\n
Pokemons Type: %s"
,
temp
->
type
);
printf
(
"
\n
Pokemons Ability: %s"
,
temp
->
ability
);
printf
(
"
\n
"
);
temp
=
temp
->
next
;
}
if
(
temp
->
next
==
NULL
)
{
printf
(
"
\n
Pokemon Name: %s"
,
temp
->
name
);
printf
(
"
\n
Pokemons Type: %s"
,
temp
->
type
);
printf
(
"
\n
Pokemons Ability: %s"
,
temp
->
ability
);
return
;
}
return
;
}
// 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
;
// list = startlist1 -> playerhead
while
(
temp
->
next
!=
NULL
)
{
// has to be a while loop to loop through all
// nodes not just the second node
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
)
{
// printf("\nFound Player");
return
temp3
;
}
if
(
name
==
temp3
->
name
)
{
return
temp3
;
}
temp3
=
temp3
->
next
;
}
if
(
temp3
->
next
==
NULL
)
{
value
=
strcmp
(
name
,
temp3
->
name
);
if
(
value
==
0
)
{
// printf("\nFound");
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
;
}
// printf("\n%s Pokemon Are:", player->name);
// printf("\nPokemon %s\n", pokemon->name);
// printf("\nPokemon Name Added %s\n", pokemon->name);
}
}
int
main
()
{
struct
Pokedex
*
start1
=
NULL
;
// start player list at this address
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
;
}
// new_node.subject,subject takes subject from the parameters
struct
Pokemon
*
startPokemonList
=
start1
->
pokemonHead
;
startPokemonList
=
NULL
;
if
(
startPokemonList
==
NULL
)
{
startPokemonList
=
Pikachu
;
}
// FindPokemon(start1, "Charizard");
// START PLAYER MAIN CODE BELOW
struct
Player
*
Ash
=
NULL
;
Ash
=
malloc
(
sizeof
(
struct
Player
));
if
(
Ash
!=
NULL
)
{
strcpy
(
Ash
->
name
,
"Ash"
);
Ash
->
next
=
NULL
;
}
// new_node.subject,subject takes subject from the parameters
struct
Player
*
startPlayerList
=
start1
->
playerHead
;
startPlayerList
=
NULL
;
if
(
startPlayerList
==
NULL
)
{
startPlayerList
=
Ash
;
}
AddPokemonToList
(
startPokemonList
,
"Charizard"
,
"Air"
,
"Fire"
);
AddPokemonToList
(
startPokemonList
,
"Benny"
,
"Air"
,
"Fire"
);
FindPokemon
(
startPokemonList
,
"Benny"
);
ListPokemon
(
startPokemonList
);
printf
(
"
\n
"
);
DisplayPokemonDetails
(
startPokemonList
);
AddPlayerToList
(
startPlayerList
,
"Jeano"
);
FindPlayer
(
startPlayerList
,
"Ash"
);
ListPlayers
(
startPlayerList
);
AddPokemonToPlayer
(
startPokemonList
,
startPlayerList
,
"Ash"
,
"Charizard"
);
AddPokemonToPlayer
(
startPokemonList
,
startPlayerList
,
"Ash"
,
"Pikachu"
);
DisplayPlayerDetails
(
startPlayerList
,
"Ash"
);
// FindPokemon(startPokemonList,"Pikachu");
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