Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (512)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Card Battling System  (Read 1315 times)
0 Members and 1 Guest are viewing this topic.
Offline AsixJin

Junior Newbie





« Posted 2013-10-23 08:35:28 »

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?
Offline actual

JGO Coder


Medals: 23



« Reply #1 - Posted 2013-10-23 09:06:34 »

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.
Offline Grimmov

Senior Newbie





« Reply #2 - Posted 2013-10-23 09:24:46 »

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?

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<Card> (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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline AsixJin

Junior Newbie





« Reply #3 - Posted 2013-10-23 18:44:36 »

Sweet! At the moment both those responses are confusing me...Time to keep learning as I go I suppose!  Grin

But I think I can wrap my head around both suggestions and implement something.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (49 views)
2014-10-17 03:59:02

Norakomi (39 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (35 views)
2014-10-15 16:18:58

TehJavaDev (65 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (55 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!