• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Which Pokémon Masters protagonist do you like most? Let us know by casting a vote in our Masters favorite protagonist poll here!
  • Red, Hilda, Paxton, or Kellyn - which Pokémon protagonist is your favorite? Let us know by voting in our poll!
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Can I ask a general programming question?

  • 180
    Posts
    13
    Years
    • Seen Aug 12, 2023
    I was just wondering if that is allowed here, as I'm attempting to make a text-based pokemon battle simulator in c++ where you can choose a party of 6 pokemon and the attacks it can do. I'm doing this as a side project really for fun, and I figured if I can at least make a fully workable simple c++ text-based program, I can move on to windows programming, and possibly graphics :). I'm up for the challenge!
     
    You shouldn't be asking if it's allowed, you should just be asking the question. There are a few people here who know C++ and could help you out with it (including me).
     
    Go for it man! I'll happily give you pointers when you need them! [/pun]
     
    Here's how my program will work. You first pick 6 pokemon in your party (I have this as 2 vectors of pointers to the pokemon classes, 1 vector for player 1, and 1 for player 2). The pokemon are given random IV's (for the moment), and EV's are at 0. Now, for each pokemon in your party you can choose 4 attacks. Here's where I'm getting some trouble at.

    I'm having trouble with is how to implement the battle system itself. To give you a bit of an idea of what I've done so far. I have my base pokemon class, and the derivatives are gonna be the pokemon itself. I understand the flow of the battle and how I want to go about it from pseudocode. The problem I'm having is how to go about it. Do I do each attack as a function, or should I make the attack a class? Also, what's a good way to implement a pokemon's attack table within the class itself?
     
    Why should we program your game for you? Your questions are a bit too general.

    I would use a queue to store which attack is going to be executed in which order. The attacks would be all children from an attack class. I would make a virtual "run" function which could let each attack have a unique effect.
     
    Believe me, I'm not asking for actual code, just a step in the right direction. Thanks DaSpirit, that may be all I need. However, I'm not familiar with the phrase "virtual run function". Is that the polymorphic class function I'd use to differentiate between the children classes?
     
    In Essentials, each move is an instance of one class, which reads the compiled data for that move. In battles, each move is an instance of a different class which inherits much of the information from the first class (i.e. base power, etc.). This battle move class also contains various functions that can modify the move's power, accuracy, type and so forth.

    It seems to be a reasonable way of doing it. With it, you can modify a particular move's information when required during battle without worrying about also modifying the compiled data for that move (which should remain constant).
     
    In Essentials, each move is an instance of one class, which reads the compiled data for that move. In battles, each move is an instance of a different class which inherits much of the information from the first class (i.e. base power, etc.). This battle move class also contains various functions that can modify the move's power, accuracy, type and so forth.
    This is the way I'd suggest to do it.. Honestly it would be the best way. This way each attack doesn't need its own function or class. While in battle, lets say pikachu attacks a squritle you could have the attack function check between the pokemon types and move types then have a super effective attack happen. I hope you understand where I'm going with this I just cant word it very well at the moment if your having trouble understanding I will try to explain better.
     
    Believe me, I'm not asking for actual code, just a step in the right direction. Thanks DaSpirit, that may be all I need. However, I'm not familiar with the phrase "virtual run function". Is that the polymorphic class function I'd use to differentiate between the children classes?

    If you don't know how to use the virtual keyword, then I don't know if you're cut out for this. C++ is a very difficult language. I recently took a few tests for it online and they turned out to be harder than I thought.

    A "virtual" function is a function in a class that has to be overridden by the child. In the parent, you can set the function equal to 0 if you don't want the parent to use it, but you do want the children to.
     
    One of the first things I did while programming Four Star Mon (which is also in C++ :P) was to create a command-line battle interface. So you're not alone on that part :P

    Yes, definitely create a move as a base class, but in that base class, have a virtual function called "useMove()" or something that the battle engine will call to run the move. That way, the battle engine doesn't need to care what move is being used (and what class type), since they will all have the same useMove() which will then automatically branch into other things depending on the type of subclass.

    Secondly, it's generally a bad idea to implement the Pokémon's attack table and other data into the move class, because there's a way to do things that doesn't require it, and doing so will have multiple instances of the same move in the engine, which really is unnecessary. (In object-oriented programming, this is known as "separation of concerns". Try not to link actions together in the same class if it's not necessary to do so.)

    For exapmle, Four Star Mon's move class doesn't have a PP counter, or any data on attack, defense, and accuracy. All that data is stored in the Pokémon who knows the move (the PP counter is placed in an "Attack" class that contains a pointer to the move that the Attack represents). The useMove(), once run, will request this data from the engine or the user of the move by itself.

    I'm not familiar with the phrase "virtual run function". Is that the polymorphic class function I'd use to differentiate between the children classes?

    Yes, yes it is. Although not "differentiate", it's quite the opposite. It's the one thing that they all have in common and the important thing in common that will be used.
     
    Last edited:
    Thank you for all your replies, guys. It'll definitely help (once I have time to go back to this program). I do have some follow-up questions, though.

    This is the way I'd suggest to do it.. Honestly it would be the best way. This way each attack doesn't need its own function or class. While in battle, lets say pikachu attacks a squritle you could have the attack function check between the pokemon types and move types then have a super effective attack happen. I hope you understand where I'm going with this I just cant word it very well at the moment if your having trouble understanding I will try to explain better

    I'm not 100% of what you're saying, but it seems like you're saying what I have planned out. The battle engine itself will check for the move and pokemon type currently in battle. I have my pokemon and move types as an int variable of that pokemon class. I plan to make a function which compares between the pokemon's type and the attack being used against it, as well as checking for STAB for the pokemon currently attacking (doing all damage calculations etc).

    In Essentials, each move is an instance of one class, which reads the compiled data for that move. In battles, each move is an instance of a different class which inherits much of the information from the first class (i.e. base power, etc.). This battle move class also contains various functions that can modify the move's power, accuracy, type and so forth.

    This part I'm not completely grasping what you're trying to explain here (please forgive me! I'm only learning c++ on my own, haven't really taken an actual course). This is what I think you're talking about: class composition - making one class which has all of its instances being the moves themselves, but through compiled data? As in from an external data file? The battle move class inherits the information through the first class, meaning the class that has each move as an instance of the class?

    Yes, definitely create a move as a base class, but in that base class, have a virtual function called "useMove()" or something that the battle engine will call to run the move. That way, the battle engine doesn't need to care what move is being used (and what class type), since they will all have the same useMove() which will then automatically branch into other things depending on the type of subclass.

    Yes. My original plan was like this. Create a base 'attack/move' class with a function similar to 'useMove()' as a pure virtual function to make it an abstract class. Which brings me to what I had originally planned for some parts of the whole battle engine.

    My pokemon base class will have an attack list vector, representing the 4 attacks the user chooses to have his/her pokemon to have. The derived pokemon (the pokemon themselves) will inherit their own list/vector where these would store pointers to the attacks. In the main program, the user chooses the attacks he/she would like to use and put the attack in the list (something along the lines attack_list.push_back(new attack()) ). In my main 'battle()' function, where the main battle engine will be where you can choose an attack for the pokemon that's first in your party as well as various other stuff, would call the 'attack() function of that pokemon class. The 'attack()' function will pass an integer (based on which attack slot the user chooses) into the function that will determine which attack the pokemon will use from the list. The attacks would have, similar to what Dragonite Ernston says, a useMove() function that determines its power, accuracy, status effect, etc etc. It will also check the opponent's pokemon type, defense, all that good stuff to calculate damage and apply miscellaneous effects.

    Now that you guys have an idea of what I had originally planned to do, you could possibly clarify, and correct me on my chosen plan. I'm understanding more and more as I write this post out and discuss it.

    Edit: Wow, didn't realize my post was so long!
     
    Yes. My original plan was like this. Create a base 'attack/move' class with a function similar to 'useMove()' as a pure virtual function to make it an abstract class. Which brings me to what I had originally planned for some parts of the whole battle engine.

    Well, seems like we think alike then!

    My pokemon base class will have an attack list vector, representing the 4 attacks the user chooses to have his/her pokemon to have. The derived pokemon (the pokemon themselves) will inherit their own list/vector where these would store pointers to the attacks.

    Wait, lemme get this straight, you're going to make a subclass for each Pokémon? Couldn't you just use that base class by itself and do pretty much the exact same thing? There's no need to inherit stuff if you're just making objects out of a class; only if you're making classes out of other classes.

    In the main program, the user chooses the attacks he/she would like to use and put the attack in the list (something along the lines attack_list.push_back(new attack())). In my main 'battle()' function, where the main battle engine will be where you can choose an attack for the pokemon that's first in your party as well as various other stuff, would call the 'attack() function of that pokemon class. The 'attack()' function will pass an integer (based on which attack slot the user chooses) into the function that will determine which attack the pokemon will use from the list. The attacks would have, similar to what Dragonite Ernston says, a useMove() function that determines its power, accuracy, status effect, etc etc. It will also check the opponent's pokemon type, defense, all that good stuff to calculate damage and apply miscellaneous effects.

    I think, rather than a battle function, you should have an entire object to manage that part. Battling is a multi-turn process, which is rather hard to do in just one function, even if you use while loops.

    Also, make the Attack class a wrapper for the Move class that points to the Move. You don't want to have multiple instances of the same move class (which will do the exact same thing) in the program if you don't need to (and you don't).

    Also, the power, accuracy, etc. should be stored in the Move class itself, not determined by useMove().

    If you want ideas about how to do it, check out the source code of this old Java engine that I never finished: https://github.com/joe-zeng/java-pokemon

    Now that you guys have an idea of what I had originally planned to do, you could possibly clarify, and correct me on my chosen plan. I'm understanding more and more as I write this post out and discuss it.

    Edit: Wow, didn't realize my post was so long!

    Don't worry, I've made longer.
     
    This is the way I'd suggest to do it.. Honestly it would be the best way. This way each attack doesn't need its own function or class. While in battle, lets say pikachu attacks a squritle you could have the attack function check between the pokemon types and move types then have a super effective attack happen. I hope you understand where I'm going with this I just cant word it very well at the moment if your having trouble understanding I will try to explain better.
    I agree, this is a very good polymorphism use. Also notes that the moves uses a dynamic class call based in each move function code.
     
    Thanks for all the advice guys. I'll put this to work once I'm done with college here in a couple weeks. I'll also be looking at the pokemon online battle simulator source for a guideline, too. Again thank you :)
     
    Back
    Top