-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.php
More file actions
54 lines (48 loc) · 1.24 KB
/
Copy pathGame.php
File metadata and controls
54 lines (48 loc) · 1.24 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
<?php
spl_autoload_register(function ($class_name) {
include $class_name . ".php";
});
echo("Fight participants have been created.\n");
$ordeus = new Ordeus();
$beast = new Beast();
$ordeus->writeStats();
$beast->writeStats();
echo("The battle starts!\n");
if($ordeus->getSpeed()>$beast->getSpeed()){
$attacker = $ordeus;
$defender = $beast;
echo("Ordeus attacks first.\n");
}
else if($ordeus->getSpeed()<$beast->getSpeed()){
$attacker = $beast;
$defender = $ordeus;
echo("Beast attacks first.\n");
}
else{
if($ordeus->getLuck()>$beast->getLuck()){
$attacker = $ordeus;
$defender = $beast;
echo("Ordeus attacks first.\n");
}
else{
$attacker = $beast;
$defender = $ordeus;
echo("Beast attacks first.\n");
}
}
for($i = 1; $i<21;$i++){
echo("Round ".$i."\n");
$attacker->dealDamage($defender);
if($defender->getHealth()<=0){
echo(get_class($defender). " is dead.\n");
echo(get_class($attacker). " has won.\n");
$attacker->writeStats();
echo("Battle has finished.\n");
die;
}
$temp = $defender;
$defender = $attacker;
$attacker = $temp;
}
echo("We'll call it a draw.\n");
echo("Battle has finished.\n");