Hey guys, this is my first time posting here...
I would you like some ideas for the following situation. In a card game like pokémon, for example, suppose there is a class called OptionCard derived from another class Card. OptionCard is responsible for adding specific effects to the gaming scene. Instances of OptionCard obviously represent different cards with different effects, ie instructions that specify such an effect. Well, the question is: how can I do to create different instances of OptionCard where each of them have different effects? It's like a single member function of a class execute different effects according to their instances. Any idea?
Card Game Problem
Page 1 of 17 Replies - 1757 Views - Last Post: 18 December 2012 - 05:31 PM
Replies To: Card Game Problem
#2
Re: Card Game Problem
Posted 23 August 2012 - 01:47 PM
Quote
Well, the question is: how can I do to create different instances of OptionCard where each of them have different effects? It's like a single member function of a class execute different effects according to their instances. Any idea?
If you have a good understanding of class inheritance and pointers you may want to look into Polymorphism.
Jim
#3
Re: Card Game Problem
Posted 23 August 2012 - 01:51 PM
Yes buddy, I can create derived classes of OptionCard and reimplement a virtual function effect() in each of them. But I think this is not a good idea. I don't wanna have a class for each single card, you know...
#4
Re: Card Game Problem
Posted 23 August 2012 - 02:05 PM
You wouldn't unless every card has a unique effect . You'd only have classes for each specific effect. If different cards can have varying levels of different effects then you might make the levels parameters used by the method(s).
#5
Re: Card Game Problem
Posted 23 August 2012 - 02:47 PM
Thanks CTphpnwb, I think it's a good idea. I can create an abstract class Effect and then subclass other classes with trivials effects. With that in hand, all the cards can have a pointer to Effect and after beeing loaded I can define what kind of effect that card would have. Thanks. =]
#6
Re: Card Game Problem
Posted 13 December 2012 - 10:32 PM
I would like to add that you can also simply have a variable damage,hp, etc (whatever stats you need) and dependant on what user has, you can vary these stats without more than a few function calls, which will save memory and prevent crashes.
#7
Re: Card Game Problem
Posted 14 December 2012 - 10:12 AM
antolyevich, please make sure to check the dates on the threads. There is no reason to go through and necro threads if you don't have significant content to add.
#8
Re: Card Game Problem
Posted 18 December 2012 - 05:31 PM
For future reference for anyone who wants to know something like this, a simple solution would be to have one class which declares variables and create objects of that class. Like this:
And then you could declare as many objects with these variables as you need. You could use if statements to control the effects.
This is java, not C++, but from my understanding, it could easily be converted to C++.
public class Example {
int x;
int y;
}
public class Example2 {
public static void main(String args[]) {
Directions example = new Directions();
example.x = 3;
example.y = 4;
}
}
And then you could declare as many objects with these variables as you need. You could use if statements to control the effects.
This is java, not C++, but from my understanding, it could easily be converted to C++.
This post has been edited by extremeblueness: 18 December 2012 - 05:33 PM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote








|