Pokemon Class library
Dependents: 2645_Game_Project_2
Pokemon.cpp
00001 #include "Pokemon.h" 00002 #include "mbed.h" 00003 #include "N5110.h" 00004 #include "Gamepad.h" 00005 #include "Bitmap.h" 00006 00007 std::string pokeNames[3] = {"Charmander","Bulbasaur","Squirtle"}; 00008 std::string TypeString[3] = {"Fire", "Grass", "Water"}; 00009 00010 Pokemon::Pokemon(void) 00011 { 00012 //Standard layout for adding information to the class 00013 Pokemon(5,20,Fire); 00014 } 00015 00016 00017 Pokemon::Pokemon(uns lvl, uns HP, PokeType type) 00018 { 00019 //setting the information given from the use of this function to use in the class 00020 level = lvl; 00021 healthPoints = HP; 00022 typing = type; 00023 lvlUp = 20; 00024 } 00025 00026 00027 void Pokemon::setType(PokeType Type) 00028 { 00029 //initial setup of partner pokemon 00030 typing = Type; 00031 healthPoints = 20; 00032 level = 5; 00033 00034 } 00035 00036 00037 void Pokemon::levelUp() 00038 { 00039 //increasing the value of the level and Health point variables, and resetting the exp variable when pokemon levels up 00040 level ++; 00041 healthPoints += 2; 00042 exp = 0; 00043 } 00044 00045 std::string Pokemon::Name(void) 00046 { 00047 //copying the Pokemon name to a character buffer 00048 char name[25]; 00049 strncpy(name,pokeNames[typing].c_str(), sizeof(name)); 00050 return name; 00051 } 00052 00053 std::string Pokemon::Type(void) 00054 { 00055 //copying the Pokemon Type to a character buffer 00056 char typ[15]; 00057 strncpy(typ,TypeString[typing].c_str(), sizeof(typ)); 00058 char typeBuffer[30]; 00059 sprintf(typeBuffer, "Type: %s", typ); 00060 return typeBuffer; 00061 } 00062 00063 std::string Pokemon::HP(void) 00064 { 00065 //copying the Pokemon Health Point stat to a character buffer 00066 char stats[50]; 00067 sprintf(stats, "HP: %u", healthPoints); 00068 return stats; 00069 } 00070 00071 std::string Pokemon::Level(void) 00072 { 00073 //copying the Pokemon level to a character buffer 00074 char levels[50]; 00075 sprintf(levels, "Lvl:%u", level); 00076 return levels; 00077 } 00078 00079 int Pokemon::OpponentTurn(Pokemon e) 00080 { 00081 //setting starting damage to 2 less than Pokemon level 00082 int damage1 = e.level-2; 00083 //comparing Pokemon types and Adjusting damage accordingly 00084 if ((e.typing == Fire && typing == Water )|| (e.typing == Grass && typing == Fire) || (e.typing == Water && typing == Grass)) {//half damage 00085 damage1 = 0.5 * damage1; 00086 } else if ((e.typing == Fire && typing == Grass)||(e.typing == Grass && typing == Water)||(e.typing == Water && typing == Fire)) {//double damage 00087 damage1 = 2 * damage1; 00088 } 00089 //returning final value for damage 00090 return damage1; 00091 } 00092 00093 00094 int Pokemon::YourTurn(Pokemon e) 00095 { 00096 //setting starting damage to 2 less than Pokemon level 00097 int damage2 = level -2; 00098 //comparing Pokemon types and Adjusting damage accordingly 00099 if ((e.typing == Fire && typing == Water )|| (e.typing == Grass && typing == Fire) || (e.typing == Water && typing == Grass)) {//double damage 00100 damage2 = 2 * damage2; 00101 } else if ((e.typing == Fire && typing == Grass)||(e.typing == Grass && typing == Water)||(e.typing == Water && typing == Fire)) {//half damage 00102 damage2 = 0.5 * damage2; 00103 } 00104 //returning final value for damage 00105 return damage2; 00106 } 00107 00108 void Pokemon::win(N5110 &lcd) 00109 { 00110 //increasing exp by 2 for a win 00111 exp = exp + 20; 00112 //Checking for level up 00113 if (exp >= lvlUp) { 00114 ///printf("levelup"); 00115 Pokemon::levelUp(); 00116 //increasing value of exp needed for level up 00117 lvlUp = lvlUp + 10; 00118 wait(1.0); 00119 lcd.clear(); 00120 lcd.printString("LEVEL UP!!",12,3); 00121 lcd.refresh(); 00122 wait(1.0); 00123 } 00124 } 00125 00126 int Pokemon::HPO(Pokemon e) 00127 { 00128 //getting value for healthpoints 00129 int HP1 = e.healthPoints; 00130 return HP1; 00131 } 00132 00133 int Pokemon::HPA() 00134 { 00135 //getting value for healthpoints 00136 int HP2 = healthPoints; 00137 return HP2; 00138 }
Generated on Thu Aug 18 2022 07:01:53 by
1.7.2