-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItem.php
More file actions
56 lines (44 loc) · 1.12 KB
/
Copy pathItem.php
File metadata and controls
56 lines (44 loc) · 1.12 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
<?php
/**
* Created by JetBrains PhpStorm.
* User: kogtev_k
* Date: 13.06.13
* Time: 19:47
* To change this template use File | Settings | File Templates.
*/
class WrongItemException extends \Exception {}
abstract class Item { //базовый класс для оружия или брони
protected $name;
protected $strength;
function __construct($name=null, $strength=null) {
if (!$name&&$strength) {
throw new WrongItemException("Имя класса не задано!");
$name="Unnamed";
}
if ($name)
$this->name=$name;
if ($strength)
$this->strength=$strength;
}
function __toString(){
return "I have $this->name with strength $this->strength\r\n";
}
function getName(){
return $this->name;
}
function setName(){
return $this->name;
}
function action(){
return $this->strength;
}
}
class weapon extends Item {
protected $name="Hand";
protected $strength=1;
}
class armor extends Item {
protected $name="NakedBody";
protected $strength=0;
}
?>