Skip to content

Commit 766b366

Browse files
committed
added rapid strike and magic shield skills
1 parent fc43ef4 commit 766b366

File tree

4 files changed

+64
-10
lines changed

4 files changed

+64
-10
lines changed

classes/Game.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class Game
44
{
5-
private $turns = 50; // temporary for initial commit
5+
private $turns = 20; // prevent endless battles
66

77
public $is_running = true;
88
private $first_attack = true;
@@ -58,23 +58,41 @@ public function play_round()
5858
}
5959

6060
if ($this->orderus_attacks) {
61-
$this->ui->display($this->narration->orderus_attacks());
62-
if ($this->orderus->attack($this->beast)) {
63-
$this->ui->display($this->narration->orderus_hits());
64-
} else {
65-
$this->ui->display($this->narration->orderus_misses());
61+
$attacks = $this->orderus->rapid_strike();
62+
if ($attacks > 1) {
63+
$this->ui->display($this->narration->orderus_rapid_strike());
64+
$this->ui->display_blank();
65+
}
66+
while ($attacks > 0) {
67+
$this->ui->display($this->narration->orderus_attacks());
68+
if ($this->orderus->attack($this->beast)) {
69+
$this->ui->display($this->narration->orderus_hits());
70+
} else {
71+
$this->ui->display($this->narration->orderus_misses());
72+
}
73+
$attacks--;
74+
if ($attacks > 0) {
75+
$this->display_stats();
76+
$this->ui->display_blank();
77+
}
6678
}
6779
} else {
6880
$this->ui->display($this->narration->beast_attacks());
69-
if ($this->beast->attack($this->orderus)) {
81+
$damage_divider = $this->orderus->magic_shield();
82+
if ($damage_divider > 1) {
83+
$this->ui->display_blank();
84+
$this->ui->display($this->narration->orderus_magic_shield());
85+
$this->ui->display_blank();
86+
}
87+
if ($this->beast->attack($this->orderus, $damage_divider)) {
7088
$this->ui->display($this->narration->beast_hits());
7189
} else {
7290
$this->ui->display($this->narration->beast_misses());
7391
}
7492
}
7593
$this->orderus_attacks = !$this->orderus_attacks;
7694

77-
// temporary for initial commit
95+
// prevent endless battles
7896
$this->turns--;
7997
$this->is_running = ($this->turns > 0);
8098

classes/Narration.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ public function beast_first_attack_luck()
4747
return $this->pick_narration($this->beast_first_attack_luck_narrations);
4848
}
4949

50+
public function orderus_rapid_strike()
51+
{
52+
return $this->pick_narration($this->orderus_rapid_strike_narrations);
53+
}
54+
55+
public function orderus_magic_shield()
56+
{
57+
return $this->pick_narration($this->orderus_magic_shield_narrations);
58+
}
59+
5060
public function orderus_attacks()
5161
{
5262
return $this->pick_narration($this->orderus_attacks_narrations);
@@ -140,6 +150,14 @@ public function draw()
140150
"Beast is luckier. It attacks first!"
141151
);
142152

153+
private $orderus_rapid_strike_narrations = array(
154+
"RAPID STRIKE!"
155+
);
156+
157+
private $orderus_magic_shield_narrations = array(
158+
"Orderus deflects the attack with his MAGIC SHIELD!"
159+
);
160+
143161
private $orderus_attacks_narrations = array(
144162
"Orderus attacks...",
145163
"One, two! One, two! And through and through...",

classes/Orderus.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,22 @@ public function __construct()
2727
$this->speed = rand($this->speed_min, $this->speed_max);
2828
$this->luck = rand($this->luck_min, $this->luck_max);
2929
}
30+
31+
public function rapid_strike()
32+
{
33+
$attacks = 1;
34+
if (rand(0, 100) <= 10) {
35+
$attacks = 2;
36+
}
37+
return $attacks;
38+
}
39+
40+
public function magic_shield()
41+
{
42+
$magic_shield = 1;
43+
if (rand(0, 100) <= 20) {
44+
$magic_shield = 2;
45+
}
46+
return $magic_shield;
47+
}
3048
}

classes/Player.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ public function speed()
8080
return $this->speed;
8181
}
8282

83-
public function attack($defender)
83+
public function attack($defender, $damage_divider = 1)
8484
{
8585
$chance = rand(0, 100);
8686
if ($chance < $this->luck) {
87-
$damage = $this->strength - $defender->defense;
87+
$damage = ($this->strength - $defender->defense) / $damage_divider;
8888
$defender->health -= $damage;
8989
if ($defender->health < 0) {
9090
$defender->health = 0; // it just makes more sense

0 commit comments

Comments
 (0)