Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Newbie: general question on trying to get a simple Pokemon game to work

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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
    */


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  4. #4
    Junior Member
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default 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.

  6. #6
    Junior Member
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default 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.

    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.

  8. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Newbie: general question on trying to get a simple Pokemon game to work

    Quote Originally Posted by willmer View Post
    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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Help on some work i got ! Reversi game
    By benni7 in forum Algorithms & Recursion
    Replies: 9
    Last Post: September 22nd, 2011, 11:38 AM
  2. [SOLVED] Simple While loop wont work??
    By chuckie987 in forum Loops & Control Statements
    Replies: 1
    Last Post: January 31st, 2011, 02:58 PM
  3. [SOLVED] "possible loss of precision", except not, code doesn't work, simple question
    By Perd1t1on in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 24th, 2010, 07:11 PM
  4. begginer wondering why his guessing game won't work
    By Ligawulf in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 8th, 2010, 12:22 AM
  5. Newbie needs help in simple servlet program
    By visitor1078 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 19th, 2009, 01:46 PM