709 B
709 B
created, course, topic, related, type, status, tags
| created | course | topic | related | type | status | tags | |
|---|---|---|---|---|---|---|---|
| 2026-04-16 08:01 | lecture | 🔴 |
|
📌 Summary
[!abstract]
📝 Content
Classes
C approach of defining a Pokemon:
typedef struct {
int exp;
int level;
int attack;
int defense;
int speed;
int hp;
} Pokemon;
void upgrade(*Pokemon p, int gainedExp) {
p->exp += gainedExp;
if (p->exp >= 4000) {
p->exp -= 4000;
p->level += 1;
}
}
In C++ we use classes:
class Pokemon {
public: // visibility modifier
int exp;
int level;
int attack;
int defense;
int speed;
int hp;
void upgrade(int gainedExp) {
exp += gainedExp;
if (exp >= 4000) {
exp -= 4000;
level += 1;
}
}
}