Newbie: general question on trying to get a simple Pokemon game to work
I am writing a game where you have a monster and fight it against others very similar to how pokemon works. I have some experience with C++ and just started learning how to properly do things in Java so that I can eventually work on Android apps.
Basically, I will have a monster class that contains all the stats for the two monsters that I will have fighting. I plan on having them fight like in pokemon, you choose a move, it happens then the computer responds until one dies. I'm having trouble figuring out generally how I will do this. Visually I want to change screens and go to the battle screen. But I can't think of the right way to code it. At the moment I want to just keep it text based while I figure it out (ie press 1 to use attack 1 or press 2 to use attack 2). Should I make a battle class or should I just code everything in my main file. I can give you a better idea if you have questions.
This is a general idea on how I want the battle to flow:
/* 1. Initialize Battle
* - get monster data
* inherit monster object from main or where ever
* - display data/moves (health, attack power, name of move)
* - receive input
* buttons set up (prompt for now 1 for attack1, 2 for attack2)
* 2. Player Attack
* - retrieve move info
* - calculate damage/stat change
* - display damage/change
* - check status (is it dead?)
* 3. Monster Attack (timer)
* - roll for move
* - calculate damage/stat change
* - display damage/change
* - check status
* 4. Repeat until monster dies
* 5. When battle is done
* - calculate xp
* - display level up or whatever
* - prompt or return to main screen
*/
Re: Newbie: general question on trying to get a simple Pokemon game to work
I don't like the sound of "should I just code everything in my main file". That's probably not the best way to go about it.
There are a ton of ways to do this. One way is to have a Monster class, which contains a List of Attack instances, which have names and damages. Each Monster starts with a certain amount of health, and you subtract from it the value of attacks done to it.
Re: Newbie: general question on trying to get a simple Pokemon game to work
Thanks for your advice. Like I said, I'm fairly new to programming and still struggle with some of the meta knowledge and understanding how to use multiple classes, interfaces, etc to accomplish my task instead of putting the code all in one file like I did in my intro C++ class in college.
I haven't gotten to instances yet on the Java tutorial so hopefully that will shed some light on my problem.
Re: Newbie: general question on trying to get a simple Pokemon game to work
So after reading through the interface tutorial stuff I am still confused. So I understand that when you create an interface you do not put any method implementations into it only the signatures. It gave the example of a car steering system that is for all types of cars. In my understanding, the interface would simply be there to specify that if you want your program for your specific brand (Toyota, Ford) then you must use the method signature that is in the interface, but you could implement it in your own class methods however you want? So if I am making a game that only I will be coding, why do I need to use the interfaces? Why can't I just make methods for each attack to generate the damage done then call on another method to subtract the damage from the monster's health.
Re: Newbie: general question on trying to get a simple Pokemon game to work
Depending on the IDE or editor you use, you can put all your classes in one file. Only one can be public. With a simpler IDE or editor that can make it easier to get the project off the ground and get the classes sort of defined.
Once you get all the classes sort of working you can strip them out of the big file and put them in their own .java files.
Re: Newbie: general question on trying to get a simple Pokemon game to work
The other thing that didn't make sense was that interfaces appear to be useful when you have objects from two separate classes that might use that interface. My program will have two monster objects of the same class fighting each other, so why would it be better to use interfaces over putting methods in for my moves.
Re: Newbie: general question on trying to get a simple Pokemon game to work
My brief view of interfaces. They are a way to give a specific type to a class. Many methods require objects of a certain type as arguments. For example the addActionListener() method requires an object of a class that implements the ActionListener interface. The reference to the listener is saved in the component by the addActionListener() method, then when that component wants to notifiy listeners of an action, it knows that all the listeners it has added have the correct actionPerformed() method so the component can call that method using the object passed via the addActionListener method.
Quote:
would it be better to use interfaces over putting methods in for my moves.
implementing an interface usually requires the class to add some mehtods to the class. They are not opposites.
Re: Newbie: general question on trying to get a simple Pokemon game to work
Quote:
Originally Posted by
willmer
The other thing that didn't make sense was that interfaces appear to be useful when you have objects from two separate classes that might use that interface. My program will have two monster objects of the same class fighting each other, so why would it be better to use interfaces over putting methods in for my moves.
I'd just like to point out that you're the first person to mention interfaces in this thread, nobody here told you they were the way to go. They're certainly one way to accomplish certain things in your game, but I'm not sure I'd start out with them. You've heard the approach I'd start out with, but it's really up to you.