-
Notifications
You must be signed in to change notification settings - Fork 0
/
6_GameObject.sol
57 lines (46 loc) · 1.21 KB
/
6_GameObject.sol
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
pragma ton-solidity >= 0.35.0;
pragma AbiHeader expire;
import './6_GameObjectInterface.sol';
contract GameObject is GameObjectInterface {
uint private health;
uint private armor;
function receiveAttack(uint value) external override {
tvm.accept();
if (value > armor) {
uint damage = value - armor;
if (damage >= health) {
health = 0;
} else {
health -= damage;
}
}
if (isDead()) {
die();
}
}
function getHealth() public returns(uint) {
return health;
}
function getArmor() public returns(uint) {
return armor;
}
function setHealth(uint newHealth) internal {
tvm.accept();
health = newHealth;
}
function setArmor(uint newArmor) internal {
tvm.accept();
armor = newArmor;
}
function isDead() private returns(bool) {
return health == 0;
}
function die() virtual internal {
tvm.accept();
withdrawFundsAndTerminate(msg.sender);
}
function withdrawFundsAndTerminate(address dest) internal {
tvm.accept();
dest.transfer(0, true, 160);
}
}