Hi,
I'm trying to come up with a simple class hierarchy for a trading card game (tcg).
But immediatly it's obvious you can get stuck quite fast. This is what I have so far:
Library class (which contains a whole list of cards which the player can choose out to create his deck).
Deck class (which contains the stackable list of cards of his playable deck)
Hand class (list of playable cards + draw cards)
Card class -> now here I'm getting stuck.
Let's say you have a certain cost of an element (check Magic the Gathering). You might for example have 1*black and 2*white to play 1 specific card. Or I can create an enumeration of the elements or create a whole new element class.
But in the card class how do I create the cost for example?
Would it be wise to choose for a dictionary(int, elements)?
How to keep track and apply skills of the card?
Any opinion on how to create a turn/phase function?
thanks in advance
Muts
Trading Card Game Class hierarchy (xna)
Page 1 of 111 Replies - 1377 Views - Last Post: 06 December 2011 - 07:29 AM
Replies To: Trading Card Game Class hierarchy (xna)
#2
Re: Trading Card Game Class hierarchy (xna)
Posted 03 December 2011 - 08:09 AM
http://www.dreaminco...-mtg-simulator/
The above post pretty much explains my point of view on creating a card class for gaming cards. More than likely you are going to be populating the actual cards from a database of all the cards in the collection. Each card will have different things (mana, type, tapped, etc) that is going to be pulled from the database for the specific card.
In my opinion (and please note that this might be an amateur approach to this) if you are only going to have 1 card class, then the card class should take into account everything for every card type: land, creature, spell, etc. By having varying card-type classes you will only need to support stuff in the class for the type of card you are creating, such as a Land class that supports tapping and producing land, or a Creature class that will support mana cost, tapping, and attacking.
MTG is about the only system I have played, so I would not be able to offer any advice as far as other systems. As far as your example question:
Let's say you have created a Creature class. There are 5 elements, so 5 possible color costs for those, and maybe 1 more for colorless, so 6 really. My approach would be setting up a cost property for each color (6 total), with everything being enumerated. The DB would store the cost for each card in a table. And the individual card being created would be populated with the data from the DB pertaining to the costs. I hope that makes sense:/.
The above post pretty much explains my point of view on creating a card class for gaming cards. More than likely you are going to be populating the actual cards from a database of all the cards in the collection. Each card will have different things (mana, type, tapped, etc) that is going to be pulled from the database for the specific card.
In my opinion (and please note that this might be an amateur approach to this) if you are only going to have 1 card class, then the card class should take into account everything for every card type: land, creature, spell, etc. By having varying card-type classes you will only need to support stuff in the class for the type of card you are creating, such as a Land class that supports tapping and producing land, or a Creature class that will support mana cost, tapping, and attacking.
MTG is about the only system I have played, so I would not be able to offer any advice as far as other systems. As far as your example question:
Quote
Let's say you have a certain cost of an element (check Magic the Gathering). You might for example have 1*black and 2*white to play 1 specific card. Or I can create an enumeration of the elements or create a whole new element class.
Let's say you have created a Creature class. There are 5 elements, so 5 possible color costs for those, and maybe 1 more for colorless, so 6 really. My approach would be setting up a cost property for each color (6 total), with everything being enumerated. The DB would store the cost for each card in a table. And the individual card being created would be populated with the data from the DB pertaining to the costs. I hope that makes sense:/.
#3
Re: Trading Card Game Class hierarchy (xna)
Posted 03 December 2011 - 09:11 AM
Thanks for the heads up
I'll be reading/replying your post probably tomorrow as I have to go in a few minutes.
I'll be reading/replying your post probably tomorrow as I have to go in a few minutes.
#4
Re: Trading Card Game Class hierarchy (xna)
Posted 04 December 2011 - 08:02 AM
K there are a few useful things I might be using later on when I work on the UI.
But as of now I'm working only on the Business layer... It's rather a habit
So as of now I have the following classes made:
It's a start
Now for the problems:
I always learned to keep the classes independent of each other
So let's say I write my DrawHand Sub in the Hand-class... How would i make sure ingame the card is removed from deck and put in my hand? You can't just remove the card from the list deck (but virtually it should be)... Also would it be wise to make my Deck-class inherits IEnuremable?
How do I add skills to my card? And how to pay for it?
For example, you have a skill fire on a dragon card which cost 2 resources... How to add this to my card? Through a list? And how would you make the interaction?
The idea is to be able to upgrade cards through ingame money (not real currency). But for some the name should be renamed but just the image would be changed. How would I compare the 2 cards?
Thanks in advance
Muts
But as of now I'm working only on the Business layer... It's rather a habit
So as of now I have the following classes made:
- Player: Name, Health and Subs for whenever the health needs to be modified.
- Card: Name, desc, enums (element, Type, rarity)
- Creature inherits Card: Attack, Defence, Type=Creature
- Resource inherits Card: Type=Resource
- Deck: Name, Shuffle (Knuths algorithm), Ilist of Card, remove and add card Subs
- Hand: Ilist of Card
It's a start
Now for the problems:
I always learned to keep the classes independent of each other
So let's say I write my DrawHand Sub in the Hand-class... How would i make sure ingame the card is removed from deck and put in my hand? You can't just remove the card from the list deck (but virtually it should be)... Also would it be wise to make my Deck-class inherits IEnuremable?
How do I add skills to my card? And how to pay for it?
For example, you have a skill fire on a dragon card which cost 2 resources... How to add this to my card? Through a list? And how would you make the interaction?
The idea is to be able to upgrade cards through ingame money (not real currency). But for some the name should be renamed but just the image would be changed. How would I compare the 2 cards?
Thanks in advance
Muts
#5
Re: Trading Card Game Class hierarchy (xna)
Posted 04 December 2011 - 04:37 PM
The only thing I can really comment on is about adding skills...it really depends on how you are using skills for this type of game. If they are like a modifier, meaning they will add to the attack or something of the creature, then more than likely that would entail adding a property to your card class that would be able to hold this value. And if this is something that costs to do, and your player is the one paying for it through whatever means, then that would likely come from the available (mana for MTG) that the player has when you used/activated the ability, and from my amateur perspective, would come from a property for the players mana.
#6
Re: Trading Card Game Class hierarchy (xna)
Posted 05 December 2011 - 07:14 AM
Recoil, on 04 December 2011 - 04:37 PM, said:
The only thing I can really comment on is about adding skills...it really depends on how you are using skills for this type of game. If they are like a modifier, meaning they will add to the attack or something of the creature, then more than likely that would entail adding a property to your card class that would be able to hold this value. And if this is something that costs to do, and your player is the one paying for it through whatever means, then that would likely come from the available (mana for MTG) that the player has when you used/activated the ability, and from my amateur perspective, would come from a property for the players mana.
Well I was thinking about using a dictionary of (amount of mana, skill object). Problem is I'm not sure how to get the amount of mana combined with the mana type.
Also, I've been thinking and haven't yet received an answer on a post on Apphub... But my first thought was to save all the cards/skills/... in a database. Is an external database supported by xbox360? What possibilities are there to save em?
#7
Re: Trading Card Game Class hierarchy (xna)
Posted 05 December 2011 - 03:37 PM
You would be better to make an editor and use XML and IntermediateSerializer for storing your cards. It is basically the same amount work that you'll have to go through to create your cards and save them into a database but much easier to read it at run time. For a quick tutorial on using IntermediateSerializer check out this one that I wrote. You should be able to easily extend it for creating your cards, skills, etc and saving them to an XML file that will be converted to an XNB so your cards/skills are secure.
#8
Re: Trading Card Game Class hierarchy (xna)
Posted 06 December 2011 - 12:46 AM
K so xml it is 
But how about the skills? How can I implement them?
But how about the skills? How can I implement them?
#9
Re: Trading Card Game Class hierarchy (xna)
Posted 06 December 2011 - 06:06 AM
I implement skills with a class like everything else. Just have a method that will apply the skill to an object.
#10
Re: Trading Card Game Class hierarchy (xna)
Posted 06 December 2011 - 06:43 AM
You can easily serialize the skill(s) in with the rest of the card data into XML. As SixOfEleven said, just create a class to handle the skills, then maybe a couple of other classes for different types of skills as far as direct damage, healing, environmental effects, etc. Then you can easily just add references into the Card class and serialize it all together to make a nice XML file.
#11
Re: Trading Card Game Class hierarchy (xna)
Posted 06 December 2011 - 06:58 AM
K but how do you implement it in the card class?
as explained before the cost can be different types of elements. so let's say the xml would be something like
as explained before the cost can be different types of elements. so let's say the xml would be something like
<cost> <green>1</green> <red>1</red> //or <any>3</any> </cost>
#12
Re: Trading Card Game Class hierarchy (xna)
Posted 06 December 2011 - 07:29 AM
You could set up a simple class to represent a cost.
Then it's just a matter of adding this to each card based on the type of mana it requires and the amount. You could also do "any" as a member of the Enum and then do some logic for checking all current available mana types to see if the player has enough total mana to cast it.
EDIT: You'd also have to add the necessary calls to allow the IntermediateSerializer to serialize the data for the cost, and it would show up something like the following in the xml file inside the card tags.
Class Cost
{
ManaType type; // Mana type required. ManaType Enum has mana types
int amount;
public Cost(ManaType mType, int mAmount)
{
type = mType;
amount = mAmount;
}
}
Then it's just a matter of adding this to each card based on the type of mana it requires and the amount. You could also do "any" as a member of the Enum and then do some logic for checking all current available mana types to see if the player has enough total mana to cast it.
EDIT: You'd also have to add the necessary calls to allow the IntermediateSerializer to serialize the data for the cost, and it would show up something like the following in the xml file inside the card tags.
<Cost>
<ManaType>Black</ManaType>
<Amount>1</Amount>
</Cost>
This post has been edited by Kilorn: 06 December 2011 - 07:32 AM
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote








|