<?php

require_once 'Character.class.php';
require_once 'Character/Wolf.class.php';
require_once 'Character/Dragon.class.php';
require_once 'Character/Human.class.php';
$character = new Character();
//output: the character was created
$character2 = new Dragon(100, 200, 3000);
$character2->attack();
//output: we attacked for 200
Example #2
0
}
class Dog extends Animal
{
    public $health = 150;
    function pet()
    {
        $this->health += 5;
        return $this;
    }
}
class Dragon extends Animal
{
    public $health = 170;
    function fly()
    {
        $this->health -= 10;
        return $this;
    }
    function displayHealth()
    {
        echo "This is a Dragon!<br>";
        parent::displayHealth();
        return $this;
    }
}
$animal = new Animal("Dog");
$animal->walk()->walk()->walk()->run()->run()->displayHealth();
$dog = new Dog("Latte");
$dog->walk()->walk()->walk()->run()->run()->pet()->displayHealth();
$dragon = new Dragon("Smaug");
$dragon->walk()->walk()->walk()->run()->run()->fly()->fly()->displayHealth();
Example #3
0
    {
        echo "Name: {$this->name}\n";
        echo "Health: {$this->health}\n";
        echo "This is the dragon!\n";
    }
    public function fly()
    {
        $this->health = $this->health - 10;
        return $this;
    }
}
$anim1 = new Animal();
$anim1->walk()->walk()->walk()->run()->run()->displayHealth();
$anim2 = new Dog();
$anim2->walk()->walk()->walk()->run()->run()->pet()->displayHealth();
$anim3 = new Dragon();
$anim3->walk()->walk()->walk()->run()->run()->fly()->fly()->displayHealth();
/*
Now, create another class called Dog that inherits everything 
that the Animal does and have, but 1) have the default health
 by 150 and 2) add a new method called pet, which when invoked,
  increase the health by 5. Have the Dog walk three times, 
  run twice, petted once, and have it display its health.
*/
/*
Now, create another classed called Dragon that inherits 
everything that the Animal does and have, but 1) have the 
default health be 170 and 2) add a new method called fly, 
which when invoked, decreased the health by 10. Have the
 Dragon walk three times, run twice, fly twice, and have it
  display its health. When the Dragon's displayHealth function
Example #4
0
class Dragon extends Animal
{
    public function __construct($name)
    {
        $this->name = $name;
        $this->hp = 170;
    }
    public function fly()
    {
        $this->hp -= 10;
    }
    public function display_hp()
    {
        parent::display_hp();
        echo "This is a dragon!";
    }
}
//-------END OF DRAGON CLASS CODE--------------//
$dragon1 = new Dragon('Eragon');
$dragon1->walk();
$dragon1->walk();
$dragon1->walk();
$dragon1->run();
$dragon1->run();
$dragon1->fly();
$dragon1->fly();
$dragon1->display_hp();
//--------TEST CODE--------------------//
$animal2 = new Animal('bob');
$animal2->fly();
//------END OF TEST-----------------//
Example #5
0
    public function pet()
    {
        $this->health += 5;
        return $this;
    }
}
//---------Dragon Class ---------//
class Dragon extends Animal
{
    public function __construct()
    {
        $this->health = 170;
    }
    function fly()
    {
        $this->health -= 10;
        return $this;
    }
    public function newHealth()
    {
        echo "This is a dragon!" . "<br>";
        $dragon_health = $this->displayHealth();
        return $dragon_health;
    }
}
$animal1 = new Animal();
$animal1->walk()->walk()->walk()->run()->run()->displayHealth();
$dog1 = new Dog();
$dog1->walk()->walk()->walk()->run()->run()->pet()->displayHealth();
$dragon1 = new Dragon();
$dragon1->walk()->walk()->walk()->run()->run()->fly()->fly()->newHealth();