Energy works
This commit is contained in:
parent
ee8d66610e
commit
e59375bbe6
6 changed files with 178 additions and 50 deletions
|
|
@ -6,7 +6,8 @@ public class BattleController : MonoBehaviour
|
|||
{
|
||||
public HeroId[] heroIds;
|
||||
public MonsterId[] monsterIds;
|
||||
|
||||
public int maxEnergy = 6;
|
||||
|
||||
public HeroInfoUI heroUIPrefab;
|
||||
public GameObject uiCanvas;
|
||||
public BattlePlayerControls battlePlayerControls;
|
||||
|
|
@ -19,6 +20,12 @@ public class BattleController : MonoBehaviour
|
|||
private GameObject[] monsterSprites;
|
||||
private HeroInfoUI[] monsterUIs;
|
||||
|
||||
private int energy;
|
||||
|
||||
void Awake() {
|
||||
this.energy = this.maxEnergy;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
|
@ -74,11 +81,36 @@ public class BattleController : MonoBehaviour
|
|||
}
|
||||
|
||||
public void OnCardUsed(BaseCard card) {
|
||||
Debug.Log("OnCardClicked " + card);
|
||||
StartCoroutine(card.Use(battlePlayerControls));
|
||||
Debug.Log("OnCardUsed " + card);
|
||||
if (!CanUseCard(card)) {
|
||||
throw new System.InvalidOperationException("Cannot use card " + card.GetDisplayName());
|
||||
}
|
||||
StartCoroutine(UseCard(card));
|
||||
}
|
||||
|
||||
public IEnumerator UseCard(BaseCard card) {
|
||||
yield return card.Use(battlePlayerControls);
|
||||
PayCardCost(card);
|
||||
}
|
||||
|
||||
public void OnTurnPassed() {
|
||||
Debug.Log("OnTurnPassed");
|
||||
this.energy = this.maxEnergy;
|
||||
}
|
||||
|
||||
public bool CanUseCard(BaseCard card) {
|
||||
return this.energy >= card.GetCost();
|
||||
}
|
||||
|
||||
private void PayCardCost(BaseCard card) {
|
||||
this.energy -= card.GetCost();
|
||||
}
|
||||
|
||||
public int GetEnergy() {
|
||||
return this.energy;
|
||||
}
|
||||
|
||||
public int GetMaxEnergy() {
|
||||
return this.maxEnergy;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue