From 581d9d781168d3b8f27d0a20a1e946c5a3391ceb Mon Sep 17 00:00:00 2001 From: henriquenakashima Date: Thu, 17 Sep 2020 23:31:49 -0400 Subject: [PATCH] Button to deal damage to random participant --- Assets/Battle/BattleController.cs | 8 ++++++++ Assets/Battle/BattleParticipant.cs | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index c660558..17ff644 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -61,4 +61,12 @@ public class BattleController : MonoBehaviour { } + + public void HitRandomParticipant() { + if (Random.Range(0f, 1f) < 0.5f) { + heroes[Random.Range(0, heroes.Length)].dealDamage(1); + } else { + monsters[Random.Range(0, monsters.Length)].dealDamage(2); + } + } } diff --git a/Assets/Battle/BattleParticipant.cs b/Assets/Battle/BattleParticipant.cs index 83439b7..ebe1efe 100644 --- a/Assets/Battle/BattleParticipant.cs +++ b/Assets/Battle/BattleParticipant.cs @@ -8,6 +8,10 @@ public class BattleParticipant protected int hp; protected int maxHP; + public void init() { + this.hp = this.maxHP; + } + public string getDisplayName() { return this.displayName; } @@ -20,7 +24,8 @@ public class BattleParticipant return this.maxHP; } - public void init() { - this.hp = this.maxHP; + public void dealDamage(int damage) { + this.hp -= damage; + if (this.hp < 0) this.hp = 0; } }