-
Notifications
You must be signed in to change notification settings - Fork 0
/
OOP_1.py
45 lines (36 loc) · 1.1 KB
/
OOP_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class Character():
MAX_SPEED = 100
dead_heals = 0
def __init__(self, race, armor=20, damage=10):
self.armor = armor
self.__race = race # Приватный атрибут
self.damage = damage
self._health = 100 # Защищённый атрибут
self._current_speed = 20
def hit(self, damage):
self._health -= damage
def is_dead(self):
return self._health == Character.dead_heals
@property
def health(self):
return self._health
@property
# Свойство на чтение
def race(self):
return self.__race
@property
def current_speed(self):
return self._current_speed
@current_speed.setter
# Свойство на запись
def current_speed(self, current_speed):
if current_speed < 0:
self._current_speed = 0
elif current_speed > 100:
self._current_speed = 0
else:
self._current_speed = current_speed
unit = Character('Elf')
print(unit.current_speed)
unit.current_speed = 40
print(unit.current_speed)