diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index a7386ac..82047f6 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -35,6 +35,7 @@ public class BattleController : MonoBehaviour heroSprites[i].name = "Hero" + i + "_Sprite"; heroSprites[i].transform.position = new Vector3(-6 + 6 * i, 0, 0); BattleParticipantSprite bps = heroSprites[i].AddComponent(); + bps.Init(battlePlayerControls); BattleParticipant participant = heroes[i]; bps.OnSpriteClicked += delegate() {battlePlayerControls.OnParticipantSpriteClicked(participant);}; @@ -55,6 +56,7 @@ public class BattleController : MonoBehaviour monsterSprites[i].name = "Monster" + i + "_Sprite"; monsterSprites[i].transform.position = new Vector3(-6 + 6 * i, 3, 0); BattleParticipantSprite bps = monsterSprites[i].AddComponent(); + bps.Init(battlePlayerControls); BattleParticipant participant = monsters[i]; bps.OnSpriteClicked += delegate() {battlePlayerControls.OnParticipantSpriteClicked(participant);}; @@ -63,6 +65,7 @@ public class BattleController : MonoBehaviour } this.battlePlayerControls.OnCardUsed += this.OnCardUsed; + this.battlePlayerControls.OnTurnPassed += this.OnTurnPassed; this.battlePlayerControls.SetHand(5); } @@ -72,16 +75,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); - } - } - public void OnCardUsed(BaseCard card) { Debug.Log("OnCardClicked " + card); StartCoroutine(card.Use(battlePlayerControls)); } + + public void OnTurnPassed() { + Debug.Log("OnTurnPassed"); + } } diff --git a/Assets/Battle/BattleParticipantSprite.cs b/Assets/Battle/BattleParticipantSprite.cs index 076f2da..f7bd72b 100644 --- a/Assets/Battle/BattleParticipantSprite.cs +++ b/Assets/Battle/BattleParticipantSprite.cs @@ -7,6 +7,12 @@ public class BattleParticipantSprite : MonoBehaviour public delegate void SpriteClickedAction(); public event SpriteClickedAction OnSpriteClicked; + private BattlePlayerControls playerControls; + + public void Init(BattlePlayerControls playerControls) { + this.playerControls = playerControls; + } + // Start is called before the first frame update void Start() { gameObject.AddComponent(); @@ -14,6 +20,9 @@ public class BattleParticipantSprite : MonoBehaviour // Update is called once per frame void Update() { + if (colorChanged && !this.playerControls.IsTargeting()) { + OnMouseExit(); + } } void OnMouseDown() { @@ -22,15 +31,22 @@ public class BattleParticipantSprite : MonoBehaviour } private Color savedColor; + private bool colorChanged; void OnMouseEnter() { - SpriteRenderer sprite = GetComponent(); - this.savedColor = sprite.color; - sprite.color = Color.Lerp(this.savedColor, Color.white, .5f); + if (this.playerControls.IsTargeting()) { + SpriteRenderer sprite = GetComponent(); + this.savedColor = sprite.color; + sprite.color = Color.Lerp(this.savedColor, Color.white, .5f); + this.colorChanged = true; + } } void OnMouseExit() { - SpriteRenderer sprite = GetComponent(); - sprite.color = this.savedColor; + if (this.colorChanged) { + SpriteRenderer sprite = GetComponent(); + sprite.color = this.savedColor; + this.colorChanged = false; + } } } diff --git a/Assets/Battle/BattlePlayerControls.cs b/Assets/Battle/BattlePlayerControls.cs index ba93956..1fcab68 100644 --- a/Assets/Battle/BattlePlayerControls.cs +++ b/Assets/Battle/BattlePlayerControls.cs @@ -11,6 +11,8 @@ public class BattlePlayerControls : MonoBehaviour public delegate void CardUsedAction(BaseCard card); public event CardUsedAction OnCardUsed; + public delegate void TurnPassedAction(); + public event TurnPassedAction OnTurnPassed; private List cardsInHand; private List cardsInHandUIs; @@ -53,7 +55,9 @@ public class BattlePlayerControls : MonoBehaviour } private void OnCardClicked(BaseCard card) { - OnCardUsed(card); + if (!this.waitingForTarget) { + OnCardUsed(card); + } } private bool waitingForTarget = false; @@ -75,4 +79,14 @@ public class BattlePlayerControls : MonoBehaviour this.participantClicked = paticipant; } } + + public void PassTurnButtonClicked() { + if (!this.waitingForTarget) { + OnTurnPassed(); + } + } + + public bool IsTargeting() { + return this.waitingForTarget; + } }