So I'm now a CS major after a year at school and we just made a pretty basic "database" using classes and fstream. We had to make it search for song title and print the list of five "songs" that included title,artist,length and an extra variable we decide.
So I've started to make it work with pokemon.
/*Pokemon database
Wyatt Knickerbocker
This will be able to load, eventually, all pokemon from all regions.
I'm also hoping to include extra information like breeding type.
And the ability to search for pokemon
based on type, name, et cetera.
*/
#include<fstream>
#include"pokemon.h"
using namespace std;
int loadregion(string string,pokemon pokemon[]);
int new_pokemon(pokemon pokemon[], int);
void press_enter();
main() {
int choice,current_poke = 0,exit = 0,matches = 0,poke_number;
bool good = false;
string search, filename;
pokemon region[256];
cout <<"Welcome to the kanto pokedex."<< endl;
cout <<"What region would you like?" << endl;
cin >> filename;
poke_number = loadregion(filename, region);
cin.ignore();
do{
cout << endl << endl << "Please enter an option." << endl;
cout << "Current pokemon information(1)\nFind pokemon by type(2)\nFind pokemon by breeding type(3)\nExit(0)" << endl;
cin >> choice;
switch (choice) {
case 1:
region[current_poke].print_long();
press_enter();
break;
case 2:
cout << "Please enter a type." << endl;
cin >> search;
cout << endl << endl;
for(int i = 0; i < poke_number; i++) {
good = region[i].findby_type(search);
if(good) {
region[i].print_type();
matches++;
}
}
cout << "Found " << matches << " title matches." << endl;
press_enter();
current_poke = new_pokemon(region, current_poke);
matches = 0;
break;
case 3:
cout << "Please enter breed type." << endl;
cin.ignore();
cin >> search;
for(int i = 0; i < poke_number; i++) {
good = region[i].findby_breed(search);
if(good) {
region[i].print_breed();
cout << endl;
matches++;
}
}
cout << endl << "Found " << matches << " title matches." << endl;
matches = 0;
current_poke = new_pokemon(region, current_poke);
press_enter();
break;
case 0:
exit = 1;
break;
default:
cout << choice <<" is not a valid option." << endl;
}
} while (exit == 0);
return 0;
}
int loadregion(string filename, pokemon pokemon[]) {
string name,type1,type2,breed1,breed2,dummy;
int dex,hp,atk,def,satk,sdef,spd;
int counter = 0;
filename = "poke/"+filename;
filename.append(".poke");
ifstream infile;
infile.open(filename.c_str());
cout <<"Here?" << endl;
while(!infile.fail()) {
infile >> name;
infile >> type1;
infile >> type2;
infile >> breed1;
infile >> breed2;
infile >> dex;
infile >> hp;
infile >> atk;
infile >> def;
infile >> satk;
infile >> sdef;
infile >> spd;
getline(infile,dummy);
pokemon[counter].set_data(name,type1,type2,breed1,breed2,dex,hp,atk,def,satk,sdef,spd);
counter++;
}
counter--;
return counter;
}
// Press enter
void press_enter() {
cout << endl << "Press enter to continue." << endl;
cin.ignore();
cin.ignore();
}
//select new pokemon
int new_pokemon(pokemon region[], int pokemon) {
char yn;
cout << "Would you like to pick a new pokemon?" << endl;
cin >> yn;
if(yn == 'y' || yn == 'Y') {
cout << "Please enter the pokedex number of the pokemon." << endl;
cin >> pokemon;
cout << "Thank you." << endl;
return (pokemon-1);
}
else return pokemon;
}
/*Pokemon class file.
contains all the usefull stuff.
and maybe not-so-useful.
*/
#include<iostream>
#include<string>
using namespace std;
class pokemon {
private:
string name;
string type1;
string type2;
string breed1;
string breed2;
int dexnumber;
int hp_ev;
int atk_ev;
int def_ev;
int spatk_ev;
int spdef_ev;
int spd_ev;
public:
pokemon();
void set_data(string, string, string, string, string, int, int, int, int, int, int, int);
void print_type();
void print_breed();
void print_long();
bool findby_type(string);
bool findby_letter(string);
bool findby_breed(string);
};
pokemon::pokemon() {
name = " ";
type1 = " ";
type2 = " ";
breed1 = " ";
breed2 = " ";
dexnumber = 0;
hp_ev = 0;
atk_ev = 0;
def_ev = 0;
spatk_ev = 0;
spdef_ev = 0;
spd_ev = 0;
}
void pokemon::set_data(string n, string t1, string t2, string b1, string b2, int dex, int hp, int atk, int def, int spatk, int spdef, int spd) {
name = n;
type1 = t1;
type2 = t2;
breed1 = b1;
breed2 = b2;
dexnumber = dex;
hp_ev = hp;
atk_ev = atk;
def_ev = def;
spatk_ev = spatk;
spdef_ev = spdef;
spd_ev = spd;
}
void pokemon::print_type() {
cout <<"NAME: " << name << endl;
cout <<"DEX NUMBER: " << dexnumber << endl;
cout << "TYPE: " << type1 << '/' << type2 << endl;
}
void pokemon::print_breed() {
cout << "NAME: " << name << endl;
cout <<"DEX NUMBER: " << dexnumber << endl;
cout << "BREEDS: " << breed1 << '/' << breed2 << endl;
}
void pokemon::print_long() {
cout <<"NAME: " << name << endl;
cout <<"DEX NUMBER: " << dexnumber << endl;
cout << "TYPE: " << type1 << '/' << type2 << endl;
cout << "BREEDS: " << breed1 << '/' << breed2 << endl;
cout << "EFFORT VALUES\n-------------" << endl;
cout << "HP: " << hp_ev << endl;
cout << "ATK: " << atk_ev << endl;
cout << "DEF: " << def_ev << endl;
cout << "SP ATK: " << spatk_ev << endl;
cout << "SP DEF: " << spdef_ev << endl;
cout << "SPD: " << spd_ev << endl;
}
bool pokemon::findby_type(string comp) {
if(comp == type1 || comp == type2)
return true;
else return false;
}
bool pokemon::findby_letter(string comp) {
cout <<"HAHA NOT YET!" << endl;
}
bool pokemon::findby_breed(string comp) {
if(comp == breed1 || comp == breed2)
return true;
else return false;
}
There's a couple of debug and output formatting issues, but then with just a few modifications and extra switches I can make it load different regions.
Eventually maybe I'll detail evolution chains and learned moves.