Pokemon Class library
Dependents: 2645_Game_Project_2
Pokemon.cpp
- Committer:
- 200923317
- Date:
- 2017-04-24
- Revision:
- 3:100f558098c0
- Parent:
- 2:bbd4389980c3
- Child:
- 4:237027245058
File content as of revision 3:100f558098c0:
#include "Pokemon.h" #include "mbed.h" #include "N5110.h" #include "Gamepad.h" #include "Bitmap.h" std::string pokeNames[3] = {"Charmander","Bulbasaur","Squirtle"}; std::string TypeString[3] = {"Fire", "Grass", "Water"}; Pokemon::Pokemon(void) { Pokemon(5,20,Fire); } Pokemon::Pokemon(uns lvl, uns HP, PokeType type) { level = lvl; healthPoints = HP; typing = type; lvlUp = 20; } void Pokemon::setType(PokeType Type) { typing = Type; healthPoints = 20; level = 5; } void Pokemon::XP() { if (exp >= lvlUp) { Pokemon::levelUp(); lvlUp = lvlUp + 15; } } void Pokemon::levelUp() { level ++; healthPoints += 2; exp = 0; } std::string Pokemon::Name(void) { char name[25]; strncpy(name,pokeNames[typing].c_str(), sizeof(name)); return name; } std::string Pokemon::Type(void) { char typ[15]; strncpy(typ,TypeString[typing].c_str(), sizeof(typ)); char typeBuffer[30]; sprintf(typeBuffer, "Type: %s", typ); return typeBuffer; } std::string Pokemon::HP(void) { char stats[50]; sprintf(stats, "HP: %u", healthPoints); return stats; } std::string Pokemon::Level(void) { char levels[50]; sprintf(levels, "Lvl:%u", level); return levels; } int Pokemon::OpponentTurn(Pokemon e) { int HP1 = healthPoints; int damage1 = e.level; if ((e.typing == Fire && typing == Water )|| (e.typing == Grass && typing == Fire) || (e.typing == Water && typing == Grass)) {//half damage damage1 = 0.5 * damage1; } else if ((e.typing == Fire && typing == Grass)||(e.typing == Grass && typing == Water)||(e.typing == Water && typing == Fire)) {//double damage damage1 = 2 * damage1; } HP1 = HP1 - damage1; return HP1; } int Pokemon::YourTurn(Pokemon e) { int HP2 = e.healthPoints; int damage2 = level; if ((e.typing == Fire && typing == Water )|| (e.typing == Grass && typing == Fire) || (e.typing == Water && typing == Grass)) {//double damage damage2 = 2 * damage2; } else if ((e.typing == Fire && typing == Grass)||(e.typing == Grass && typing == Water)||(e.typing == Water && typing == Fire)) {//half damage damage2 = 0.5 * damage2; } HP2 = HP2 - damage2; return HP2; }