Chaser Playerplayer entity dummyplayerclassjava is given Cre

Chaser Player(player, entity ,dummyplayerclass.java is given)
Create a class called Chaser that extends the Player class. Your Chaser player will chase after a player on the opposing team. We will use a RandomWalker player as the opposing player when we test your code. If your player catches up to the RandomWalker player, your player should continue to follow it. If you did not get your RandomWalker player working to test this, just use the DummyPlayerclass that is given. Test your code with only two players in the game: your Chaser player and one opponent.

Note: When testing your code for you Chaser player, try adjusting the speed of your player. When your player moves faster it should catch the RandomWalker player eciently. When your player moves slower you should be able to see that it is (usually) walking in a curve rather than a straight line to try and chase the RandomWalker player.

player class

public abstract class Player extends Entity{


/** this player\'s team name */
protected String team;

/** this player\'s name */
protected String name;

/** this player\'s number */
protected int number;

  
/** gets this player\'s team name
    *
    * @return the team name that this player is on
    */
public final String getTeam(){ return this.team; }


/** gets this player\'s name
    *
    * @return the name of this player
    */
public final String getName(){ return this.name; }

/** gets this player\'s number
    *
    * @return the number of this player
    */
public final int getNumber(){ return this.number; }


/** creates a player with specified symbol at specified position
    *
    * @param f is the field the player will be playing on
    * @param side is the side of the field the player will play on
    * @param name is this name of the player
    * @param number is this player\'s number
    * @param team is this player\'s team name
    * @param symbol is a character (char) representation of this player
    * @param x is the x-coordinate of this player
    * @param y is the y-coordinate of this player
    */
public Player(Field f, int side, String name, int number, String team, char symbol, double x, double y){
    super(symbol, x, y);
    this.name = name;
    this.number = number;
    this.team = team;
    f.registerPlayer(this, this.id, side); // register the player on the field
}

/** attempt to catch an opponent player
    *
    * @param opponent a player on the opponent\'s team that you are trying to catch
    * @param field is the field the game is being played on
    * @return true if this player successfully catches the opponent player, false otherwise
    */
public final boolean catchOpponent(Player opponent, Field field){
    return field.catchOpponent(this, opponent);
}


/** Informs this player that they have been caught by another player.
    * <p>
    * This method should only be called from within the Field class.
    *
    * @param opponent is the player that caught this player
    * @param id should be the id of the this player
    */
public void beenCaught(Player opponent, int id){
    /* check if the caller knows this entity\'s id */
    if( this.id != id ){
      throw new SecurityException(\"Unauthorized attempt to call beenCaught \");
    }
   
}
   
/** attempt to free a teammate from jail
    *
    * @param teammate is another player on this player\'s team
    * @param field is the field the game is being played on
    * @return true if the <code>teammate</code> is successfully freed from jail, false otherwise
    */
public final boolean freeTeammate(Player teammate, Field field){
    return field.freeTeammate(this, teammate);
}
   
/** Informs this player that they have been freed by a teammate
    * <p>
    * This method should only be called from within the Field class.
    *
    * @param teammate is the player that caught this player
    * @param id should be the id of the this player
    */
public void hasBeenFreed(Player teammate, int id){
    /* check if the caller knows this entity\'s id */
    if( this.id != id){
      throw new SecurityException(\"Unauthorized attempt to call hasBeenFreed \");
    }
   
}



/** attempt to pick up the opponent\'s flag
    *
    * @param field is the field the game is being played on
    * @return true if this player successfully picked up the opponent\'s flag, false otherwise
    */
public final boolean pickUpFlag(Field field){
    return field.pickUpFlag(this);
}


/** Informs this player that they have picked up the flag
    * <p>
    * This method should only be called from with the Field class.
    *
    * @param id should be the id of the this player
    */
public void hasPickedUpFlag(int id){
    /* check if the caller knows this entity\'s id */
    if( this.id != id ){
      throw new SecurityException(\"Unauthorized attempt to call hasPickedUpFlag \");
    }
   
}

/** Informs this player that they have dropped the flag
    * <p>
    * This method should only be called from within the Field class.
    *
    * @param id should be the id of the this player
    */
public void hasDroppedFlag(int id){
    /* check if the caller knows this entity\'s id */
    if( this.id != id ){
      throw new SecurityException(\"Unauthorized attempt to call hasDroppedFlag \");
    }
   
}


/** attempt to win the game
    *
    * @param field is the field the game is being played on
    * @return true if this player successfully brings the opponent\'s flag back to this player\'s base, false otherwise
    */
public final boolean winGame(Field field){
    return field.winGame(this);
}

  


}

Dummy player.java

public class DummyPlayer extends Player{

@Override
public void play(Field field){
    // play is the logic for the player
    // you should make changes to the player\'s speed here
    // you should not update position
    if( Math.random() < 0.5){
      this.speedX *= 0.99;
    }
    if( Math.random() < 0.0005){
      this.speedY *= -1;
    }

    //
    // should not update position here
    //      updatePosition(1,field);
    // this is now removed.
    //
}
   

@Override
public void update(Field field){}




/** create a player that has some random motion
    * <p>
    * the player starts in a random direction
    *
    * @param f is the field the player will be playing on
    * @param side is the side of the field the player will play on
    * @param name is this player\'s name
    * @param number is this player\'s number
    * @param team is this player\'s team\'s name
    * @param symbol is a character representation of this player
    * @param x is the initial x position of this player
    * @param y is the initial y position of this player
    */
public DummyPlayer(Field f, int side, String name, int number, String team,char symbol, double x, double y){
    super(f, side, name, number, team, symbol, x, y);
    this.speedX = Math.random()*4-2;
    this.speedY = Math.random()*4-2;
}

}

Entity.java

/**
* Entity class to represent \"things\" in the game: players, flags, jails, bases, etc.
*/
public abstract class Entity{
/** time scaling factor. Will be more important when View is graphics based */
public static double TIME_SCALE = 50;    
  
/** character representation of this entity */
protected char symbol;

/** current x-coordinate of this entity */
protected double x;
/** current y-coordinate of this entity */
protected double y;

/** current speed in x-direction of this entity */
protected double speedX;
/** current speed in y-direction of this entity */
protected double speedY;


/** unique ID for entity */
protected int id;

protected static int ID = 0; // used to generate unique id\'s


/** maximum speed for a player for use in tournament */
public static final int MAX_SPEED = 10;


/** creates an entity (for players) with specified symbol at specified position
    *
    * @param symbol is a character (char) representation of the entity
    * @param x is the x-coordinate of the entity
    * @param y is the y-coordinate of the entity
    */
public Entity(char symbol, double x, double y){
    this.symbol = symbol;
    this.x = x;
    this.y = y;
    this.id = ID; // set the ID for the entity
    ID +=1;        // update the ID counter for the next entity created
}
  

/** constructor for non-player things
    *
    * @param symbol is a character (char) representation of the entity
    * @param x is the x-coordinate of the entity
    * @param y is the y-coordinate of the entity
    */
public Entity(Field f, int side, char symbol, double x, double y, String ref){
   this(symbol, x, y);
    f.registerThing(this, this.id, side); // register with the field
    this.sprite = SpriteStore.get().getSprite(ref);
}


/** gets this entity\'s symbol
    *
    * @return the symbol of this entity (char)
    */
public char getSymbol(){ return this.symbol; }

/** gets the current speed in the x-direction of this entity
    *
    * @return the current x-direction speed of this entity
    */
public double getSpeedX(){ return this.speedX; }

/** gets the current speed in the y-direction of this entity
    *
    * @return the current y-direction speed of this entity
    */
public double getSpeedY(){ return this.speedY; }

/** gets the current x-coordinate of this entity
    *
    * @return the current x-coordinate of this entity
    */
public int getX() { return (int) this.x; }

/** gets the current y-coordinate of this entity
    *
    * @return the current y-coordinate of this entity
    */
public int getY() { return (int) this.y; }

/** update the position of this entity using basic physics
    * <p>
    * In each direction, we have
    * new_position = current_position + speed * time_elapsed
    * <p>
    * Note: TIME_SCALE will need to be manually adjusted to a value that allows good game play
    *
    * @param time is a length of time
    * @param field is the current field
    * @param id is supposed to the entity\'s id value
    */
public final void updatePosition(long time, Field field, int id)
          throws SecurityException, EntityOutOfBoundsException
    {
    if( id != this.id ){
      throw new SecurityException(\"Unauthorized change of position\");
    }

    /* need to add logic of when to actually throw this */
    if(false){
      throw new EntityOutOfBoundsException(\"out of bounds\");
    }

    this.x += (time * this.speedX) / TIME_SCALE;
    this.y += (time * this.speedY) / TIME_SCALE;
    checkCoordinates(field);
}

/** checks that this player is within the field boundaries
    *
    * @param field is the field that this entity is on
    */
protected void checkCoordinates(Field field) throws EntityOutOfBoundsException{
    // check if this entity is out of the playing field
    // if they are throw the exception
    // if they are not, do nothing
}


/** logic for this entity (change direction/speed)
    * <p>
    * logic is based on current playing field (which holds information about
    * all entities on the field) and possibly state of this entity. Do NOT
    * update the entity\'s position here, just update speed.
    *
    * @param field is the current playing field
    */
public abstract void play(Field field);

/** update this entity for any changes to it
    * <p>
    * For example, if this entity is moved by another entity, this entity\'s
    * positions need to be updated.
    *
    * @param field is the current playing field
    */
public abstract void update(Field field);


/** override the equals method from Object
    * <p>
    * This needs to be implemented in a child class
    *
    * @param o is an object to be tested for equality with this
    * @return throws an exception
    */
@Override
public boolean equals(Object o){
   if(this == o){return true;}
   if(o==null){return false;}
   if( o instanceof Entity){
    return this.id == ((Entity)o).id;
   }
   return false;
}


/* Setter methods
   *
   * We don\'t want a player of one team to be able to change the
   * position or movement of a player on another team.
   * The caller needs to know the entity\'s id number.
   */

/** sets the x-coordinate of this entity
    *
    * @param x is the new x-coordinate
    * @param id should be the entity\'s id
    */
protected final void setX(double x, int id){
    /* check if the caller knows this entity\'s id */
    if( id != this.id ){
      throw new SecurityException(\"Unauthorized change of entity x coordinate\");
    }
    this.x = x;
}

/** sets the y-coordinate of this entity
    *
    * @param y is the new y-coordinate
    * @param id should be the entity\'s id
    */
protected final void setY(double y, int id){
    /* check if the caller knows this entity\'s id */
      if( id != this.id ){
      throw new SecurityException(\"Unauthorized change of entity y coordinate\");
    }
    this.y = y;
}

/** sets the speed in the x-direction of this entity
    *
    * @param speedX is the new x-direction speed
    * @param id should be the entity\'s id
    */
protected final void setSpeedX(double speedX, int id){
    /* check if the caller knows this entity\'s id */
      if( id != this.id ){
      throw new SecurityException(\"Unauthorized change of entity x-direction speed\");
    }
    this.speedX = speedX;
}

/** sets the current speed in the y-direction of this entity
    *
    * @param speedY is the new y-direction speed
    * @param id should be the entity\'s id
    */
protected final void setSpeedY(double speedY, int id){
    /* check if the caller knows this entity\'s id */
    if( id != this.id ){
      throw new SecurityException(\"Unauthorized change of entity y-direction speed\");
    }
    this.speedY = speedY;
}


//
// this is used for graphical representations
//

/** the sprite that will represent this entity */
protected Sprite sprite;

public Sprite getSprite(){ return this.sprite; }

public void setSprite(String ref, int id){
    /* check if the caller knows this entity\'s id */
    if( id != this.id ){
      throw new SecurityException(\"Unauthorized change of entity\'s sprite\");
    }
    this.sprite = SpriteStore.get().getSprite(ref);
}



}

Solution

This is the code for Chaser class

Public class Chaser extends Player{
  
   public Chaser(Field f, int side, String name, int number, String team,char symbol, double x, double y)
   {
       super(f, side, name, number, team, symbol, x, y);
       this.speedX = Math.random()*4-2;
   this.speedY = Math.random()*4-2;
   }

   @Override
   public void play(Field field) {
       if( Math.random() < 0.5){
       this.speedX *= 0.99;
   }
   if( Math.random() < 0.0005){
   this.speedY *= -1;
   }
      
   }

   @Override
   public void update(Field field) {

      
   }
  
   public void chase(Player opponent)
   {
       while(this.speedX < opponent.speedX)
       {
           this.speedX += 0.5;
           if(this.speedY<opponent.speedY)
           {
               this.speedY +=0.5;
           }
       }
   }
}

Chaser Player(player, entity ,dummyplayerclass.java is given) Create a class called Chaser that extends the Player class. Your Chaser player will chase after a
Chaser Player(player, entity ,dummyplayerclass.java is given) Create a class called Chaser that extends the Player class. Your Chaser player will chase after a
Chaser Player(player, entity ,dummyplayerclass.java is given) Create a class called Chaser that extends the Player class. Your Chaser player will chase after a
Chaser Player(player, entity ,dummyplayerclass.java is given) Create a class called Chaser that extends the Player class. Your Chaser player will chase after a
Chaser Player(player, entity ,dummyplayerclass.java is given) Create a class called Chaser that extends the Player class. Your Chaser player will chase after a
Chaser Player(player, entity ,dummyplayerclass.java is given) Create a class called Chaser that extends the Player class. Your Chaser player will chase after a
Chaser Player(player, entity ,dummyplayerclass.java is given) Create a class called Chaser that extends the Player class. Your Chaser player will chase after a
Chaser Player(player, entity ,dummyplayerclass.java is given) Create a class called Chaser that extends the Player class. Your Chaser player will chase after a
Chaser Player(player, entity ,dummyplayerclass.java is given) Create a class called Chaser that extends the Player class. Your Chaser player will chase after a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site