Card Battling System

OK so I thought I get some input here since I honestly I have a small infantile knowledge of the Java language (I’m learning as I go). Without giving out too much info, the game is in short a “Mega Man Chip Challenge” or basically an RPG-Like game that uses cards. I was wonder how I should go about implementing the cards…I believe making a class for the cards is the only way to go about it. Each card knows general info about itself, but in battle they can carry out a wide variety of actions…I was thinking having a method that can read the cards ID number and thus, using a crap ton of else if statements, perform the required actions. I guess what I want to know is basically if there is an easier way to go about the entire thing. Any suggestions?

A “crap ton” of conditional statements is usually a bad idea. If you are looking to implement the game in OOP, then more typical style would be for the card to do its own calculations and carry out its own actions, rather than a separate system.

Some questions that might help clarify things:

  • Even though there are a wide variety of actions, can they be categorized (Damage causing, healing, stat improvement, etc)?
  • Will a given card have actions of more than one type?
  • Do all of the actions come into play all of the time or does the player choose among a set of available actions for a given card?

Without knowing more, I would create a class that represents an Action. A Card can own one or more Actions and would iterate through them to calculate the overall effect.

You are indeed missing the whole point of OOP design… but this is the perfect problem to help you grasp it. You shouldn’t be using conditions to implement each card’s behavior, instead…

1.) Make an abstract class called Card which contains all of the code that all cards share in common. Abstract classes cannot be instantiated but they can be extended by other classes.
2.) Now make a class for each type of card you want in your game, and have each one extend the Card class. Your subclasses will inherit all of the implemented methods of the parent “Card” class.
3.) Now, put an abstract method in the Card class, such as “doActions”. Notice that this prevents your child classes from compiling… abstract methods must be implemented by child classes.
4.) Have each one of the child classes override “doActions”… this is where you can specify the individual behaviors of each card.

Now, whenever you have a variable of type Card, you can store any of the child classes of Card inside of it. You can even store all of your cards in an ArrayList (or any other generic container class), no matter which type of card it is.

You can call card.doActions() and it will perform the appropriate actions for whichever type of card it is. Try testing it out with debug messages.

Sweet! At the moment both those responses are confusing me…Time to keep learning as I go I suppose! ;D

But I think I can wrap my head around both suggestions and implement something.