diff --git a/Assets/Battle/BaseCard.cs b/Assets/Battle/BaseCard.cs new file mode 100644 index 0000000..6b4ac7d --- /dev/null +++ b/Assets/Battle/BaseCard.cs @@ -0,0 +1,43 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public enum CardId { + CrashingPunch +} + +public enum CardType { + Action +} + +public abstract class BaseCard +{ + private CardId id; + private string displayName; + private int cost; + private CardType type; + private string effectText; + + public BaseCard(CardId id, string displayName, int cost, CardType type, string effectText) { + this.id = id; + this.displayName = displayName; + this.cost = cost; + this.type = type; + this.effectText = effectText; + } + + public abstract IEnumerator Use(BattlePlayerControls playerControls); + + public CardId GetId() {return id;} + public string GetDisplayName() {return displayName;} + public int GetCost() {return cost;} + public string GetDisplayType() { + switch (type) { + case CardType.Action: + return ""; + default: + throw new System.ArgumentException("CardType unknown", "cardType"); + } + } + public string GetEffectText() {return effectText;} +} diff --git a/Assets/Battle/BaseCard.cs.meta b/Assets/Battle/BaseCard.cs.meta new file mode 100644 index 0000000..6b67208 --- /dev/null +++ b/Assets/Battle/BaseCard.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e40048c9e74d54948bcbc7d7cad13e95 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index 8a4252a..a7386ac 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -29,11 +29,14 @@ public class BattleController : MonoBehaviour HeroId id = heroIds[i]; heroes[i] = new BattleHero(id); - heroes[i].init(); + heroes[i].Init(); heroSprites[i] = HeroDatabase.createHeroSprite(id); heroSprites[i].name = "Hero" + i + "_Sprite"; heroSprites[i].transform.position = new Vector3(-6 + 6 * i, 0, 0); + BattleParticipantSprite bps = heroSprites[i].AddComponent(); + BattleParticipant participant = heroes[i]; + bps.OnSpriteClicked += delegate() {battlePlayerControls.OnParticipantSpriteClicked(participant);}; heroUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI)); heroUIs[i].Init(heroSprites[i], heroes[i]); @@ -46,11 +49,14 @@ public class BattleController : MonoBehaviour MonsterId id = monsterIds[i]; monsters[i] = MonsterDatabase.createMonsterScript(id); - monsters[i].init(); + monsters[i].Init(); monsterSprites[i] = MonsterDatabase.createMonsterSprite(id); monsterSprites[i].name = "Monster" + i + "_Sprite"; monsterSprites[i].transform.position = new Vector3(-6 + 6 * i, 3, 0); + BattleParticipantSprite bps = monsterSprites[i].AddComponent(); + BattleParticipant participant = monsters[i]; + bps.OnSpriteClicked += delegate() {battlePlayerControls.OnParticipantSpriteClicked(participant);}; monsterUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI)); monsterUIs[i].Init(monsterSprites[i], monsters[i]); @@ -68,14 +74,14 @@ public class BattleController : MonoBehaviour public void HitRandomParticipant() { if (Random.Range(0f, 1f) < 0.5f) { - heroes[Random.Range(0, heroes.Length)].dealDamage(1); + heroes[Random.Range(0, heroes.Length)].DealDamage(1); } else { - monsters[Random.Range(0, monsters.Length)].dealDamage(2); + monsters[Random.Range(0, monsters.Length)].DealDamage(2); } } - public void OnCardUsed(int index) { - Debug.Log("OnCardClicked " + index); - HitRandomParticipant(); + public void OnCardUsed(BaseCard card) { + Debug.Log("OnCardClicked " + card); + StartCoroutine(card.Use(battlePlayerControls)); } } diff --git a/Assets/Battle/BattleParticipant.cs b/Assets/Battle/BattleParticipant.cs index ebe1efe..58d6eb4 100644 --- a/Assets/Battle/BattleParticipant.cs +++ b/Assets/Battle/BattleParticipant.cs @@ -8,23 +8,23 @@ public class BattleParticipant protected int hp; protected int maxHP; - public void init() { + public void Init() { this.hp = this.maxHP; } - public string getDisplayName() { + public string GetDisplayName() { return this.displayName; } - public int getHP() { + public int GetHP() { return this.hp; } - public int getMaxHP() { + public int GetMaxHP() { return this.maxHP; } - public void dealDamage(int damage) { + public void DealDamage(int damage) { this.hp -= damage; if (this.hp < 0) this.hp = 0; } diff --git a/Assets/Battle/BattleParticipantSprite.cs b/Assets/Battle/BattleParticipantSprite.cs new file mode 100644 index 0000000..076f2da --- /dev/null +++ b/Assets/Battle/BattleParticipantSprite.cs @@ -0,0 +1,36 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class BattleParticipantSprite : MonoBehaviour +{ + public delegate void SpriteClickedAction(); + public event SpriteClickedAction OnSpriteClicked; + + // Start is called before the first frame update + void Start() { + gameObject.AddComponent(); + } + + // Update is called once per frame + void Update() { + } + + void OnMouseDown() { + Debug.Log("Clicked " + this.name); + OnSpriteClicked(); + } + + private Color savedColor; + + void OnMouseEnter() { + SpriteRenderer sprite = GetComponent(); + this.savedColor = sprite.color; + sprite.color = Color.Lerp(this.savedColor, Color.white, .5f); + } + + void OnMouseExit() { + SpriteRenderer sprite = GetComponent(); + sprite.color = this.savedColor; + } +} diff --git a/Assets/Battle/BattleParticipantSprite.cs.meta b/Assets/Battle/BattleParticipantSprite.cs.meta new file mode 100644 index 0000000..d08a9f1 --- /dev/null +++ b/Assets/Battle/BattleParticipantSprite.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f53484a8e76654248a278d9cc4910f0e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Battle/BattlePlayerControls.cs b/Assets/Battle/BattlePlayerControls.cs index 8008e63..ba93956 100644 --- a/Assets/Battle/BattlePlayerControls.cs +++ b/Assets/Battle/BattlePlayerControls.cs @@ -5,13 +5,15 @@ using UnityEngine.UI; public class BattlePlayerControls : MonoBehaviour { + public BattleController battleController; public GameObject uiCanvas; public GameObject cardPrefab; - public delegate void CardUsedAction(int i); + public delegate void CardUsedAction(BaseCard card); public event CardUsedAction OnCardUsed; - private List cardsInHand; + private List cardsInHand; + private List cardsInHandUIs; // Start is called before the first frame update void Start() @@ -26,14 +28,19 @@ public class BattlePlayerControls : MonoBehaviour } public void SetHand(int numberOfCards) { - this.cardsInHand = new List(); + this.cardsInHand = new List(); + this.cardsInHandUIs = new List(); for (int i = 0; i < numberOfCards; i++) { - GameObject newCard = Instantiate(this.cardPrefab, this.uiCanvas.transform); + // TODO + BaseCard newCard = new CardCrashingPunch(); this.cardsInHand.Add(newCard); - newCard.transform.position = CalculateCardPosition(i, numberOfCards); - Button button = newCard.GetComponent