Last active
October 20, 2016 21:10
-
-
Save VictorFursa/13627951e5526cf056019afe560db4ee to your computer and use it in GitHub Desktop.
полиморф
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class Character | |
{ | |
public $lvl= 1; | |
public $name; | |
public $power; | |
public $intellect; | |
abstract function updateStat(); | |
public function __construct($name) | |
{ | |
$this->name = $name; | |
} | |
function levelUp($level) | |
{ | |
$this->lvl = $level; | |
return $this->updateStat(); | |
} | |
public function getStat() | |
{ | |
echo '<h1>' . $this->name . '</h1>'.'интелект' . $this->intellect . '<br>' . 'сила' . $this->power; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once "Character.php"; | |
class Mage extends Character | |
{ | |
public $intellect = 2; | |
public $power = 1; | |
function updateStat() | |
{ | |
$this->power = $this->lvl -1 + ($this->power + 1); | |
$this->intellect = $this->lvl * 2 + ($this->intellect ); | |
} | |
} | |
$mage = new Mage('Mage'); | |
$mage->getStat(); | |
$mage->levelUp(10); | |
$mage->getStat(); | |
$mage->levelUp(1); | |
$mage->getStat(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once "Character.php"; | |
class Warrior extends Character | |
{ | |
public $intellect = 1; | |
public $power = 2; | |
function updateStat() | |
{ | |
$this->intellect = $this->lvl -1 + ($this->intellect + 1); | |
$this->power = $this->lvl * 2 + ($this->power ); | |
} | |
} | |
$warrior = new Warrior('Warrior'); | |
$warrior->getStat(); | |
$warrior->levelUp(10); | |
$warrior->getStat(); | |
$warrior->levelUp(1); | |
$warrior->getStat(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment