-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPersonnage.php
129 lines (112 loc) · 2.55 KB
/
Personnage.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/*
* Personnage.php
*
* Copyright 2015 Eric Heintzmann <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
abstract class Personnage{
protected $_id;
protected $_nom;
protected $_degats;
const CEST_MOI = 1;
const PERSONNAGE_TUE = 2;
const PERSONNAGE_FRAPPE = 3;
public function __construct(array $tab){
$this->hydrate($tab);
}
public function id(){
return $this->_id;
}
public function nom(){
return $this->_nom;
}
public function degats(){
return $this->_degats;
}
public function niveau(){
return $this->_niveau;
}
public function experience(){
return $this->_experience;
}
public function setId($id){
$id = (int) $id;
if ($id > 0){
$this->_id = $id;
}
}
public function setNom($nom){
if (is_string($nom)){
$this->_nom = $nom;
}
}
public function setDegats($degats){
$degats = (int) $degats;
if ( $degats >= 0 && $degats <= 100 ){
$this->_degats = $degats;
}
}
public function setNiveau($niveau){
$niveau = (int) $niveau;
if (niveau>=1){
$this->_niveau = $niveau;
}
}
public function setExperience($xp){
$niveau = (int) $xp;
if (xp >= 0 && xp <= 100){
$this->_experience = $niveau;
}
}
public function frapperPesonnage(Personnage $p){
if ($p->id() == $this->id()){
return self::CEST_MOI;
}
else {
return $p->recevoirDegats();
}
}
public function recevoirDegats(){
$this->setDegats($this->degats() + 5);
if ($this->degats() >= 100){
return self::PERSONNAGE_TUE;
}
else {
return self::PERSONNAGE_FRAPPE;
}
}
public function hydrate(array $tab){
foreach($tab as $key => $value){
$method = 'set'.ucfirst($key);
if (method_exists($this, $method)){
$this->$method($value);
}
}
}
public static function nomValide($nom){
if (is_string($nom) && !empty($nom)){
return true;
}
else {
return false;
}
}
}
?>