@Fajlworks
Thank you again for your guidance. I have been reading a few of your posts in other topics regarding card games as well. I have been working on the database and would like to share what I’ve done. Hopefully others will find this useful.
Card Class:
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Card {
public string cardName;
public int cardID;
public int cardMana;
public int cardAttack;
public int cardDefense;
public int cardSpeed;
public CardType cardType;
public SubType cardSubType;
public Faction cardFaction;
public int cardGems;
public GameObject cardPrefab;
public enum CardType{
Summon,
Chant,
Equipment
}
public enum SubType{
Creature,
Structure,
Armor,
Weapon
}
public enum Faction
{
Neutral,
Chaos,
Water,
Earth,
Wind,
}
public Card(string name, int id, int mana, int attack, int defense, int speed, CardType type, SubType subType,
Faction faction, int gems)
{
cardName = name;
cardID = id;
cardMana = mana;
cardAttack = attack;
cardDefense = defense;
cardSpeed = speed;
cardType = type;
cardSubType = subType;
cardFaction = faction;
cardGems = gems;
cardPrefab = Resources.Load<GameObject>("Prefabs/" + name);
}
}
CardDB Class:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CardDB : MonoBehaviour {
public List<Card> cards = new List<Card>();
void Start(){
cards.Add (new Card ("Annoyed Knight", 0, 1, 2, 2, 3, Card.CardType.Summon,
Card.SubType.Creature, Card.Faction.Neutral, 0));
cards.Add (new Card ("Infuriated Bear", 1, 3, 5, 4, 4, Card.CardType.Summon,
Card.SubType.Creature, Card.Faction.Neutral, 0));
cards.Add (new Card ("Ballistic Bear", 2, 4, 5, 6, 5, Card.CardType.Summon,
Card.SubType.Creature, Card.Faction.Neutral, 0));
}
}
Disclaimer: please don’t make fun of the test card names xD I’m using these for testing out vanilla creatures (creatures with no abilities).
I currently have prefabs created for each of the three cards. Each prefab has:
-a 2D box collider
-a sprite renderer
-3 text mesh child objects which represent: Attack, Defense and Mana cost
Am I on the right track?
I was wondering how I might go about creating the deck class next? Just briefly playing around with it, I have made:
Deck Class:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PlayerSummonDeck : MonoBehaviour {
public List<Card> playerSummonDeck = new List<Card>();
public CardDB database;
void Start () {
database = GameObject.FindGameObjectWithTag ("CardDB").GetComponent<CardDB>();
playerSummonDeck.Add (database.cards [0]);
}
void Update () {
}
}
I was wondering how to start expanding the deck class further? I basically want it to be that when I click on the deck it draws the top card of the list, instatiates it as the prefab and adds it to the hand. It should then remove the instatiated card from the deck. The deck should also be shuffled at the start of its creation (but I think I know how to do that).
I think this thread could become a valuable resource for those just starting out creating a card game. If you would like to continue to help me with this project I would be happy to keep posting the code I have created for others to see/use.
Thank you for all your help so far!