Pokemon Class library
Dependents: 2645_Game_Project_2
Pokemon.cpp@4:237027245058, 2017-05-02 (annotated)
- Committer:
- 200923317
- Date:
- Tue May 02 14:46:51 2017 +0000
- Revision:
- 4:237027245058
- Parent:
- 3:100f558098c0
- Child:
- 5:30f8eda741db
finished, before rework;
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 | 0:1fa2aa6d65e8 | 12 | Pokemon(5,20,Fire); |
200923317 | 0:1fa2aa6d65e8 | 13 | } |
200923317 | 0:1fa2aa6d65e8 | 14 | |
200923317 | 0:1fa2aa6d65e8 | 15 | |
200923317 | 0:1fa2aa6d65e8 | 16 | Pokemon::Pokemon(uns lvl, uns HP, PokeType type) |
200923317 | 0:1fa2aa6d65e8 | 17 | { |
200923317 | 0:1fa2aa6d65e8 | 18 | level = lvl; |
200923317 | 0:1fa2aa6d65e8 | 19 | healthPoints = HP; |
200923317 | 0:1fa2aa6d65e8 | 20 | typing = type; |
200923317 | 0:1fa2aa6d65e8 | 21 | lvlUp = 20; |
200923317 | 0:1fa2aa6d65e8 | 22 | } |
200923317 | 0:1fa2aa6d65e8 | 23 | |
200923317 | 0:1fa2aa6d65e8 | 24 | |
200923317 | 0:1fa2aa6d65e8 | 25 | void Pokemon::setType(PokeType Type) |
200923317 | 0:1fa2aa6d65e8 | 26 | { |
200923317 | 0:1fa2aa6d65e8 | 27 | typing = Type; |
200923317 | 0:1fa2aa6d65e8 | 28 | healthPoints = 20; |
200923317 | 0:1fa2aa6d65e8 | 29 | level = 5; |
200923317 | 0:1fa2aa6d65e8 | 30 | |
200923317 | 0:1fa2aa6d65e8 | 31 | } |
200923317 | 0:1fa2aa6d65e8 | 32 | |
200923317 | 0:1fa2aa6d65e8 | 33 | |
200923317 | 0:1fa2aa6d65e8 | 34 | void Pokemon::levelUp() |
200923317 | 0:1fa2aa6d65e8 | 35 | { |
200923317 | 0:1fa2aa6d65e8 | 36 | level ++; |
200923317 | 0:1fa2aa6d65e8 | 37 | healthPoints += 2; |
200923317 | 0:1fa2aa6d65e8 | 38 | exp = 0; |
200923317 | 0:1fa2aa6d65e8 | 39 | } |
200923317 | 0:1fa2aa6d65e8 | 40 | |
200923317 | 0:1fa2aa6d65e8 | 41 | std::string Pokemon::Name(void) |
200923317 | 0:1fa2aa6d65e8 | 42 | { |
200923317 | 0:1fa2aa6d65e8 | 43 | |
200923317 | 0:1fa2aa6d65e8 | 44 | char name[25]; |
200923317 | 0:1fa2aa6d65e8 | 45 | strncpy(name,pokeNames[typing].c_str(), sizeof(name)); |
200923317 | 0:1fa2aa6d65e8 | 46 | return name; |
200923317 | 0:1fa2aa6d65e8 | 47 | } |
200923317 | 0:1fa2aa6d65e8 | 48 | |
200923317 | 0:1fa2aa6d65e8 | 49 | std::string Pokemon::Type(void) |
200923317 | 0:1fa2aa6d65e8 | 50 | { |
200923317 | 0:1fa2aa6d65e8 | 51 | char typ[15]; |
200923317 | 0:1fa2aa6d65e8 | 52 | strncpy(typ,TypeString[typing].c_str(), sizeof(typ)); |
200923317 | 0:1fa2aa6d65e8 | 53 | char typeBuffer[30]; |
200923317 | 0:1fa2aa6d65e8 | 54 | sprintf(typeBuffer, "Type: %s", typ); |
200923317 | 0:1fa2aa6d65e8 | 55 | return typeBuffer; |
200923317 | 0:1fa2aa6d65e8 | 56 | } |
200923317 | 0:1fa2aa6d65e8 | 57 | |
200923317 | 0:1fa2aa6d65e8 | 58 | std::string Pokemon::HP(void) |
200923317 | 0:1fa2aa6d65e8 | 59 | { |
200923317 | 0:1fa2aa6d65e8 | 60 | char stats[50]; |
200923317 | 0:1fa2aa6d65e8 | 61 | sprintf(stats, "HP: %u", healthPoints); |
200923317 | 0:1fa2aa6d65e8 | 62 | return stats; |
200923317 | 0:1fa2aa6d65e8 | 63 | } |
200923317 | 0:1fa2aa6d65e8 | 64 | |
200923317 | 0:1fa2aa6d65e8 | 65 | std::string Pokemon::Level(void) |
200923317 | 0:1fa2aa6d65e8 | 66 | { |
200923317 | 0:1fa2aa6d65e8 | 67 | char levels[50]; |
200923317 | 0:1fa2aa6d65e8 | 68 | sprintf(levels, "Lvl:%u", level); |
200923317 | 0:1fa2aa6d65e8 | 69 | return levels; |
200923317 | 0:1fa2aa6d65e8 | 70 | } |
200923317 | 0:1fa2aa6d65e8 | 71 | |
200923317 | 2:bbd4389980c3 | 72 | int Pokemon::OpponentTurn(Pokemon e) |
200923317 | 0:1fa2aa6d65e8 | 73 | { |
200923317 | 2:bbd4389980c3 | 74 | int damage1 = e.level; |
200923317 | 2:bbd4389980c3 | 75 | if ((e.typing == Fire && typing == Water )|| (e.typing == Grass && typing == Fire) || (e.typing == Water && typing == Grass)) {//half damage |
200923317 | 2:bbd4389980c3 | 76 | damage1 = 0.5 * damage1; |
200923317 | 2:bbd4389980c3 | 77 | } else if ((e.typing == Fire && typing == Grass)||(e.typing == Grass && typing == Water)||(e.typing == Water && typing == Fire)) {//double damage |
200923317 | 2:bbd4389980c3 | 78 | damage1 = 2 * damage1; |
200923317 | 4:237027245058 | 79 | } |
200923317 | 4:237027245058 | 80 | return damage1; |
200923317 | 0:1fa2aa6d65e8 | 81 | } |
200923317 | 0:1fa2aa6d65e8 | 82 | |
200923317 | 2:bbd4389980c3 | 83 | |
200923317 | 2:bbd4389980c3 | 84 | int Pokemon::YourTurn(Pokemon e) |
200923317 | 2:bbd4389980c3 | 85 | { |
200923317 | 2:bbd4389980c3 | 86 | int damage2 = level; |
200923317 | 2:bbd4389980c3 | 87 | if ((e.typing == Fire && typing == Water )|| (e.typing == Grass && typing == Fire) || (e.typing == Water && typing == Grass)) {//double damage |
200923317 | 2:bbd4389980c3 | 88 | damage2 = 2 * damage2; |
200923317 | 2:bbd4389980c3 | 89 | } else if ((e.typing == Fire && typing == Grass)||(e.typing == Grass && typing == Water)||(e.typing == Water && typing == Fire)) {//half damage |
200923317 | 2:bbd4389980c3 | 90 | damage2 = 0.5 * damage2; |
200923317 | 4:237027245058 | 91 | } |
200923317 | 4:237027245058 | 92 | return damage2; |
200923317 | 4:237027245058 | 93 | } |
200923317 | 4:237027245058 | 94 | |
200923317 | 4:237027245058 | 95 | void Pokemon::win() |
200923317 | 4:237027245058 | 96 | { |
200923317 | 4:237027245058 | 97 | exp = exp + 20; |
200923317 | 4:237027245058 | 98 | if (exp >= lvlUp) { |
200923317 | 4:237027245058 | 99 | Pokemon::levelUp(); |
200923317 | 4:237027245058 | 100 | lvlUp = lvlUp + 10; |
200923317 | 4:237027245058 | 101 | } |
200923317 | 4:237027245058 | 102 | } |
200923317 | 4:237027245058 | 103 | |
200923317 | 4:237027245058 | 104 | int Pokemon::HPO(Pokemon e) |
200923317 | 4:237027245058 | 105 | { |
200923317 | 4:237027245058 | 106 | int HP1 = e.healthPoints; |
200923317 | 4:237027245058 | 107 | return HP1; |
200923317 | 4:237027245058 | 108 | } |
200923317 | 4:237027245058 | 109 | |
200923317 | 4:237027245058 | 110 | int Pokemon::HPA() |
200923317 | 4:237027245058 | 111 | { |
200923317 | 4:237027245058 | 112 | int HP2 = healthPoints; |
200923317 | 2:bbd4389980c3 | 113 | return HP2; |
200923317 | 4:237027245058 | 114 | } |