Search Unity

Designing a Trading Card Game

Discussion in 'Scripting' started by Geoth21, Jan 8, 2014.

  1. Geoth21

    Geoth21

    Joined:
    Jan 8, 2014
    Posts:
    5
    Hello all! I was told to post here in the forums instead of the questions site so here it is.

    I am in the process of starting a trading card game with unity just to practice my programming skills on a project. The game is similar to magic the gathering but on a not so complicated scale. What i was contemplating and couldn't find an answer to it is, how should i go about programming the cards in order to have automatic effects.

    What i mean is, when for example i activate a creature's ability the effect should be made by the program and not by the user manually. So in order to have many effects, should i structure the program:

    Class Card and as a subclass each card of the game?
    Class Card and each unit as an entry in an XML file?
    Or a database ( i think this is the most inefficient way of doing it)
    Thanks for considering this question and reading it :D
     
  2. Sildaekar

    Sildaekar

    Joined:
    Jul 8, 2013
    Posts:
    95
    Since it's similar to MTG (the best TCG ever in my opinion) I would do something like this:

    Code (csharp):
    1.  
    2. public class card{
    3. }
    4.  
    5. public class mana : card{
    6. }
    7.  
    8. public class creature : card{
    9. }
    10.  
    11. public class spell : card{
    12. }
    13.  
    As far as the effects go, you could just do something like this in the "card" class:

    Code (csharp):
    1.  
    2. //Play the card
    3. public void Play(){
    4.   CardEffect();
    5. }
    6.  
    7. public virtual void CardEffect(){
    8. }
    9.  
    The "virtual" keyword will allow you to override the CardEffect method in other classes that inherit the "card" class.
     
  3. Geoth21

    Geoth21

    Joined:
    Jan 8, 2014
    Posts:
    5
    That was my initial thougth. But if i have 500 different behaviours for example, will i have to make 500 different classes?
     
  4. vitali15

    vitali15

    Joined:
    Jan 9, 2014
    Posts:
    5
    Hi guys i on my way to study Unity3d for ... also card trading game.
    I already done it on AndroidSDK - Archmage Lite. So now i decide to rewrite it using Unity3d.

    In original game i create cards for view on the fly. Lets say it has small image, big image as card background, cards name, cards, description, and cards costs.
    Here how it looks right now:
    $Battlements.jpg

    So generally i need way to create texture with all this together. if you asking me why - i don't won't create huge pack of all pre generated cards (more that 240). Also i do not won't load all textures at ones (i think it will cause a out of memory) .

    So what you suggestions?

    Next question: If i planning to move card by finger, make click on it and long click - what is the best Unity object for it? Button?
     
  5. Geoth21

    Geoth21

    Joined:
    Jan 8, 2014
    Posts:
    5
    I am now stuck a bit on the philosophy of unity i think as an engine. I have created my Card class and it's subclasses, but i can't wrap on my head how to create new cards via it's constructor and assign it to a gameobject. I always run on the error that classes that inherit from mono behavior can't use a constructor. Any tips?

    What i need to do is for example that my gameobject on the board needs to become the Card card = new Card("Name", 5000, "Kills 1 creature when on play") for a Card(string name, int power, string effect) type.
     
  6. Geoth21

    Geoth21

    Joined:
    Jan 8, 2014
    Posts:
    5
    Alright thanks for the answer!
     
  7. Geoth21

    Geoth21

    Joined:
    Jan 8, 2014
    Posts:
    5
    Ok tried a couple of methods but still can't get around it. I want each card that is being initialized having different name and power for example. Can't think how i can do it in an initialize function without calling a constructor. What i mean:

    Code (csharp):
    1.  
    2. public class Card : MonoBehaviour
    3. {
    4.      public string Name { get;  set; }
    5.      public int Power { get; set; }
    6.      public Sprite Image { get; set; }
    7.      public void Initialize()
    8.      {
    9.           // How to know which card do i want to initialize?
    10.           // This will hard code the stats, but how would i know which to summon?
    11.           // Should i hard code each different card in such a function and make it a prefab?
    12.            this.Name = "FireBreathingMonster";
    13.            this.Power = 1000;
    14.      }
    15. }
    16.  
    Thanks again for any help.
     
  8. vitali15

    vitali15

    Joined:
    Jan 9, 2014
    Posts:
    5
    I not sure that your card object must contain reference to Image. Imagine 500 images loaded into memory? Not cool.
    I think better store reference to image name. Also initialize better do thru reflection or any other good mechanism.
    For example you can store cards name, image, dsc and behavoir in json or xml and initialize it by demand.

    And still no body answer on my question - how build image(sprite, texture) from multiple images and texts? )
     
  9. JoshoHai

    JoshoHai

    Joined:
    Apr 16, 2016
    Posts:
    1
    I know this is 2 years old at this point. I am wanting to do the same thing. @Geoth21
    have you gotten through you project, would you kindly give me some guidance.

    Thank you!
     
    peca92sk likes this.