Creating cards for a card game

So I'm playing with the idea of putting together a simple battle card playing game and am running up against a data/code issue. In the game will be various Cards (potentially hundreds). Each card will have some data describing various its strengths and it may also have complex methods that handle what happens when you play the card.
(I'd like each Card implementation to represent what the card does, as opposed to who may hold a particular copy of it. For example, I'd like to have a unique JackOfDiamondsCard object that represents info specific to the card. I may then have several Hands that contain CardInstance objects, some of which may have a reference to the unique JackOfDiamondsCard object. Thus the JackOfDiamonsCard could appear in multiple hands.)
At first glance it's a simple case of having a root Card class and hundreds of children that fill out the details. However, this has the problem that I can create many instances of the same card, which both seems like a waste of memory (since all instances would have exactly the same data) and would make equals() and hashCode() give different results for different instances of the same card.
One way around this is to put all the cards together into a single enum, but that would quickly grow to an unmanagable (and unreadable) size. I'd also like to be able to group the cards into different packages, or maybe even spread them across several jars.
Another way may be to turn each card into a singleton and then build an index of all the cards in the jar (maybe using @annotations?) This seems kind of complicated, though, and writing all those singletons would make for a lot of boilerplate in each card class.
Any ideas on a good way to tackle this? Are singletons the way to go or should I put up with potentially multiple copies of the same card object floating around?

Mark_McKay wrote:
The problem is that I need the overriding classes to provide some fairly complex code for each card. In a battle card game, there may be several different things in play that each card could alter in a wacky way. One card may give the player more 'energy points'. Another may strike the opponent with lightning damage. A third may cause one player to randomly steal a card from the other player. A fourth could set up some sort of defense barrier. The wide (and unpredictable) range things that each card may do prevent me from creating just one generic card class. (Although that would work well if the cards only differed by their data).Allow me to introduce some friends of mine. Probably the first one is going to be easiest for you to understand and get working quickly. The last one, probably only any use in conjunction with one of the others here.
This wacky behaviour is really just another property of the card, like it's suit, or name, or whatever. Behaviours, like data, can often be assigned to objects at runtime, rather than expressed with unweildy inheritance trees.

Similar Messages

  • Exchange Apple Store card for iTunes card

    I got an Apple Store giftcard for Christmas but I would get more use out of an iTunes gift card. Is there a way to exhange them over the phone or online? There is no Apple Store close to where I live.

    Apple stores are unlikely to exchange them, nor to allow you to buy iTunes gift cards them (most stores don't allow you to use gift cards to buy gift cards).
    You could try contacting iTunes Support and see if they can help : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption
    Or you could try selling them (e.g. to family, friends, locally, eBay etc) and using the proceeds to buy iTunes cards

  • Smart Card and  Java Card (URGENT)

    Dear everyone.
    I have purchased a card reader (which is supposed to be java card compatible).
    I have 2 problems.
    1. I just wonder if i can use a Smart Card generally available. Do i need to have a special card for Java Card??
    2. Can i use card kit to interface to the reader/writer? How do i install my applets??
    Please reply soon.
    Thank you very much.

    I tried to execute the OCF samples.
    this code
    OpenCard.services = com.ibm.opencard.factory.MFCCardServiceFactory
    did not give any trouble
    this code
    OpenCard.terminals = com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminalFactory
    gave some troubles. May be because iam not using ibm terminal(card).
    And also, i think the OCF samples will not work anyhow, because the Reflex reader is not OCF complaint.
    So the following may not work
    OpenCard.services = com.slb.opencard.Cyberflex
    I have most imp. questions to ask you now.
    1. What card should i purchase and from whom (along with some software if necessary)?
    2. What is the procedure for reading/writing to that card using the Reflex reader.
    Please help.
    Thanks
    Goldy.

  • Making music for commercial video game with Garage Band?

    Can I use Garage Band and it's istruments/DLC instrument packs to create music for a commercial game?
    Is the music mine mine MINE? Or do I have to pay royalties to Apple?

    Not only that, but you are free to use the Apple loops, too. Warning: Some large commercial firms have used Garageband for the same purpose and they have sometimes issued YouTube take down notices thinking that you are copying their content when you use some parts of GB.

  • ActionScript for Random Card Game

    Hello helpful user:
    I am fairly new to scripting in Flash and am struggling big time with a game I'm creating.
    An overiview of the game might help: It is a matching/Poker game. The first level requires one to beat a random pair of cards by selecting cards that are face down on the stage to drag and drop into a designated slot before the time runs out. Second level is a three of a kind, third is a flush, fourth is a straight , fifth is a full house, then four of a kind, then straight flush.
    I have the cards already on stage, set as movieclips and instance names reflecting there value (number,suit). You double click to flip the card. Drag and drop. Beat the presented hand to progress forward. Pretty basic, in theory.
    Where I am struggling is how to have the cards appear in randomized spots on stage. I also want the "hand to beat" to be selected from the cards already on stage, but randomly(except for the largest pair so it doesn't accidentally make it so you can't win). And lastly, how can I make it so it will recognize when the "hand to beat" has been beaten and one can advance.
    I'm afraid it will require 'if' statements and arrays, which I am still learning how to manipulate. I know what I want, but can't visualize the code to accomplish it. Please Help!
    Thank You!

    sorry, the actionscript i have so far for the pairs is as follows:
    bcJs.addEventListener(Event.ENTER_FRAME, goCoverjaxSpade);
    function goCoverjaxSpade(e:Event)
        bcJs.x = jaxSpade.x;
        bcJs.y = jaxSpade.y;
    bcJs.doubleClickEnabled = true;
    bcJs.addEventListener(MouseEvent.DOUBLE_CLICK, goDimbcJs);
    function goDimbcJs(e:MouseEvent)
        bcJs.scaleX = .01;
        bcJs.scaleY = .01;
        trace("disappear");
    bcJh.addEventListener(Event.ENTER_FRAME, coverbcJh);
    function coverbcJh(e:Event)
        bcJh.x = jaxHeart.x;
        bcJh.y = jaxHeart.y;
    bcJh.doubleClickEnabled = true;
    bcJh.addEventListener(MouseEvent.DOUBLE_CLICK, goDimbcJh);
    function goDimbcJh(e:MouseEvent)
        bcJh.scaleX = .01;
        bcJh.scaleY = .01;
        trace("disappear");
    jaxHeart.doubleClickEnabled = true;
    jaxHeart.addEventListener(MouseEvent.MOUSE_DOWN, itsPressedjaxHeart);
    jaxHeart.addEventListener(MouseEvent.MOUSE_UP, letGojaxHeart);
    jaxHeart.addEventListener(MouseEvent.DOUBLE_CLICK, reAppearbcJh);
    function reAppearbcJh(e:MouseEvent)
        bcJh.scaleX = .99;
        bcJh.scaleY = .99;
        trace("reappear");
    function itsPressedjaxHeart(e:MouseEvent)
        e.target.startDrag();
    function letGojaxHeart(e:MouseEvent)
        e.target.stopDrag();
        if (jaxHeart.hitTestObject(pairSlot1))
            jaxHeart.x = pairSlot1.x;
            jaxHeart.y = pairSlot1.y;
    jaxSpade.doubleClickEnabled = true;
    jaxSpade.addEventListener(MouseEvent.DOUBLE_CLICK, reAppearbcJs);
    jaxSpade.addEventListener(MouseEvent.MOUSE_DOWN, itsPressedjaxSpade);
    jaxSpade.addEventListener(MouseEvent.MOUSE_UP, letGojaxSpade);
    function reAppearbcJs(e:MouseEvent)
        bcJs.scaleX = .99;
        bcJs.scaleY = .99;
        trace("reappear");
    function itsPressedjaxSpade(e:MouseEvent)
        e.target.startDrag();
    function letGojaxSpade(e:MouseEvent)
        e.target.stopDrag();
        if (jaxSpade.hitTestObject(pairSlot2))
            jaxSpade.x = pairSlot2.x;
            jaxSpade.y = pairSlot2.y;

  • Purchased Itunes card..Have balance on my itunes account but trying to use the balance for an APP game...how do i transfer the funds ?

    I had a itunes card purchased for me...I redeemed it on my iphone in the Itunes APP...shows it was redeemed succesfully.Want to use the balance for an APP game i have....SImpsons Tapped out...hoe do i transfer it to it . it keeps using my credit card for purchasing premium items...how do i fix this to the itunes balance...thanks

    So then put any sim card in and restore it.  this isn't rocket science

  • How to create iTune or App Store without credit card for my existing Apple ID without create new Apple ID or email?

    I got 2 Apple ID and the first time to I use it to iTune or App Store, a box will pop out and telling me this:
    "This Apple ID has not yet been used with the i Tunes Store. Please review your account information."
    Then, I click on the button, "Review". Bla bla... but ended up, I must provide a credit card in order to complete it.
    I do not have credit card, so I search 'How to create iTune or App Store without credit card', same link and same tactic only valid for New Apple ID.
    So, it seem no other option to create iTune or App Store without credit card for existing Apple ID, right?

    The same thing is happening to me!

  • HT201272 I pay for games blood&glory regend and i pay for option but It say fail. But I alway got mail payment from my credit card for nothing of service.

    I feel so bad> I play games Blood&Glory Legend. I paid for buy option from this game. IT said download fail. I didn't get any service but I got mail for my credit card for the payment from download option of this game.

    here is a workaround for that error:
    http://btsc.webapps.blackberry.com/btsc/viewdocument.do?externalId=KB27348&sliceId=1&cmd=displayKC&d...
    Please click the Thumbs Up icon if this comment has helped you!
    If your issue is resolved, please click the solution button on the resolution!
    Every BlackBerry should have BlackBerry Protect, get it now! | Follow me on Twitter | Bring Back BBM Music!

  • How do I set birthday reminders without having to create a separate contact card for each person in a family?

    I'm trying to set birthday reminders in iCal based on the birthday field in Contacts. But in order to create separate birthday entries for individuals in the same family, you have to set up a separate card for each person. Anyway around that?

    Thank you to johnbeardy, Anthony.Ralph and Rob for your replies.  The OP (I guess that's me, Maps Man) has been happy with CS since CS2. I have upgraded etc and used it successfully.  Unfortunately, I have recently up graded my camera as well but CS5 would not read the new RAW files.  My natural inclination was to look at a CS upgrade but Adobe effectively priced me out. It obviously is not interested in amateur hobbyists anymore perhaps because they don't produce enough cash for Adobe.   Even the new "Cheap" offer they are offering is still very pricey as well as being ongoing for life. I looked at a variety of alternatives including Elements, Lightroom and DxO Pro 8.  In the meantime I used a combination of Nikon's ViewNX2 to judge my uploads off camera then Adobe DNG Converter to change them to DNG and back to CS5 for the fun bit.  Rightly or wrongly, I decided that Lightroom was the least objectionable both for cost and user friendliness.  And I do like the results I get using it.  I can now go back to coming straight out of camera, do a substantial amount of edit work and go directly to CS5 for final touches such as size and frame (perhaps Lightroom does that also but I have not yet found how!  Time will tell.)  It is just that I find the first part so annoying.  I do not mind organisations giving us suggestions (e.g. Catalogues) I just find it a nuisance that I cannot say "Thanks, but no thanks it is too complicated for what I want."  As for using it "properly" it is debatable whether Adobe's engineers have done it "properly" if they don't give that choice.  After all, CS5 etc does not need catalogues to work well so why should Lightroom's catalogues be "proper?" 
    Obviously I will be sticking with Lightroom and I will try to find my way round the problem.  I had hoped that there may have been some way to customize it for my needs but there does not seem to be.
    Thank you again for your comments.

  • TS3297 I Cannot update or purchase from itunes because of this error " We were unable to authorize your payment card for this purchase please update your billing info " this error is beacuse my brother tried to purchase some game worth 38$ which i dont ne

    I Cannot update or purchase from itunes because of this error " We were unable to authorize your payment card for this purchase please update your billing info " this error is beacuse my brother tried to purchase some game worth 38$ which i dont need it and i want to report a problem for this issue and able to get update my apps

    Welcome to the Apple Community.
    Apple's policy on sales of digital content is that all sales are final. If however you wish to appeal to Apple, select the content which is causing a problem and use the 'Report a problem' button in Your Purchase History.

  • I have created an apple id on my pc but when i'm trying to download free apps from itunes store it's asking for credit card information which i don't have, that's why i went through apple support there i found "if you don't have credit card then click on

    I have created an apple id on my pc but when i'm trying to download free apps from itunes store it's asking for credit card information which i don't have, that's why i went through apple support there i found "if you don't have credit card then click on none option but the problem is there isn't any none option so plzzzz some help me?

    If you have an existing ID, & you don't want to use a credit card, you'll have to redeem an iTunes gift card. If you don't want to do that, you'll have to create a new ID by following the directions here, EXACTLY:
    http://support.apple.com/kb/ht2534

  • HT2534 i have a half-filled form for my apple id account & in it there is no option as NONE for credit card payment method. Now when i try to create a new account it asks me for a different email/apple id as my actual id already exists???

    i have a half-filled form for my apple id account & in it there is no option as NONE for credit card payment method. Now when i try to create a new account it asks me for a different email/apple id as my actual id already exists???

    If you want to use the email address that you used on the first account then you will need to remove it from that first account before you can do so e.g. via the Store > View Account menu option on your computer's or via http://appleid.apple.com - you can create a new email address via http://gmail.com or http://hotmail.com to replace it with.

  • HT2534 The option to enter 'None' for credit card does not seem to appear on the iphone 3G that I got for my mother. Please advise how I may create an itunes account, thank you

    Hello
    Subject: Create itunes account without credit card for iPhone 3G
    The option to enter 'None' for credit card does not seem to appear on the iphone 3G that I got for my mother. Please advise how I may create an itunes account, thank you

    Creating iTunes Store, App Store, iBookstore, Mac App Store account w/o a credit card

  • I don't have credit card for creAting my apple ID. There is no NONE option also to select . Please help

    I don't have credit card for creAting my apple ID. There is no NONE option also to select . Please help...

    Did you or your friend follow, exactly, the instructions on the page that FoxFifth linked to when creating a new account ? I've just tried it on my computer's iTunes and the instructions still work, I get the 'none' option on a new account

  • Create Membership Card for organization

    I have created a membership card template using Avery Business Cards for the output media.  Now i need to insert the member's name in the card and print them.  Can someone walk me through the process?
    Thanks

    Hi...
    You can purchase iTunes gift cards that can be redeemed to purchase Lion.
    Choose your iTunes Gift Card - Apple Store
    To redeem a code just click Redeem under Quick Links right side of the App Store window.
    Make sure you purchase a card(s) that can cover the price of Lion $29.99 plus an applicable taxes or fees >  iTUNES STORE - MAC APP STORE TERMS AND CONDITIONS

Maybe you are looking for

  • HP OfficeJet 8500 Pro A909n error says printhead has problem, can't access tests or fixes

    The printer was not printing but a few streaks of magenta. I ran the tests and the test printing and did the functions to allign printheads, clean printheads, and calibrate linefeed but still could not get magenta to print. I read much advise on the

  • Client EJB JNDI lookup broken in OC4J 9.0.2?

    I have a client program that connects to an EJB in the application server and invokes methods on it. If it look up the EJB using the actual JNDI binding, it works fine. If I look it up in java:comp/env (and use the ejb-ref in application-client.xml a

  • Screen size smaller than 1024x768?

    Hi all, I'm working on a project that is being done on 1024x768 screen size. I don't get to resize the screen as with widescreen monitor it gets a bid odd when resized for a non-native resolution. So my questions is, do you reckon that there are many

  • Is this the infamous CPU whine?

    I recently got a new logic board for my MBP, and since then, I've noticed that a quiet whine coming from it. The MBP is a mid-2006 model; the logic board was installed by AppleCare a week ago. The whine only happens when the computer is not plugged i

  • Tcode to view fico related postings for one process order

    Hi Experts, Is there any trasaction code which can be used to view all related posting into FICO for one process order Thanks in advance. Narayanan Moderator: Please, search SDN