vault backup: 2026-04-16 08:33:48
This commit is contained in:
@@ -22,15 +22,39 @@ C approach of defining a Pokemon:
|
||||
```C
|
||||
typedef struct {
|
||||
int exp;
|
||||
int level;
|
||||
int attack;
|
||||
unsigned int hp;
|
||||
char name[];
|
||||
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:
|
||||
```C++
|
||||
class Pokemon() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user