SHOW:
|
|
- or go back to the newest paste.
1 | #include <iostream> | |
2 | #include <vector> | |
3 | #include <string> | |
4 | #include <cstdlib> | |
5 | ||
6 | using namespace std; | |
7 | ||
8 | class Entity | |
9 | { | |
10 | private: | |
11 | ||
12 | string name; | |
13 | int health; | |
14 | int maxHealth; | |
15 | int damage; | |
16 | ||
17 | public: | |
18 | ||
19 | Entity(string entityName) | |
20 | { | |
21 | name = entityName; | |
22 | maxHealth = 10; | |
23 | health = maxHealth; | |
24 | damage = 2; | |
25 | } | |
26 | ||
27 | string get_name() | |
28 | { | |
29 | return name; | |
30 | } | |
31 | ||
32 | int get_health() | |
33 | { | |
34 | return health; | |
35 | } | |
36 | ||
37 | int get_max_health() | |
38 | { | |
39 | return maxHealth; | |
40 | } | |
41 | ||
42 | int get_damage() | |
43 | { | |
44 | return damage; | |
45 | } | |
46 | ||
47 | void lower_health(int value) | |
48 | { | |
49 | health -= value; | |
50 | if (health < 0) | |
51 | { | |
52 | health = 0; | |
53 | } | |
54 | } | |
55 | void add_health(int value) | |
56 | { | |
57 | health += value; | |
58 | if (health > maxHealth) | |
59 | { | |
60 | health = maxHealth; | |
61 | } | |
62 | } | |
63 | }; | |
64 | ||
65 | class Player : public Entity | |
66 | { | |
67 | private: | |
68 | ||
69 | int metal; | |
70 | int oxygen; | |
71 | ||
72 | public: | |
73 | ||
74 | Player(string playerName) : Entity(playerName) | |
75 | { | |
76 | metal = 0; | |
77 | oxygen = 100; | |
78 | } | |
79 | ||
80 | Player() : Entity("John") | |
81 | { | |
82 | ||
83 | } | |
84 | ||
85 | int get_metal() | |
86 | { | |
87 | return metal; | |
88 | } | |
89 | ||
90 | int get_oxygen() | |
91 | { | |
92 | return oxygen; | |
93 | } | |
94 | ||
95 | void display_player_info() | |
96 | { | |
97 | cout << "Stan gracza" << endl; | |
98 | cout << "------------------------------------------------" << endl; | |
99 | cout << "Życie: " << get_health() << "/" << get_max_health() << endl; | |
100 | cout << "Atak: " << get_damage() << endl; | |
101 | cout << "Tlen: " << oxygen << "%" << endl; | |
102 | cout << "Metal: " << metal << "/50" << endl; | |
103 | } | |
104 | ||
105 | void rest() | |
106 | { | |
107 | cout << get_name() << " odpoczywa. Zużycie 2% tlenu." << endl << endl; | |
108 | lower_oxygen(2); | |
109 | add_health(5); | |
110 | display_player_info(); | |
111 | } | |
112 | ||
113 | void lower_oxygen(int value) | |
114 | { | |
115 | oxygen -= value; | |
116 | } | |
117 | ||
118 | void add_oxygen(int value) | |
119 | { | |
120 | if(oxygen + value > 100) | |
121 | { | |
122 | oxygen = 100; | |
123 | } | |
124 | else | |
125 | { | |
126 | oxygen += value; | |
127 | } | |
128 | } | |
129 | ||
130 | void add_metal(int value) | |
131 | { | |
132 | metal += value; | |
133 | } | |
134 | }; |