Class Opponent


  • public class Opponent
    extends Boat
    Represents a opponent boat with AI.
    • Field Detail

      • steering

        public java.lang.String steering
    • Constructor Detail

      • Opponent

        public Opponent​(int yPosition,
                        int width,
                        int height,
                        Lane[] lanes,
                        int laneNo,
                        java.lang.String name)
        Creates an instance of the player boat.
        Parameters:
        yPosition - Y-position of the boat.
        width - Width of the boat.
        height - Height of the boat.
        lanes - Lanes for the boat.
        laneNo - Lane number for the boat.
        name - Name of the boat.
    • Method Detail

      • ai

        public void ai​(int backgroundOffset)

        Controls the AI behaviour of the boat.

        Changes the movement path of the boat.

        AI new path selection:

        1) If not in lane, go back to lane.

        2) If obstacle ahead, avoid the obstacle. If dead ahead, slow down.

        3) If nothing, speed up.

        Parameters:
        backgroundOffset - Background offset
      • SetRandomBoat

        public int SetRandomBoat​(java.util.ArrayList<java.lang.Integer> possibleBoats)

        Assigns a random boat template to the boat.

        This includes stats and texture.

        Parameters:
        possibleBoats - List of remaining boat templates that haven't been assigned yet.
        Returns:
        Int representing the index of the boat template that was assigned.