-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlatihan_encapsulation.py
More file actions
63 lines (49 loc) · 1.97 KB
/
Copy pathlatihan_encapsulation.py
File metadata and controls
63 lines (49 loc) · 1.97 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Latihan Encapsulation ini akan menggunakan Sistem Level dan Experience
jadi ketika hero1 menyerang maka experience akan nambah dan levelnya akan naik begitupun sebaliknya
"""
class Hero:
# private class variabel
__jumlah = 0
def __init__(self, name, health, attPower, armor):
self.__name = name
self.__healthStandar = health
self.__attPowerStandar = attPower
self.__armorStandar = armor
self.__level = 1
self.__exp = 0
self.__heatlhMax = self.__healthStandar * self.__level
self.__attPower = self.__attPowerStandar * self.__level
self.__armor = self.__armorStandar * self.__level
self.__health = self.__heatlhMax
Hero.__jumlah += 1
@property
def info(self):
return "{} level {} : \n\thealth = {}/{} \n\tattack = {} \n\tarmor = {}".format(self.__name, self.__level,
self.__health,
self.__heatlhMax,
self.__attPower,
self.__armor)
@property
def gainExp(self):
pass
@gainExp.setter
def gainExp(self, addExp):
self.__exp += addExp
if self.__exp >= 100:
print(self.__name, 'level up')
self.__level += 1
self.__exp -= 100
self.__heatlhMax = self.__healthStandar * self.__level
self.__attPower = self.__attPowerStandar * self.__level
self.__armor = self.__armorStandar * self.__level
def attack(self, musuh):
self.gainExp = 299
slandar = Hero('slandar', 100, 5, 10)
axe = Hero('axe', 100, 5, 10)
print(slandar.info)
slandar.attack(axe)
slandar.attack(axe)
slandar.attack(axe)
slandar.attack(axe)
print(slandar.info)