MCPcopy Create free account
hub / github.com/ThePhD/sol2 / player

Class player

examples/source/usertype_advanced.cpp:10–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#include <iostream>
9
10struct player {
11public:
12 int bullets;
13 int speed;
14
15 player() : player(3, 100) {
16 }
17
18 player(int ammo) : player(ammo, 100) {
19 }
20
21 player(int ammo, int hitpoints)
22 : bullets(ammo), hp(hitpoints) {
23 }
24
25 void boost() {
26 speed += 10;
27 }
28
29 bool shoot() {
30 if (bullets < 1)
31 return false;
32 --bullets;
33 return true;
34 }
35
36 void set_hp(int value) {
37 hp = value;
38 }
39
40 int get_hp() const {
41 return hp;
42 }
43
44private:
45 int hp;
46};
47
48int main() {
49 std::cout << "=== usertype_advanced ===" << std::endl;

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected