-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathZombie.php
41 lines (28 loc) · 869 Bytes
/
Zombie.php
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
<?php
class Zombie extends Individual {
public function __construct() {
parent::__construct($health = 20, $attack = 5);
$this->health = $health;
$this->attack = $attack;
}
public function bites(Human $human) {
$health = $human->getHealth();
echo 'Zombie bites Human.<br>';
echo 'Human health before bite: ' . $health . '<br>';
$health -= $this->attack;
if ($health < 0) {
$health = 0;
}
echo 'Human health after bite: ' . $health . '<br>';
$human->setHealth($health);
}
public function eats(Child $child) {
$health = $child->getHealth();
$health -= $this->attack;
if ($health < 0) {
$health = 0;
}
echo 'Zombie eats a little child. :O<br>';
$child->setHealth($health);
}
}