Class Pokemon


  • public class Pokemon
    extends java.lang.Object
    Class that implements a Pokemon.

    Let's play Pokemon! This is our Pokemon class. Each Pokemon has several member variables that make it a Pokemon. Each Pokemon has:

    • a name
    • a number of hit points that decrement as the game continues
    • up to 50 points to split between attack and defense
    • a 6-sided dice for calculating attack damage
    • a 20-sided die for calculating attack bonuses and defense bonuses

    Have a look through the Pokemon file to see how we can construct objects, can use member variables of these objects, and use objects of the same type to make our game.

    See Also:
    Lab 4 Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Pokemon()
      Create a new Pokemon with default values.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean attack(Pokemon opponent)
      Attack another Pokemon.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Pokemon

        public Pokemon()
        Create a new Pokemon with default values.

        Constructs a new Pokemon with a 6-sided die, 20-sided die, 0 hit points, attack level of 0, defense level of 0, and an empty name.

    • Method Detail

      • attack

        public boolean attack(Pokemon opponent)
        Attack another Pokemon.

        Calling this method will cause this Pokemon to attack another Pokemon as follows:

        • We get the attack bonus and defense bonus.
        • We roll the d6 die 3 times to calculate the damage.
        • We then compare to see if the attack hit or missed, and see if this was a fatal attack.
        This is a good function to look through to see objects in action!
        Parameters:
        opponent - the Pokemon to attack
        Returns:
        whether or not the game has ended