Skip to content

Instantly share code, notes, and snippets.

@VictorFursa
Created September 1, 2016 08:39
Show Gist options
  • Save VictorFursa/8bf810c4edfe1bbe5b034c6bcf509e69 to your computer and use it in GitHub Desktop.
Save VictorFursa/8bf810c4edfe1bbe5b034c6bcf509e69 to your computer and use it in GitHub Desktop.
Warcraft 2
<?php
abstract class Character {
public $name;
public $role;
public $level = 1;
protected $count;
abstract public function updateStats();
function __construct($name, $role,$level) {
$this->name = $name;
$this->role = $role;
$this->level = $level;
}
public function getLevel() {
return $this->level;
}
public function levelUp() {
return $this->level += $this->count;
}
}
<?php
require_once "Character.php";
class Mage extends Character
{
public function updateStats(){
if($this->role == 'mage')
{
$this->count = 10;
return $stat = [
'lvl' => [$this->level],
'characterName'=>
[$this->name],
'stat' =>
[ 'intellect' => $this->levelUp($this->level),
'power' => $this->levelUp($this->level) / 50
]
];
}
}
}
$mage = new Mage('name', 'mage',55);
echo'<pre>';
print_r($mage->updateStats());
echo'</pre>';
<?php
require_once "Character.php";
class Warrior extends Character
{
public function updateStats(){
if($this->role == 'warrior')
{
$this->count = 2.5;
return $stat = [
'lvl' => [$this->level],
'characterName'=>
[$this->name],
'stat' =>
[ 'power' => $this->levelUp($this->level),
'intellect' => $this->levelUp($this->level) / 10
]
];
}
}
}
$warrior = new Warrior('name', 'warrior',34);
echo'<pre>';
print_r($warrior->updateStats());
echo'</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment