////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////

package pp.battleship.game.server;

import pp.battleship.BattleshipConfig;
import pp.battleship.model.ShipMap;

/**
 * Class representing a player
 */
public class Player {
    private final ShipMap map;
    private final String name;
    private final int id;

    /**
     * Creates new Player
     *
     * @param id     the id of the connection to the client represented by this player
     * @param name   the human-readable name of this player
     * @param config model holding the player
     */
    Player(int id, String name, BattleshipConfig config) {
        this.id = id;
        this.name = name;
        map = new ShipMap(config.getMapWidth(), config.getMapHeight(), null);
    }

    /**
     * Returns the id of the connection to the client represented by this player.
     *
     * @return the id
     */
    public int getId() {
        return id;
    }

    @Override
    public String toString() {
        return String.format("Player(%s,%s)", name, id); //NON-NLS
    }

    /**
     * @return map containing own ships and shots
     */
    public ShipMap getMap() {
        return map;
    }
}
