/**
 * Abstrakte Repräsentation eines Spielers, der an einem anderen gerät spielt
 * und durch eine Online Verbindung mit dieser Instanz kommuniziert
 * @author Luca Conte, Peer Ole Wachtel
 */
public abstract class OnlinePlayer extends Player implements AsyncSocketListener {
    protected AsyncSocket socket;
    protected int wantedBoardSize;

    protected boolean hasReceivedCoinPackage;

    /**
     * Constructor
     * @param size the size of the board the enemy player wants to play with
     * the actual board size will be determined once the semester of the online partner is known
     * @param socket an AsyncSocket to communicate with the enemy through
     * @author Peer Ole Wachtel, Luca Conte
     */
    public OnlinePlayer(Integer size, AsyncSocket socket) {
        this.socket = socket;
        this.wantedBoardSize = size;
        this.myCoin = null;
        socket.setHandler(this);
    }

    /**
     * sends the IAM Package for introduction
     * @author Luca Conte
     */
    public abstract void sendIAM();

    /**
     * receives a message from the AsyncSocket
     * satisfies AsyncSocketListener interface
     * @author Luca Conte
     */
    public abstract void receive(String message);

    /**
     * receives the coin toss result from the enemy
     * @param coin the result of the coin toss
     * @author Peer Ole Wachtel
     */
    @Override
    public abstract void receiveCoin(boolean coin);

    /**
     * closes the socket and does player cleanup work
     * @author Luca Conte
     */
    @Override
    public void destroy() {
        super.destroy();
        this.socket.close();
    }

}
