Commit 5708520f authored by jinny.wilkin's avatar jinny.wilkin

Pokedex finished

parent b68740f9
No preview for this file type
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#define MAXCHAR 1000 #define MAXCHAR 1000
...@@ -13,14 +14,17 @@ typedef struct Pokemon{ ...@@ -13,14 +14,17 @@ typedef struct Pokemon{
typedef struct Trainers{ typedef struct Trainers{
char name[50]; char name[50];
Pokemon owned[]; Pokemon owned[400];
int totalOwned;
} Trainers; } Trainers;
typedef struct Pokedex{ typedef struct Pokedex{
Pokemon pokemon[721]; Pokemon pokemon[721];
Trainers trainers[]; Trainers trainers[5];
} Pokedex; } Pokedex;
Pokedex mainDex;
int populateDex(){ int populateDex(){
FILE *fp; FILE *fp;
char row[MAXCHAR]; char row[MAXCHAR];
...@@ -29,23 +33,21 @@ int populateDex(){ ...@@ -29,23 +33,21 @@ int populateDex(){
fp = fopen("pokedexREF.csv", "r"); fp = fopen("pokedexREF.csv", "r");
Pokemon pokelist[721];
int read = 0; int read = 0;
int records = 0; int records = 0;
while (!feof(fp)){ while (!feof(fp)){
read = fscanf(fp, "%d,%11[^,],%8[^,],%8[^,],%13[^,],%d,%d,%5[^,],%11[^,],%11[^,],%21[^\n]\n", read = fscanf(fp, "%d,%11[^,],%8[^,],%8[^,],%13[^,],%d,%d,%5[^,],%11[^,],%11[^,],%21[^\n]\n",
&pokelist[records].id, pokelist[records].name, pokelist[records].type1, pokelist[records].type2, pokelist[records].ability, &pokelist[records].height, &mainDex.pokemon[records].id, mainDex.pokemon[records].name, mainDex.pokemon[records].type1, mainDex.pokemon[records].type2, mainDex.pokemon[records].ability, &mainDex.pokemon[records].height,
&pokelist[records].weight, pokelist[records].dimorphic, pokelist[records].evolveTo, pokelist[records].evolveFrom, pokelist[records].species); &mainDex.pokemon[records].weight, mainDex.pokemon[records].dimorphic, mainDex.pokemon[records].evolveTo, mainDex.pokemon[records].evolveFrom, mainDex.pokemon[records].species);
if (read == 11) records++; if (read == 11){
records++;
}
if(read != 11){ if(read != 11){
printf("File Format Error"); printf("File Format Error");
printf("\n%d records read.\n", records); printf("\n%d records read.\n", records);
printf("%d %s %s %s %s %s %d %d %s %s %s\n", pokelist[2].id, pokelist[2].name, pokelist[2].species, pokelist[2].type1, pokelist[2].type2, pokelist[2].ability, pokelist[2].height,
pokelist[2].weight, pokelist[2].dimorphic, pokelist[2].evolveTo, pokelist[2].evolveFrom);
return 1; return 1;
} }
...@@ -53,15 +55,201 @@ int populateDex(){ ...@@ -53,15 +55,201 @@ int populateDex(){
fclose(fp); fclose(fp);
printf("\n%d records read.\n", records); printf("\n%d pokemon records read.\n", records);
}
int generateDex(int trainerID){
int i = 0;
int numMon = rand() % 300;
//printf("%d\n", numMon);
while(i <= numMon){
//printf("%s\n", mainDex.pokemon[rand() % 721].name);
mainDex.trainers[trainerID].owned[i] = mainDex.pokemon[rand() % 721];
i++;
}
return numMon;
}
void printDex(int trainerID){
int i;
printf("\n%s owns %d Pokemon. Their full PC is as follows:\n", mainDex.trainers[trainerID].name, mainDex.trainers[trainerID].totalOwned+1);
for(i=0;i<=mainDex.trainers[trainerID].totalOwned; i++){
printf("%d. %s\n", i+1, mainDex.trainers[trainerID].owned[i].name);
}
}
void printPokemon(int pokemonID){
printf("The Pokemon you are looking for is %s, the %s.\n", mainDex.pokemon[pokemonID].name, mainDex.pokemon[pokemonID].species);
if(isspace(mainDex.pokemon[pokemonID].type2[0])){
printf("%s is a %s type, ", mainDex.pokemon[pokemonID].name, mainDex.pokemon[pokemonID].type1);
}
else{
printf("%s has types %s and %s, ", mainDex.pokemon[pokemonID].name, mainDex.pokemon[pokemonID].type1, mainDex.pokemon[pokemonID].type2);
}
printf("it is %.2fm tall and %.2fkg in weight and has the ability %s. ", ((float)mainDex.pokemon[pokemonID].height/10), ((float)mainDex.pokemon[pokemonID].weight/10), mainDex.pokemon[pokemonID].ability);
if(mainDex.pokemon[pokemonID].dimorphic == "TRUE"){
printf("This Pokemon is sexually dimorphic, which means that the males and females of this species look different! ");
}else{
printf("This Pokemon isn't sexually dimorphic, which means that the males and females of this species look the same! ");
}
if(!isspace(mainDex.pokemon[pokemonID].evolveFrom[0]) && !isspace(mainDex.pokemon[pokemonID].evolveTo[0])){
printf("%s evolved from %s, and will evolve into %s.", mainDex.pokemon[pokemonID].name, mainDex.pokemon[pokemonID].evolveFrom, mainDex.pokemon[pokemonID].evolveTo);
}
else if(!isspace(mainDex.pokemon[pokemonID].evolveFrom[0]) && isspace(mainDex.pokemon[pokemonID].evolveTo[0])){
printf("%s evolved from %s.", mainDex.pokemon[pokemonID].name, mainDex.pokemon[pokemonID].evolveFrom);
}
else if(isspace(mainDex.pokemon[pokemonID].evolveFrom[0]) && !isspace(mainDex.pokemon[pokemonID].evolveTo[0])){
printf("%s will evolve into %s.", mainDex.pokemon[pokemonID].name, mainDex.pokemon[pokemonID].evolveTo);
}
else{
printf("%s has no known evolutions.", mainDex.pokemon[pokemonID].name);
}
printf("\n");
}
char* stripSpace(char* string){
char final[100];
int c = 0, d = 0;
while(string[c] != '\0')
{
if(!(string[c] == ' ' && string[c+1] == ' ')){
final[d] = string[c];
d++;
}
c++;
}
string[d] = '\0';
string[strcspn(string, "\n")] = 0;
//printf("\n%s<-ends here", string);
return string;
}
int identify(){
int choice = 0;
int arrayLength;
while(choice!='6'){
printf("\nHow would you like to identify this Pokemon?\n1. By Name\t\t2. By ID\n3. By Primary Type\t4. By Secondary Type\n5. Trainer Info\t\t6. Exit\n\nEnter Your Choice: ");
choice = getch();
printf("%d", choice);
switch(choice){
case '1':
printf("\nEnter the Pokemon's Name: ");
char str[13];
fgets(str, 13, stdin);
str[0] = toupper(str[0]);
stripSpace(str);
int count = -1;
int comparitor = 1;
char nameStr[12];
while(comparitor != 0 && count <=720){
count++;
strcpy(nameStr, mainDex.pokemon[count].name);
comparitor = strcmp(str,nameStr);
}
if(!comparitor){
printPokemon(count);
}
else{
printf("We couldn't find that Pokemon, could you check the spelling?\n");
}
break;
case '2':
printf("\nEnter the Pokemon's ID: ");
int pokeID;
scanf("%d", &pokeID);
if(1 <= pokeID && pokeID < 722){
printPokemon(pokeID-1);
}
else{
printf("That value is out of range of this Pokedex, please try a value between 1 and 721\n");
}
break;
case '3':
printf("\nEnter Pokemon Type: ");
fgets(str, 13, stdin);
str[0] = toupper(str[0]);
stripSpace(str);
count = 0;
int output = 0;
while(count < 721){
if(!strcmp(str, mainDex.pokemon[count].type1)){
printf("\n%d. %s", mainDex.pokemon[count].id, mainDex.pokemon[count].name);
output++;
}
count++;
}
if(!output){
printf("We couldn't find any with that type, did you type it correctly?\n");
}
break;
case '4':
printf("\nEnter Pokemon Type: ");
fgets(str, 13, stdin);
str[0] = toupper(str[0]);
stripSpace(str);
count = 0;
output = 0;
while(count < 721){
if(!strcmp(str, mainDex.pokemon[count].type2)){
printf("\n%d. %s", mainDex.pokemon[count].id, mainDex.pokemon[count].name);
output++;
}
count++;
}
if(!output){
printf("We couldn't find any with that type, did you type it correctly?\n");
}
break;
case '5':
arrayLength = sizeof(mainDex.trainers)/sizeof(mainDex.trainers[0]);
printf("\nWe have records for %d trainers.", arrayLength);
count = 0;
while(count <arrayLength){
printf("\n%d. %s", count+1 , mainDex.trainers[count].name);
count++;
}
printf("\nWhich would you like to know about? ");
int trainerID;
scanf("%d", &trainerID);
trainerID--;
if(trainerID > 0 && trainerID <= arrayLength){
printDex(trainerID);
}
else{
printf("\nWe do not have any records for that trainer, please enter a value between 1 and %d", arrayLength);
}
break;
case '6':
printf("\nExitting Pokedex...");
return 0;
default:
printf("\n\nInvalid Selection, please try again!\n");
}
}
return 0;
} }
int main(void){ int main(void){
printf("Loading Pokedex, please wait..."); printf("Loading Pokedex, please wait...");
populateDex(); populateDex();
strcpy(mainDex.trainers[0].name, "Ash Ketchum");
mainDex.trainers[0].totalOwned = generateDex(0);
strcpy(mainDex.trainers[1].name, "Brock Harrison");
mainDex.trainers[1].totalOwned = generateDex(1);
strcpy(mainDex.trainers[2].name, "Misty Williams");
mainDex.trainers[2].totalOwned = generateDex(2);
strcpy(mainDex.trainers[3].name, "Elizabeth Keen");
mainDex.trainers[3].totalOwned = generateDex(3);
strcpy(mainDex.trainers[4].name, "Dawn Hikari");
mainDex.trainers[4].totalOwned = generateDex(4);
identify();
} }
...@@ -718,4 +718,4 @@ ...@@ -718,4 +718,4 @@
718,Zygarde,Dragon,Ground,Aura-Break,50,3050,FALSE, , ,Order Pokemon 718,Zygarde,Dragon,Ground,Aura-Break,50,3050,FALSE, , ,Order Pokemon
719,Diancie,Rock,Fairy,Clear-Body,7,88,FALSE, , ,Jewel Pokemon 719,Diancie,Rock,Fairy,Clear-Body,7,88,FALSE, , ,Jewel Pokemon
720,HoopaHoopa,Psychic,Ghost,Magician,5,90,FALSE, , ,Mischief Pokemon 720,HoopaHoopa,Psychic,Ghost,Magician,5,90,FALSE, , ,Mischief Pokemon
721,Volcanion,Fire,Water,Water-Absorb,17,1950,FALSE, , ,Steam Pokemon 721,Volcanion,Fire,Water,Water-Absorb,17,1950,FALSE, , ,Steam Pokemon
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment