From c7d2302326bfb87dd926ecfa7b0b3d09270cf7e8 Mon Sep 17 00:00:00 2001 From: henriquenakashima Date: Sun, 20 Sep 2020 14:28:10 -0400 Subject: [PATCH] Draw monster hand --- Assets/Battle/BattleController.cs | 7 +++++-- Assets/Battle/BattlePlayerControls.cs | 16 +++++++++++----- Assets/Battle/HandControls.cs | 20 +++++++++++++++----- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index f334a98..13ca7ad 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -157,7 +157,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe hero.ResetBlock(); } - // Heroes act until they pas + // Heroes act until they pass while (!this.heroPassedTurn) { yield return null; } @@ -177,7 +177,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe monster.ResetBlock(); } - // Start of monster turn + // Monsters act until they pass List monsterHand = this.monsterDeck.GetHandPile(); for (int i = 0; i < monsterHand.Count; i++) { MonsterCard monsterCard = monsterHand[i]; @@ -185,6 +185,9 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe yield return UseMonsterCard(monsterCard); } } + + // End of monster turn + this.monsterDeck.DiscardHand(); } public void NotifyHeroCardUsed(HeroCard card) { diff --git a/Assets/Battle/BattlePlayerControls.cs b/Assets/Battle/BattlePlayerControls.cs index ebfe469..8da36d8 100644 --- a/Assets/Battle/BattlePlayerControls.cs +++ b/Assets/Battle/BattlePlayerControls.cs @@ -22,6 +22,7 @@ public class BattlePlayerControls : MonoBehaviour private PlayArea playArea; private HandControls heroHandControls; + private HandControls monsterHandControls; private Dictionary cardsInPlayUIs; public void Init( @@ -30,8 +31,10 @@ public class BattlePlayerControls : MonoBehaviour this.monsterDeck = monsterDeck; this.playArea = playArea; - this.heroHandControls = new HandControls(this.uiCanvas, this.cardPrefab); - this.heroHandControls.OnCardClicked += OnCardClicked; + this.heroHandControls = new HandControls(this.uiCanvas, this.cardPrefab, HandControlsPosition.Bottom); + this.heroHandControls.OnCardClicked += OnHeroCardClicked; + this.monsterHandControls = new HandControls(this.uiCanvas, this.cardPrefab, HandControlsPosition.Top); + this.monsterHandControls.OnCardClicked += OnMonsterCardClicked; this.cardsInPlayUIs = new Dictionary(); } @@ -52,7 +55,7 @@ public class BattlePlayerControls : MonoBehaviour // TODO } - private void OnCardClicked(HeroCard card) { + private void OnHeroCardClicked(HeroCard card) { if (this.singleTargeting == null) { if (this.battleController.CanUseHeroCard(card)) { OnCardUsed(card); @@ -60,6 +63,9 @@ public class BattlePlayerControls : MonoBehaviour } } + private void OnMonsterCardClicked(MonsterCard card) { + } + private SingleTargeting singleTargeting; public IEnumerator ChooseTarget(SingleTargeting targeting) { @@ -85,11 +91,11 @@ public class BattlePlayerControls : MonoBehaviour } public void NotifyHeroHandPileChanged() { - this.heroHandControls.SetHeroHand(this.heroDeck.GetHandPile().ToList()); + this.heroHandControls.SetHand(this.heroDeck.GetHandPile().ToList()); } public void NotifyMonsterHandPileChanged() { - SetMonsterHand(this.monsterDeck.GetHandPile().ToList()); + this.monsterHandControls.SetHand(this.monsterDeck.GetHandPile().ToList()); } private void NotifyPlayAreaChanged() { diff --git a/Assets/Battle/HandControls.cs b/Assets/Battle/HandControls.cs index dddf416..d4798bd 100644 --- a/Assets/Battle/HandControls.cs +++ b/Assets/Battle/HandControls.cs @@ -4,6 +4,11 @@ using System.Linq; using UnityEngine; using UnityEngine.UI; +public enum HandControlsPosition { + Top, + Bottom, +} + public class HandControls where BaseCardT : BaseCard { public delegate void CardClickedAction(BaseCardT card); @@ -11,15 +16,17 @@ public class HandControls where BaseCardT : BaseCard private GameObject uiCanvas; private GameObject cardPrefab; + private HandControlsPosition position; private List cardsInHandUIs; - public HandControls(GameObject uiCanvas, GameObject cardPrefab) { + public HandControls(GameObject uiCanvas, GameObject cardPrefab, HandControlsPosition position) { this.uiCanvas = uiCanvas; this.cardPrefab = cardPrefab; + this.position = position; } - public void SetHeroHand(List hand) { + public void SetHand(List hand) { if (this.cardsInHandUIs != null) { foreach (GameObject cardInHandUI in this.cardsInHandUIs) { GameObject.Destroy(cardInHandUI); @@ -42,8 +49,11 @@ public class HandControls where BaseCardT : BaseCard const int SPACING = 8; const int DELTA = BattleCardPrefabConstants.CARD_WIDTH + SPACING; - return new Vector3(Screen.width * 0.5f - DELTA / 2 * (count - 1) + DELTA * index, - SPACING + BattleCardPrefabConstants.CARD_HEIGHT / 2, - 0); + float x = Screen.width * 0.5f - DELTA / 2 * (count - 1) + DELTA * index; + float y = (this.position == HandControlsPosition.Bottom + ? SPACING + BattleCardPrefabConstants.CARD_HEIGHT / 2 + : Screen.height - SPACING - BattleCardPrefabConstants.CARD_HEIGHT / 2); + + return new Vector3(x, y, 0); } }