I recently started learning C++ about a week ago, and I made a bit of progress. In honor of Pokemon Go releasing, I decided to make a Pokedex with the original 151 Pokemon. So far I have 120 or so of them in there and it works PERFECTLY! (Thank goodness). I believe my code could be much more efficient and work better. I probably am using bad practices too. If I am, please feel free to tell me and if you find a problem, tell me!
Pokemon.h:
#pragma once
#include <string>
class Pokemon {
public:
std::string type;
double weight, height;
std::string Gender;
int evoLevel;
bool finalEvo;
int dexNum;
std::string name;
Pokemon(std::string name2, std::string type2, double weight2, double height2, std::string Gender2, int evoLevel2, bool finalEvo2, int dexNum2);
Pokemon();
};
Pokemon.cpp:
#include "Pokemon.h"
Pokemon::Pokemon(std::string name2, std::string type2, double weight2, double height2, std::string Gender2, int evoLevel2, bool finalEvo2, int dexNum2) {
name = name2;
type = type2;
weight = weight2;
height = height2;
Gender = Gender2;
evoLevel = evoLevel2;
finalEvo = finalEvo2;
dexNum = dexNum2;
}
//Default constructer
Pokemon::Pokemon() {
name = "Pichario";
type = "Death";
weight = 10;
height = 12;
Gender = "Male and Female";
evoLevel = 1;
finalEvo = true;
dexNum = 999;
}
main.cpp:
#include <iostream>
#include <string>
#include <vector>
#include "Pokemon.h"
int main() {
//Create Pokemon objects
Pokemon bulbasaur("Bulbasaur", "Grass and Poison", 15.2, 28, "Male and Female", 1, false, 1);
Pokemon ivysaur("Ivysaur", "Grass and Poison", 28.7, 39, "Male and Female", 2, false, 2);
Pokemon venusaur("Venusaur", "Grass and Poison", 220.5, 79, "Male and Female", 3, true, 3);
Pokemon charmander("Charmander", "Fire", 18.7, 24, "Male and Female", 1, false, 4);
Pokemon charmeleon("Charmeleon", "Fire", 41.9, 44, "Male and Female", 2, false, 5);
Pokemon charizard("Charizard", "Fire and Flying", 199.5, 67, "Male and Female", 3, true, 6);
Pokemon squirtle("Squirtle", "Water", 19.8, 20, "Male and Female", 1, false, 7);
Pokemon wartortle("Wartortle", "Water", 49.6, 39, "Male and Female", 2, false, 8);
Pokemon blastoise("Blastoise", "Water", 188.5, 63, "Male and Female", 3, true, 9);
Pokemon caterpie("Caterpie", "Bug", 6.4, 12, "Male and Female", 1, false, 10);
Pokemon metapod("Metapod", "Bug", 21.8, 28, "Male and Female", 2, false, 11);
Pokemon butterfree("Butterfree", "Bug and Flying", 70.5, 43, "Male and Female", 3, true, 12);
Pokemon weedle("Weedle", "Bug and Poison", 7.1, 12, "Male and Female", 1, false, 13);
Pokemon kakuna("Kakuna", "Bug and Poison", 22, 24, "Male and Female", 2, false, 14);
Pokemon beedrill("Beedrill", "Bug and Poison", 65, 39, "Male and Female", 3, true, 15);
Pokemon pidgey("Pidgey", "Normal and Flying", 4, 12, "Male and Female", 1, false, 16);
Pokemon pidgeotto("Pidgeotto", "Normal and Flying", 66.1, 43, "Male and Female", 2, false, 17);
Pokemon pidgeot("Pidgeot", "Normal and Flying", 87.1, 59, "Male and Female", 3, true, 18);
Pokemon rattata("Rattata", "Normal", 7.7, 12, "Male and Female", 1, false, 19);
Pokemon raticate("Raticate", "Normal", 40.8, 28, "Male and Female", 2, true, 20);
Pokemon spearow("Spearow", "Normal and Flying", 4.4, 12, "Male and Female", 1, false, 21);
Pokemon fearow("Fearow", "Normal and Flying", 83.8, 47, "Male and Female", 2, true, 22);
Pokemon ekans("Ekans", "Poison", 15.2, 79, "Male and Female", 1, false, 23);
Pokemon arbok("Arbok", "Poison", 143.3, 138, "Male and Female", 2, true, 24);
Pokemon pikachu("Pikachu", "Electric", 13.2, 16, "Male and Female", 1, false, 25);
Pokemon raichu("Raichu", "Electric", 66.1, 31, "Male and Female", 2, true, 26);
Pokemon sandshrew("Sandshrew", "Ground", 26.5, 24, "Male and Female", 1, false, 27);
Pokemon sandslash("Sandslash", "Ground", 65, 39, "Male and Female", 2, true, 28);
Pokemon nidoranf("Nidoran female", "Poison", 15.4, 16, "Female", 1, false, 29);
Pokemon nidorina("Nidorina", "Poison", 44.1, 31, "Female", 2, false, 30);
Pokemon nidoqueen("Nidoqueen", "Poison and Ground", 132.3, 51, "Female", 3, true, 31);
Pokemon nidoranm("Nidoran Male", "Poison", 19.8, 20, "Male", 1, false, 32);
Pokemon nidorino("Nidorino", "Poison", 43, 35, "Male", 2, false, 33);
Pokemon nidoking("Nidoking", "Poison and Ground", 136.7, 55, "Male", 3, true, 34);
Pokemon clefairy("Clefairy", "Fairy", 16.5, 24, "Male and Female", 1, false, 35);
Pokemon clefable("Clefable", "Fairy", 88.2, 51, "Male and Female", 2, true, 36);
Pokemon vulpix("Vulpix", "Fire", 21.8, 24, "Male and Female", 1, false, 37);
Pokemon ninetales("Ninetales", "Fire", 43.9, 43, "Male and Female", 2, true, 38);
Pokemon jigglypuff("Jigglypuff", "Normal and Fairy", 12.1, 20, "Male and Female", 1, false, 39);
Pokemon wigglytuff("Wigglytuff", "Normal and Fairy", 26.5, 39, "Male and Female", 2, true, 40);
Pokemon zubat("Zubat", "Poison and Flying", 16.5, 31, "Male and Female", 1, false, 41);
Pokemon golbat("Golbat", "Poison and Flying", 121.3, 63, "Male and Female", 2, true, 42);
Pokemon oddish("Oddish", "Grass and Poison", 11.9, 20, "Male and Female", 1, false, 43);
Pokemon gloom("Gloom", "Grass and Poison", 19, 31, "Male and Female", 2, false, 44);
Pokemon vileplume("Vileplume", "Grass and Poison", 41, 47, "Male and Female", 3, true, 45);
Pokemon paras("Paras", "Bug and Grass", 11.9, 12, "Male and Female", 1, false, 46);
Pokemon parasect("Parasect", "Bug and Grass", 65, 39, "Male and Female", 2, true, 47);
Pokemon venonat("Venonat", "Bug and Poison", 66.1, 39, "Male and Female", 1, false, 48);
Pokemon venomoth("Venomoth", "Bug and Poison", 27.6, 59, "Male and Female", 2, true, 49);
Pokemon diglett("Diglett", "Ground", 1.8, 8, "Male and Female", 1, false, 50);
Pokemon dugtrio("Dugtrio", "Ground", 73.4, 28, "Male and Female", 2, true, 51);
Pokemon meowth("Meowth", "Normal", 9.3, 16, "Male and Female", 1, false, 52);
Pokemon persian("Persian", "Normal", 70.5, 39, "Male and Female", 2, true, 53);
Pokemon psyduck("Psyduck", "Water", 43.2, 31, "Male and Female", 1, false, 54);
Pokemon golduck("Golduck", "Water", 168.9, 67, "Male and Female", 2, true, 55);
Pokemon mankey("Mankey", "Fighting", 61.7, 20, "Male and Female", 1, false, 56);
Pokemon primeape("Primeape", "Fighting", 70.5, 39, "Male and Female", 2, true, 57);
Pokemon growlithe("Growlithe", "Fire", 41.9, 28, "Male and Female", 1, false, 58);
Pokemon arcanine("Arcanine", "Fire", 341.7, 63, "Male and Female", 2, true, 59);
Pokemon poliwag("Poliwag", "Water", 27.3, 24, "Male and Female", 1, false, 60);
Pokemon poliwhirl("Poliwhirl", "Water", 44.1, 39, "Male and Female", 2, false, 61);
Pokemon poliwrath("Poliwrath", "Water and Fighting", 119, 51, "Male and Female", 3, true, 62);
Pokemon abra("Abra", "Psychic", 43, 35, "Male and Female", 1, false, 63);
Pokemon kadabra("Kadabra", "Psychic", 124.6, 51, "Male and Female", 2, false, 64);
Pokemon alakazam("Alakazam", "Psychic", 105.8, 59, "Male and Female", 3, true, 65);
Pokemon machop("Machop", "Fighting", 43, 31, "Male and Female", 1, false, 66);
Pokemon machoke("Machoke", "Fighting", 155.4, 59, "Male and Female", 2, false, 67);
Pokemon machamp("Machamp", "Fighting", 286.6, 63, "Male and Female", 3, true, 68);
Pokemon bellsprout("Bellsprout", "Grass and Poison", 8.8, 28, "Male and Female", 1, false, 69);
Pokemon weepinbell("Weepinbell", "Grass and Poison", 14.1, 39, "Male and Female", 2, false, 70);
Pokemon victreebel("Victreebel", "Grass and Poison", 34.2, 67, "Male and Female", 3, true, 71);
Pokemon tentacool("Tentacool", "Water and Poison", 100.3, 35, "Male and Female", 1, false, 72);
Pokemon tentacruel("Tentacruel", "Water and Poison", 121.3, 63, "Male and Female", 2, true, 73);
Pokemon geodude("Geodude", "Rock and Ground", 44.1, 16, "Male and Female", 1, false, 74);
Pokemon graveler("Graveler", "Rock and Ground", 231.5, 39, "Male and Female", 2, false, 75);
Pokemon golem("Golem", "Rock and Ground", 661.4, 31, "Male and Female", 3, true, 76);
Pokemon ponyta("Ponyta", "Fire", 66.1, 39, "Male and Female", 1, false, 77);
Pokemon rapidash("Rapidash", "Fire", 209.4, 67, "Male and Female", 2, true, 78);
Pokemon slowpoke("Slowpoke", "Water and Psychic", 79.4, 47, "Male and Female", 1, false, 79);
Pokemon slowbro("Slowbro", "Water and Psychic", 173.1, 63, "Male and Female", 2, true, 80);
Pokemon magnemite("Magnemite", "Electric and Steel", 13.2, 12, "Unknown", 1, false, 81);
Pokemon magneton("Magneton", "Electric and Steel", 132.3, 39, "Unknown", 2, true, 82);
Pokemon farfetchd("Farfetch'd", "Normal and Flying", 33.1, 31, "Male and Female", 1, true, 83);
Pokemon doduo("Doduo", "Normal and Flying", 86.4, 45, "Male and Female", 1, false, 84);
Pokemon dodrio("Dodrio", "Normal and Flying", 187.8, 71, "Male and Female", 2, true, 85);
Pokemon seel("Seel", "Water", 198.4, 43, "Male and Female", 1, false, 86);
Pokemon dewgong("Dewgong", "Water and Ice", 264.6, 67, "Male and Female", 2, true, 87);
Pokemon grimer("Grimer", "Poison", 66.1, 35, "Male and Female", 1, false, 88);
Pokemon muk("Muk", "Poison", 66.1, 47, "Male and Female", 2, true, 89);
Pokemon shellder("Shellder", "Water", 8.8, 12, "Male and Female", 1, false, 90);
Pokemon cloyster("Cloyster", "Water and Ice", 292.1, 59, "Male and Female", 2, true, 91);
Pokemon gastly("Gastly", "Ghost and Poison", 0.2, 51, "Male and Female", 1, false, 92);
Pokemon haunter("Haunter", "Ghost and Poison", 0.2, 63, "Male and Female", 2, false, 93);
Pokemon gangar("Gengar", "Ghost and Poison", 89.3, 59, "Male and Female", 3, true, 94);
Pokemon onix("Onix", "Rock and Ground", 463, 346, "Male and Female", 1, true, 95);
Pokemon drowzee("Drowzee", "Psychic", 71.4, 39, "Male and Female", 1, false, 96);
Pokemon hypno("Hypno", "Psychic", 166.7, 63, "Male and Female", 2, true, 97);
Pokemon krabby("Krabby", "Water", 14.3, 16, "Male and Female", 1, false, 98);
Pokemon kingler("Kingler", "Water", 132.3, 51, "Male and Female", 2, true, 99);
Pokemon voltorb("Voltorb", "Electric", 22.9, 20, "Unknown", 1, false, 100);
Pokemon electrode("Electrode", "Electric", 146.8, 47, "Male and Female", 2, true, 101);
Pokemon exeggcute("Exeggcute", "Grass and Psychic", 5.5, 16, "Male and Female", 1, false, 102);
Pokemon exeggutor("Exeggutor", "Grass and Psychic", 264.6, 79, "Male and Female", 2, true, 103);
Pokemon cubone("Cubone", "Ground", 14.3, 16, "Male and Female", 1, false, 104);
Pokemon marowak("Marowak", "Ground", 99.2, 39, "Male and Female", 2, true, 105);
Pokemon hitmonlee("Hitmonlee", "Fighting", 109.8, 59, "Male", 1, true, 106);
Pokemon hitmonchan("Hitmonchan", "Fighting", 110.7, 55, "Male", 1, true, 107);
Pokemon lickitung("Lickitung", "Normal", 144.4, 47, "Male and Female", 1, true, 108);
Pokemon koffing("Koffing", "Poison", 2.2, 24, "Male and Female", 1, false, 109);
Pokemon weezing("Weezing", "Poison", 20.9, 47, "Male and Female", 2, true, 110);
Pokemon rhyhorn("Rhyhorn", "Ground and Rock", 253.5, 39, "Male and Female", 1, false, 111);
Pokemon rhydon("Rhydon", "Ground and Rock", 264.6, 75, "Male and Female", 2, true, 112);
Pokemon chansey("Chansey", "Normal", 76.3, 43, "Female", 1, true, 113);
Pokemon tangela("Tangela", "Grass", 77.2, 39, "Male and Female", 1, true, 114);
Pokemon kangaskhan("Kangaskhan", "Normal", 176.4, 87, "Female", 1, true, 115);
Pokemon horsea("Horsea", "Water", 17.6, 16, "Male and Gender", 1, false, 116);
Pokemon seadra("Seadra", "Water", 55.1, 47, "Male and Female", 2, true, 117);
Pokemon goldeen("Goldeen", "Water", 33.1, 24, "Male and Female", 1, false, 118);
Pokemon seaking("Seaking", "Water", 86, 51, "Male and Female", 2, true, 119);
Pokemon staryu("Staryu", "Water", 76.1, 31, "Unknown", 1, false, 120);
Pokemon starmie("Starmie", "Water and Psychic", 176.4, 43, "Unknown", 2, true, 121);
Pokemon mrmime("Mr. Mime", "Fairy and Psychic", 120, 51, "Male and Female", 1, true, 122);
Pokemon scyther("Scyther", "Bug and Flying", 123.5, 59, "Male and Female", 1, true, 123);
//Create a vector with all of the pokemon
std::vector<Pokemon> pokemon = { bulbasaur, ivysaur, venusaur,
charmander, charmeleon, charizard,
squirtle, wartortle, blastoise,
caterpie, metapod, butterfree,
weedle, kakuna, beedrill,
pidgey, pidgeotto, pidgeot,
rattata, raticate,
spearow, fearow,
ekans, arbok,
pikachu, raichu,
sandshrew, sandslash,
nidoranf, nidorina, nidoqueen,
nidoranm, nidorino, nidoking,
clefairy, clefable,
vulpix, ninetales,
jigglypuff, wigglytuff,
zubat, golbat,
oddish, gloom, vileplume,
paras, parasect,
meowth, persian,
psyduck, golduck,
mankey, primeape,
growlithe, arcanine,
poliwag, poliwhirl, poliwrath,
abra, kadabra, alakazam,
machop, machoke, machamp,
bellsprout, weepinbell, victreebel,
tentacool, tentacruel,
geodude, graveler, golem,
ponyta, rapidash,
slowpoke, slowbro,
magnemite, magneton,
farfetchd,
doduo, dodrio,
seel, dewgong,
grimer, muk,
shellder, cloyster,
gastly, haunter, gangar,
onix,
drowzee, hypno,
krabby, kingler,
voltorb, electrode,
exeggcute, exeggutor,
cubone, marowak,
hitmonlee, hitmonchan,
lickitung,
koffing, weezing,
rhyhorn, rhydon,
chansey,
tangela,
kangaskhan,
horsea, seadra,
goldeen, seaking,
staryu, starmie,
mrmime,
scyther };
//Ask the user which way they would like to search
std::cout << "Welcome to the Pokedex! We have the first " << pokemon.size() + 4 << " pokemon indexed!" << std::endl;
std::cout << "Would you like to search by name, number, or type?" << std::endl;
std::string input = "";
std::cin >> input;
//make input uppercase
for (int p = 0; p < input.size(); p++) {
input[p] = toupper(input[p]);
}
//check for input
if (input == "NAME") {
//Ask for name
std::cout << "Enter the name of the pokemon" << std::endl;
std::cin >> input;
bool found = false;
//make name lowercase
for (int j = 0; j < input.length(); j++) {
input[j] = tolower(input[j]);
}
//make first letter uppercase
input[0] = toupper(input[0]);
//loop through vector
for (int i = 0; i < pokemon.size(); i++) {
//check if input is the same as a pokemon name
if (input == pokemon.at(i).name) {
std::cout << "The pokemon " << pokemon.at(i).name << " has been found!" << std::endl;
std::cout << pokemon.at(i).name << " is a " << pokemon.at(i).type << " type." << std::endl;
std::cout << pokemon.at(i).name << "'s weight and height are: " << pokemon.at(i).weight << " lbs and " << pokemon.at(i).height << " inches." << std::endl;
std::cout << pokemon.at(i).name << "'s gender is " << pokemon.at(i).Gender << std::endl;
if (pokemon.at(i).finalEvo) {
std::cout << pokemon.at(i).name << " is the final evolution in its line." << std::endl;
if (pokemon.at(i).evoLevel > 1) {
std::cout << pokemon.at(i).name << " is what " << pokemon.at(i - 1).name << " evolves into." << std::endl;
}
else {
std::cout << pokemon.at(i).name << " is the only pokemon in its evolution line" << std::endl;
}
}
else {
std::cout << pokemon.at(i).name << " evolves into " << pokemon.at(i + 1).name << std::endl;
if (pokemon.at(i).evoLevel > 1) {
std::cout << pokemon.at(i).name << " is what " << pokemon.at(i - 1).name << " evolves into." << std::endl;
}
}
found = true;
break;
}
}
//what to do if invalid pokemon is entered
if (found == false) {
std::cerr << "Pokemon not found!" << std::endl;
}
}
else if (input == "TYPE") {
//get input
std::string input = "";
std::cout << "Enter the type you would like!" << std::endl;
std::cin >> input;
//make input lowercase
for (int k = 0; k < input.size(); k++) {
input[k] = tolower(input[k]);
}
//make first letter uppercase
input[0] = toupper(input[0]);
//loop through vector
for (int i = 0; i < pokemon.size(); i++) {
//see if pokemon type contains the input
if (pokemon.at(i).type.find(input) != std::string::npos) {
std::cout << pokemon.at(i).name << " is a " << pokemon.at(i).type << " type!" << std::endl;
}
}
}
else {
std::cout << "Enter the number of the pokemon" << std::endl;
int input = 1;
std::cin >> input;
bool found = false;
std::cout << input << std::endl;
for (int i = 0; i < pokemon.size(); i++) {
//see if pokemon has same num as input
if (input == pokemon.at(i).dexNum) {
std::cout << "The pokemon " << pokemon.at(i).name << " has been found!" << std::endl;
std::cout << pokemon.at(i).name << " is a " << pokemon.at(i).type << " type." << std::endl;
std::cout << pokemon.at(i).name << "'s weight and height are: " << pokemon.at(i).weight << " lbs and " << pokemon.at(i).height << " inches." << std::endl;
std::cout << pokemon.at(i).name << "'s gender is " << pokemon.at(i).Gender << std::endl;
if (pokemon.at(i).finalEvo) {
std::cout << pokemon.at(i).name << " is the final evolution in its line." << std::endl;
if (pokemon.at(i).evoLevel > 1) {
std::cout << pokemon.at(i).name << " is what " << pokemon.at(i - 1).name << " evolves into." << std::endl;
}
else {
std::cout << pokemon.at(i).name << " is the only pokemon in its evolution line" << std::endl;
}
}
else {
std::cout << pokemon.at(i).name << " evolves into " << pokemon.at(i + 1).name << std::endl;
if (pokemon.at(i).evoLevel > 1) {
std::cout << pokemon.at(i).name << " is what " << pokemon.at(i - 1).name << " evolves into." << std::endl;
}
}
found = true;
break;
}
}
//Say pokemon wasnt
if (found == false) {
std::cerr << "Pokemon not found!" << std::endl;
}
}
return 0;
}
finalEvo
andevoLevel
logic doesn't jive well with the Eeveelutions. Jolteon (#135) does not evolve into Flareon (#136), and Eevee (#133) is not restricted to evolving into Vaporeon (#134). \$\endgroup\$