package lect78_impl.model; import lect78_impl.controller.Controls; /** * @overview Represents a player in the game * * @attributes * id Integer Player ID * tankSet TankSet Set of tanks owned by this player * controls Controls Key mappings for this player */ public class Player { private int id; private TankSet tankSet; private Controls controls; /** * @effects Creates a new Player with given ID, controls, and tank limit */ public Player(int id, Controls controls, int maxTanks) { this.id = id; this.controls = controls; this.tankSet = new TankSet(this, maxTanks); } /** * @effects Returns the player's ID */ public int getId() { return id; } /** * @effects Returns the player's tank set */ public TankSet getTankSet() { return tankSet; } /** * @effects Returns the player's controls */ public Controls getControls() { return controls; } /** * @effects Adds a tank to the player's tank set * @return true if successful, false otherwise */ public boolean addTank(Tank tank) { return tankSet.addTank(tank); } /** * @effects Removes a tank from the player's tank set * @return true if successful, false otherwise */ public boolean removeTank(Tank tank) { return tankSet.removeTank(tank); } /** * @effects Gets the player's currently active tank */ public Tank getActiveTank() { return tankSet.getActiveTank(); } /** * @effects Switches to the player's next tank * @return true if successful, false if no other tanks available */ public boolean nextTank() { return tankSet.nextTank(); } /** * @effects Checks if the player has lost (no tanks left) */ public boolean hasLost() { return tankSet.isEmpty(); } /** * @effects Returns a string representation of this player */ @Override public String toString() { return "Player " + id + " with " + tankSet.size() + " tanks"; } }