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 UnityEngine;
public enum CardId {
CrashingPunch
}
public enum CardType {
Action
}

View file

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

View file

@ -29,20 +29,16 @@ public class BattlePlayerControls : MonoBehaviour
}
public void SetHand(int numberOfCards) {
this.cardsInHand = new List<BaseCard>();
public void SetHand(List<BaseCard> hand) {
this.cardsInHandUIs = new List<GameObject>();
for (int i = 0; i < numberOfCards; i++) {
// TODO
BaseCard newCard = new CardCrashingPunch();
this.cardsInHand.Add(newCard);
GameObject newCardUI = Instantiate(this.cardPrefab, this.uiCanvas.transform);
this.cardsInHandUIs.Add(newCardUI);
newCardUI.transform.position = CalculateCardPosition(i, numberOfCards);
newCardUI.GetComponent<CardUI>().Init(newCard);
for (int i = 0; i < hand.Count; i++) {
BaseCard card = hand[i];
GameObject cardUI = Instantiate(this.cardPrefab, this.uiCanvas.transform);
this.cardsInHandUIs.Add(cardUI);
cardUI.transform.position = CalculateCardPosition(i, hand.Count);
cardUI.GetComponent<CardUI>().Init(card);
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
monsterIds: 000000000100000000000000
maxEnergy: 6
cardIds: 0000000000000000000000000000000000000000
heroUIPrefab: {fileID: 6641511084601005557, guid: ef1b469b45cedee418e4c4adf577cd00,
type: 3}
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: