anndorian
12-25-2008, 01:49 PM
Ok, I begun writing a game of cards, but not the usual stuff like 21/blackjack/poker ( altow in principle they all look the same in code). Every card has some proprietes like name, description and some special abilities.
All of that data is in a XML file.
Until now I was creatin a new Object for each card giving it the proprieties from the XML file. But I dont think this is the good solution for this kind of stuff.
I've seen the came of cards classes but all of them were heaving 2 arrays for names and values and I dont think this could be applied for what I need ( some cards have more abbilities than others ).
Could anyone give me an hint or something ?
Thanks
lordofduct
12-25-2008, 04:53 PM
What is your card game like, what is it you want your cards to do?
Your best starting place is to create a class similar to each card node of you xml... for instance if you have a xml node for each card:
<card name="jack" value="11" suit="spade" />
then you class should start with the basic interface:
public interface ICard
{
function set name( value:String ):void
function get name():String
function set value( value:int ):void
function get value():int
function set suit( value:String ):void
function get suit():String
}
Basically the same stuff you keep attaching to the Objects you create for the card. Really the purpose of the Class here in this specific instance is that you actually have these properties "typed" instead of "assumed implicitly". Now the program actually expects all Card instances to have these properties.
then build up from there for whatever stuff you usually do with your cards.
[edit]
I don't know what it is, but I've noticed that when I'm typing I am almost certain when spelling the word "your" that I actually have the 'r' at the end. And then after posting the 'r's aren't there. Am I actually not putting the 'r'? I mean I do this a lot on accident. It bugs me.
You might not need xml at all? In several games that I've created - from cards to a mahjong game I just did, I make all the properties separate arrays - faces, etc, and then created them using recursive for loops:
so you'd start with faces (4 of them) and go through each face and assign the individual values (a, 2, 3, 4, 5, etc), when you reach the end of those values, go to the next face, and start over.
This can go even deeper. In Mah Jong there are 3 sets of 9 tiles (with 4 each) and then 4 N,S,E,W tiles, and then flowers and then dragons. So I created a movie clip that contained every value, knowing that there would be 4 of each of those, and did a for loop to create 4 tiles with the first frame's value, move to the next frame, make 4 of those, etc.
Unless you've got a stack of cards where the values in each are completely different from the rest and in no way able to iterate through them, I don't know if XML is necessary. Meaning, if it's like a regular deck of cards, just build them on the fly, or if it's a stack of Pokemon cards, you're going to generate their stats somewhat at random, but within fixed ares so it might be possible to build each one at random as long as you have a starting list of the characters and the range of each of their properties:
(this isn't actionscript, it's just to give you an idea)
- characterType1: strengthRange=4-10, wisdomRange=6-10, luckRange=4-7, etc,
So then when you go through each of your characters, you'd assign their strength by getting a random number times the lower range, and add the difference between the low and high ranges.
i'm sure there's better ways to do that, but that's how I've been going about it.
Here's a link to the mah jong game, with the AS2 flash file link on there:
www.beaurocks.com/flash
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.