Class TurtleMob


  • public class TurtleMob
    extends Object
    Ok, fine, "mob" is a bit of an overstatement. This class helps manage a pair of deadly turtles.
    Version:
    1.0
    Author:
    Brad Richards
    • Constructor Detail

      • TurtleMob

        public TurtleMob​(TurtleMob otherMob)
        This copy constructor sets up our "mob" to look exactly like the TurtleMob instance passed in as an input. We need to make sure that the two turtles we manage are completely separate from the two turtles in the other "mob", and that the Circles in our two turtles are separate from their Circles but have the same state.
        Parameters:
        otherMob - A reference to another TurtleMob object we want to copy
      • TurtleMob

        public TurtleMob()
        Default constructor for objects of class TurtleMob. It makes a pair of Turtle instances with the same "speed", then calls splitUp() to make sure they're not at exactly the same position on the screen.
    • Method Detail

      • splitUp

        public void splitUp()
        Causes the two Turtles to move apart horizontally, then leaves them both facing south.
      • advance

        public void advance()
        Moves both turtles forward one "step".
      • equals

        public boolean equals​(TurtleMob other)
        Compares "us" to another TurtleMob. It returns true if *all* details of our first turtle match theirs (including the Circle within it), and the same is true for our second turtle and theirs.
        Parameters:
        other - A reference to the TurtleMob to which we will compare ourselces
        Returns:
        True if our turtles match their turtles, false otherwise.
      • sameSpot

        public boolean sameSpot()
        Compares our two turtles to see if they're at the same position on the screen. There's no method in the Turtle class that can help us here, so we need to go look into their Circle objects, get their X and Y positions, and compare those.
        Returns:
        True if our circles are at the same spot on the screen.