Create CardDatabase

This commit is contained in:
henriquenakashima 2020-09-19 00:34:27 -04:00
parent 18cfff1135
commit 246b2471f4
6 changed files with 50 additions and 17 deletions

View file

@ -2,10 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public enum CardId {
CrashingPunch
}
public enum CardType { public enum CardType {
Action Action
} }

View file

@ -7,11 +7,14 @@ public class BattleController : MonoBehaviour
public HeroId[] heroIds; public HeroId[] heroIds;
public MonsterId[] monsterIds; public MonsterId[] monsterIds;
public int maxEnergy = 6; public int maxEnergy = 6;
public CardId[] cardIds;
public HeroInfoUI heroUIPrefab; public HeroInfoUI heroUIPrefab;
public GameObject uiCanvas; public GameObject uiCanvas;
public BattlePlayerControls battlePlayerControls; public BattlePlayerControls battlePlayerControls;
private List<BaseCard> hand;
public BattleHero[] heroes; public BattleHero[] heroes;
private GameObject[] heroSprites; private GameObject[] heroSprites;
private HeroInfoUI[] heroUIs; private HeroInfoUI[] heroUIs;
@ -29,6 +32,12 @@ public class BattleController : MonoBehaviour
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
this.hand = new List<BaseCard>();
for (int i = 0; i < cardIds.Length; i++) {
BaseCard newCard = CardDatabase.CreateCard(cardIds[i]);
this.hand.Add(newCard);
}
heroes = new BattleHero[3]; heroes = new BattleHero[3];
heroSprites = new GameObject[3]; heroSprites = new GameObject[3];
heroUIs = new HeroInfoUI[3]; heroUIs = new HeroInfoUI[3];
@ -71,7 +80,7 @@ public class BattleController : MonoBehaviour
this.battlePlayerControls.OnCardUsed += this.OnCardUsed; this.battlePlayerControls.OnCardUsed += this.OnCardUsed;
this.battlePlayerControls.OnTurnPassed += this.OnTurnPassed; this.battlePlayerControls.OnTurnPassed += this.OnTurnPassed;
this.battlePlayerControls.SetHand(5); this.battlePlayerControls.SetHand(this.hand);
StartHeroTurn(); StartHeroTurn();
} }

View file

@ -29,20 +29,16 @@ public class BattlePlayerControls : MonoBehaviour
} }
public void SetHand(int numberOfCards) { public void SetHand(List<BaseCard> hand) {
this.cardsInHand = new List<BaseCard>();
this.cardsInHandUIs = new List<GameObject>(); this.cardsInHandUIs = new List<GameObject>();
for (int i = 0; i < numberOfCards; i++) { for (int i = 0; i < hand.Count; i++) {
// TODO BaseCard card = hand[i];
BaseCard newCard = new CardCrashingPunch(); GameObject cardUI = Instantiate(this.cardPrefab, this.uiCanvas.transform);
this.cardsInHand.Add(newCard); this.cardsInHandUIs.Add(cardUI);
cardUI.transform.position = CalculateCardPosition(i, hand.Count);
GameObject newCardUI = Instantiate(this.cardPrefab, this.uiCanvas.transform); cardUI.GetComponent<CardUI>().Init(card);
this.cardsInHandUIs.Add(newCardUI);
newCardUI.transform.position = CalculateCardPosition(i, numberOfCards);
newCardUI.GetComponent<CardUI>().Init(newCard);
int cardIndex = i; int cardIndex = i;
newCardUI.GetComponent<Button>().onClick.AddListener(delegate {OnCardClicked(newCard);}); cardUI.GetComponent<Button>().onClick.AddListener(delegate {OnCardClicked(card);});
} }
} }

View file

@ -304,6 +304,7 @@ MonoBehaviour:
heroIds: 010000000000000002000000 heroIds: 010000000000000002000000
monsterIds: 000000000100000000000000 monsterIds: 000000000100000000000000
maxEnergy: 6 maxEnergy: 6
cardIds: 0000000000000000000000000000000000000000
heroUIPrefab: {fileID: 6641511084601005557, guid: ef1b469b45cedee418e4c4adf577cd00, heroUIPrefab: {fileID: 6641511084601005557, guid: ef1b469b45cedee418e4c4adf577cd00,
type: 3} type: 3}
uiCanvas: {fileID: 35522588} uiCanvas: {fileID: 35522588}

View file

@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum CardId {
CrashingPunch
}
public class CardDatabase
{
public static BaseCard CreateCard(CardId id) {
switch (id)
{
case CardId.CrashingPunch:
return new CardCrashingPunch();
default:
throw new System.ArgumentException("CardId unknown", "id");
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 945fc2d9e25fa7843b9290d50f9b25e9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: