Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class unit{
- public $id;
- public $name;
- public $hp;
- public $armour;
- public $race;
- public function set_hp($new_hp){
- echo "<br>$this->$name, $this->$id: hp change from $this->$hp to ";
- $this->$hp=$new_hp;
- echo "$this->hp.";
- if($this->$hp<=0){
- $this->$hp=0;
- echo "<br>The unit died.";
- }
- }
- public function death_coil(){
- echo "<br>$this->$name, $this->$id got hit by a death coil.";
- if($this->$race=="ud") set_hp($this->$hp+200);
- else if($this->$race=="hum") set_hp($this->$hp-100);
- }
- public function holy_light(){
- echo "<br>$this->$name, $this->$id got holy lighted.";
- if($this->$race=="hum") set_hp($this->$hp+200);
- else if($this->$race=="ud") set_hp($this->$hp-100);
- }
- }
- class ghoul extends unit{
- public function __construct($id){
- $this->$id=$id;
- $this->$name="Ghoul";
- $this->$hp=340;
- $this->$armour=0;
- $this->$race="ud";
- echo "<br>New $this->$name, $this->$id created.";
- }
- }
- class footman extends unit{
- public function __construct($id){
- $this->$id=$id;
- $this->$name="Footman";
- $this->$hp=420;
- $this->$armour=2;
- $this->$race="hum";
- echo "<br>New $this->$name, $this->$id created.";
- }
- }
- $id=0;
- function add_footman(){
- global $id;
- $tab[$id]=new footman($id);
- $id++;
- }
- function add_ghoul(){
- global $id;
- $tab[$id]=new ghoul($id);
- $id++;
- }
- function coil($id){
- $tab[$id]->death_coil();
- if($tab[$id]->hp==0) unset($tab[$id]);
- }
- function light($id){
- $tab[$id]->holy_light();
- if($tab[$id]->hp==0) unset($tab[$id]);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement