Imposter

Here we are going to write the Imposter class. This class will do Fake Tasks and eliminate other players, all while keeping track of how many other players are alive.

  1. Create a class called Imposter that is also a Player!

  2. The imposter has a private int state called numberOfTargets;

  3. The constructor of the Imposter has two parameters, a String for name, and an int for number of players alive

    1. Super the name, true, true (name, we are alive, we are the imposter)

    2. Set the numberOfTargets state equal to the int parameter

  4. Write the doTask() method. This method should print out "Name: fakes a task"

  5. Write the void eliminate(Crewmate c) method. We only allow Crewmate as the parameter as Imposters cannot eliminate each other.

    1. If c is alive

      1. Tell c to get eliminated

      2. Decrease number of targets by 1

      3. If number of targets is less than or equal to 0

        1. Print out the "Imposter Name has won as Imposter"

        2. Followed by this line that updates the game status: PlayerDriver.gameOver = PlayerDriver.IMPOSTERWIN; (this will mark as incorrect until you add my Driver class)

Imposter Code **Warning only if needed**


public class Imposter extends Player{

private int numberOfTargets;

public Imposter(String n, int targets) {

super(n, true, true);

numberOfTargets = targets;

}


public void doTask() {

System.out.println(getName() + ": Fakes tasks");

}

public void eliminate(Crewmate c) {

if(c.getIsAlive()) {

c.gotEliminated();

numberOfTargets--;

if(numberOfTargets <= 0) {

System.out.println(getName() + " has won!");

PlayerDriver.gameOver = PlayerDriver.IMPOSTERWIN;

}

}

}


}