-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
66 lines (43 loc) · 1.29 KB
/
index.php
File metadata and controls
66 lines (43 loc) · 1.29 KB
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
<?php
spl_autoload_register(function ($class) {
$class = str_replace('OOP_assignment_2\\', '', $class);
$class = str_replace("\\", DIRECTORY_SEPARATOR, $class);
$filepath = __DIR__ . '/includes/classes/' . $class . '.php';
$filepath = str_replace("/", DIRECTORY_SEPARATOR, $filepath);
require_once $filepath;
});
echo "<h1>Fantasy Spell System</h1>";
// --- Parent Spell Instances ---
$spellOne = new Spell();
$spellOne->manaCost = 10;
$spellOne->cast();
$spellTwo = new Spell();
$spellTwo->manaCost = 25;
$spellTwo->cast();
// --- First-Level Children ---
$attackSpell = new AttackSpell();
$attackSpell->cast();
$defenseSpell = new DefenseSpell();
$defenseSpell->cast();
$healingSpell = new HealingSpell();
$healingSpell->cast();
// --- Second-Level Children ---
$fireball = new Fireball("Fireball", 120);
$lightning = new LightningStrike("Lightning Strike", 150);
$shield = new IceShield("Ice Shield", 200);
$heal = new GreaterHeal("Greater Heal", 120);
$fireball->explode();
$lightning->strike();
$shield->protect();
$heal->heal();
// --- Trait Example ---
$utilitySpell = new UtilitySpell();
$utilitySpell->cast();
// --- Type Hinting Example ---
function dumpSpell(SpellInterface $spell)
{
var_dump($spell);
}
dumpSpell($fireball);
dumpSpell($utilitySpell);
?>