Pokemon Class library
Dependents: 2645_Game_Project_2
Pokemon.cpp@8:b6c9e09401cc, 2017-05-03 (annotated)
- Committer:
- 200923317
- Date:
- Wed May 03 22:23:23 2017 +0000
- Revision:
- 8:b6c9e09401cc
- Parent:
- 7:5e2a3c3e2380
Final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
200923317 | 0:1fa2aa6d65e8 | 1 | #include "Pokemon.h" |
200923317 | 0:1fa2aa6d65e8 | 2 | #include "mbed.h" |
200923317 | 0:1fa2aa6d65e8 | 3 | #include "N5110.h" |
200923317 | 0:1fa2aa6d65e8 | 4 | #include "Gamepad.h" |
200923317 | 3:100f558098c0 | 5 | #include "Bitmap.h" |
200923317 | 2:bbd4389980c3 | 6 | |
200923317 | 0:1fa2aa6d65e8 | 7 | std::string pokeNames[3] = {"Charmander","Bulbasaur","Squirtle"}; |
200923317 | 0:1fa2aa6d65e8 | 8 | std::string TypeString[3] = {"Fire", "Grass", "Water"}; |
200923317 | 0:1fa2aa6d65e8 | 9 | |
200923317 | 0:1fa2aa6d65e8 | 10 | Pokemon::Pokemon(void) |
200923317 | 0:1fa2aa6d65e8 | 11 | { |
200923317 | 7:5e2a3c3e2380 | 12 | //Standard layout for adding information to the class |
200923317 | 0:1fa2aa6d65e8 | 13 | Pokemon(5,20,Fire); |
200923317 | 0:1fa2aa6d65e8 | 14 | } |
200923317 | 0:1fa2aa6d65e8 | 15 | |
200923317 | 0:1fa2aa6d65e8 | 16 | |
200923317 | 0:1fa2aa6d65e8 | 17 | Pokemon::Pokemon(uns lvl, uns HP, PokeType type) |
200923317 | 0:1fa2aa6d65e8 | 18 | { |
200923317 | 7:5e2a3c3e2380 | 19 | //setting the information given from the use of this function to use in the class |
200923317 | 0:1fa2aa6d65e8 | 20 | level = lvl; |
200923317 | 0:1fa2aa6d65e8 | 21 | healthPoints = HP; |
200923317 | 0:1fa2aa6d65e8 | 22 | typing = type; |
200923317 | 0:1fa2aa6d65e8 | 23 | lvlUp = 20; |
200923317 | 0:1fa2aa6d65e8 | 24 | } |
200923317 | 0:1fa2aa6d65e8 | 25 | |
200923317 | 0:1fa2aa6d65e8 | 26 | |
200923317 | 0:1fa2aa6d65e8 | 27 | void Pokemon::setType(PokeType Type) |
200923317 | 0:1fa2aa6d65e8 | 28 | { |
200923317 | 7:5e2a3c3e2380 | 29 | //initial setup of partner pokemon |
200923317 | 0:1fa2aa6d65e8 | 30 | typing = Type; |
200923317 | 0:1fa2aa6d65e8 | 31 | healthPoints = 20; |
200923317 | 0:1fa2aa6d65e8 | 32 | level = 5; |
200923317 | 0:1fa2aa6d65e8 | 33 | |
200923317 | 0:1fa2aa6d65e8 | 34 | } |
200923317 | 0:1fa2aa6d65e8 | 35 | |
200923317 | 0:1fa2aa6d65e8 | 36 | |
200923317 | 0:1fa2aa6d65e8 | 37 | void Pokemon::levelUp() |
200923317 | 0:1fa2aa6d65e8 | 38 | { |
200923317 | 7:5e2a3c3e2380 | 39 | //increasing the value of the level and Health point variables, and resetting the exp variable when pokemon levels up |
200923317 | 0:1fa2aa6d65e8 | 40 | level ++; |
200923317 | 0:1fa2aa6d65e8 | 41 | healthPoints += 2; |
200923317 | 0:1fa2aa6d65e8 | 42 | exp = 0; |
200923317 | 0:1fa2aa6d65e8 | 43 | } |
200923317 | 0:1fa2aa6d65e8 | 44 | |
200923317 | 0:1fa2aa6d65e8 | 45 | std::string Pokemon::Name(void) |
200923317 | 0:1fa2aa6d65e8 | 46 | { |
200923317 | 7:5e2a3c3e2380 | 47 | //copying the Pokemon name to a character buffer |
200923317 | 0:1fa2aa6d65e8 | 48 | char name[25]; |
200923317 | 0:1fa2aa6d65e8 | 49 | strncpy(name,pokeNames[typing].c_str(), sizeof(name)); |
200923317 | 0:1fa2aa6d65e8 | 50 | return name; |
200923317 | 0:1fa2aa6d65e8 | 51 | } |
200923317 | 0:1fa2aa6d65e8 | 52 | |
200923317 | 0:1fa2aa6d65e8 | 53 | std::string Pokemon::Type(void) |
200923317 | 0:1fa2aa6d65e8 | 54 | { |
200923317 | 7:5e2a3c3e2380 | 55 | //copying the Pokemon Type to a character buffer |
200923317 | 0:1fa2aa6d65e8 | 56 | char typ[15]; |
200923317 | 0:1fa2aa6d65e8 | 57 | strncpy(typ,TypeString[typing].c_str(), sizeof(typ)); |
200923317 | 0:1fa2aa6d65e8 | 58 | char typeBuffer[30]; |
200923317 | 0:1fa2aa6d65e8 | 59 | sprintf(typeBuffer, "Type: %s", typ); |
200923317 | 0:1fa2aa6d65e8 | 60 | return typeBuffer; |
200923317 | 0:1fa2aa6d65e8 | 61 | } |
200923317 | 0:1fa2aa6d65e8 | 62 | |
200923317 | 0:1fa2aa6d65e8 | 63 | std::string Pokemon::HP(void) |
200923317 | 0:1fa2aa6d65e8 | 64 | { |
200923317 | 7:5e2a3c3e2380 | 65 | //copying the Pokemon Health Point stat to a character buffer |
200923317 | 0:1fa2aa6d65e8 | 66 | char stats[50]; |
200923317 | 0:1fa2aa6d65e8 | 67 | sprintf(stats, "HP: %u", healthPoints); |
200923317 | 0:1fa2aa6d65e8 | 68 | return stats; |
200923317 | 0:1fa2aa6d65e8 | 69 | } |
200923317 | 0:1fa2aa6d65e8 | 70 | |
200923317 | 0:1fa2aa6d65e8 | 71 | std::string Pokemon::Level(void) |
200923317 | 0:1fa2aa6d65e8 | 72 | { |
200923317 | 7:5e2a3c3e2380 | 73 | //copying the Pokemon level to a character buffer |
200923317 | 0:1fa2aa6d65e8 | 74 | char levels[50]; |
200923317 | 0:1fa2aa6d65e8 | 75 | sprintf(levels, "Lvl:%u", level); |
200923317 | 0:1fa2aa6d65e8 | 76 | return levels; |
200923317 | 0:1fa2aa6d65e8 | 77 | } |
200923317 | 0:1fa2aa6d65e8 | 78 | |
200923317 | 2:bbd4389980c3 | 79 | int Pokemon::OpponentTurn(Pokemon e) |
200923317 | 0:1fa2aa6d65e8 | 80 | { |
200923317 | 7:5e2a3c3e2380 | 81 | //setting starting damage to 2 less than Pokemon level |
200923317 | 5:30f8eda741db | 82 | int damage1 = e.level-2; |
200923317 | 7:5e2a3c3e2380 | 83 | //comparing Pokemon types and Adjusting damage accordingly |
200923317 | 2:bbd4389980c3 | 84 | if ((e.typing == Fire && typing == Water )|| (e.typing == Grass && typing == Fire) || (e.typing == Water && typing == Grass)) {//half damage |
200923317 | 2:bbd4389980c3 | 85 | damage1 = 0.5 * damage1; |
200923317 | 2:bbd4389980c3 | 86 | } else if ((e.typing == Fire && typing == Grass)||(e.typing == Grass && typing == Water)||(e.typing == Water && typing == Fire)) {//double damage |
200923317 | 2:bbd4389980c3 | 87 | damage1 = 2 * damage1; |
200923317 | 4:237027245058 | 88 | } |
200923317 | 7:5e2a3c3e2380 | 89 | //returning final value for damage |
200923317 | 4:237027245058 | 90 | return damage1; |
200923317 | 0:1fa2aa6d65e8 | 91 | } |
200923317 | 0:1fa2aa6d65e8 | 92 | |
200923317 | 2:bbd4389980c3 | 93 | |
200923317 | 2:bbd4389980c3 | 94 | int Pokemon::YourTurn(Pokemon e) |
200923317 | 2:bbd4389980c3 | 95 | { |
200923317 | 7:5e2a3c3e2380 | 96 | //setting starting damage to 2 less than Pokemon level |
200923317 | 5:30f8eda741db | 97 | int damage2 = level -2; |
200923317 | 7:5e2a3c3e2380 | 98 | //comparing Pokemon types and Adjusting damage accordingly |
200923317 | 2:bbd4389980c3 | 99 | if ((e.typing == Fire && typing == Water )|| (e.typing == Grass && typing == Fire) || (e.typing == Water && typing == Grass)) {//double damage |
200923317 | 2:bbd4389980c3 | 100 | damage2 = 2 * damage2; |
200923317 | 2:bbd4389980c3 | 101 | } else if ((e.typing == Fire && typing == Grass)||(e.typing == Grass && typing == Water)||(e.typing == Water && typing == Fire)) {//half damage |
200923317 | 2:bbd4389980c3 | 102 | damage2 = 0.5 * damage2; |
200923317 | 4:237027245058 | 103 | } |
200923317 | 7:5e2a3c3e2380 | 104 | //returning final value for damage |
200923317 | 4:237027245058 | 105 | return damage2; |
200923317 | 4:237027245058 | 106 | } |
200923317 | 4:237027245058 | 107 | |
200923317 | 5:30f8eda741db | 108 | void Pokemon::win(N5110 &lcd) |
200923317 | 4:237027245058 | 109 | { |
200923317 | 7:5e2a3c3e2380 | 110 | //increasing exp by 2 for a win |
200923317 | 4:237027245058 | 111 | exp = exp + 20; |
200923317 | 7:5e2a3c3e2380 | 112 | //Checking for level up |
200923317 | 4:237027245058 | 113 | if (exp >= lvlUp) { |
200923317 | 8:b6c9e09401cc | 114 | ///printf("levelup"); |
200923317 | 4:237027245058 | 115 | Pokemon::levelUp(); |
200923317 | 7:5e2a3c3e2380 | 116 | //increasing value of exp needed for level up |
200923317 | 4:237027245058 | 117 | lvlUp = lvlUp + 10; |
200923317 | 5:30f8eda741db | 118 | wait(1.0); |
200923317 | 5:30f8eda741db | 119 | lcd.clear(); |
200923317 | 5:30f8eda741db | 120 | lcd.printString("LEVEL UP!!",12,3); |
200923317 | 5:30f8eda741db | 121 | lcd.refresh(); |
200923317 | 5:30f8eda741db | 122 | wait(1.0); |
200923317 | 4:237027245058 | 123 | } |
200923317 | 4:237027245058 | 124 | } |
200923317 | 4:237027245058 | 125 | |
200923317 | 4:237027245058 | 126 | int Pokemon::HPO(Pokemon e) |
200923317 | 4:237027245058 | 127 | { |
200923317 | 7:5e2a3c3e2380 | 128 | //getting value for healthpoints |
200923317 | 4:237027245058 | 129 | int HP1 = e.healthPoints; |
200923317 | 4:237027245058 | 130 | return HP1; |
200923317 | 4:237027245058 | 131 | } |
200923317 | 4:237027245058 | 132 | |
200923317 | 4:237027245058 | 133 | int Pokemon::HPA() |
200923317 | 4:237027245058 | 134 | { |
200923317 | 7:5e2a3c3e2380 | 135 | //getting value for healthpoints |
200923317 | 4:237027245058 | 136 | int HP2 = healthPoints; |
200923317 | 2:bbd4389980c3 | 137 | return HP2; |
200923317 | 4:237027245058 | 138 | } |