/* Connect four - written in java Copyright (C) 2020 Oliver Schappacher and Dorian Zedler This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package de.itsblue.ConnectFour.player; import de.itsblue.ConnectFour.Plate.*; import java.util.ArrayList; import de.itsblue.ConnectFour.*; /** * Player is an abstract class meant for usage with de.itsblue.ConnectFour. It * is a template for a connect four player. * * @author Dorian Zedler */ public abstract class Player { /** * The button row used to control the game. */ public ButtonRow gameControllingButtonRow; /** * The type of plate the player is using. */ public PlateType usingPlateType; /** * An array containing all move listeners */ ArrayList playerMoveListeners = new ArrayList(); /** * Whether it is this player's turn */ public boolean isMyTurn = false; /** * Constructor * * @param gameControllingButtonRow The button row used to control the game. * @param usingPlateType The type of plate the player is using. */ public Player(ButtonRow gameControllingButtonRow, PlateType usingPlateType) { this.gameControllingButtonRow = gameControllingButtonRow; this.usingPlateType = usingPlateType; } /** * Function to set wether it is this player's turn */ public void setIsMyTurn(boolean isMyTurn) { this.isMyTurn = isMyTurn; if (isMyTurn) this.gameControllingButtonRow.setColor(Plate.getColor(this.usingPlateType)); } /** * Function to perform a move for the Player * * @param column the column to insert the plate into */ public void doMove(int column) { if (this.isMyTurn){ System.out.println("[LOG] " + Plate.getColor(this.usingPlateType) + " is doing a move in col: " + column); for (PlayerMoveListener playerMoveListener : playerMoveListeners) { playerMoveListener.movePerformed(column, this); } } } /** * Function to add a move listener * * @param listener the listener to add */ public void addMoveListener(PlayerMoveListener listener) { this.playerMoveListeners.add(listener); } /** * Function to remove a move listener * * @param listener the listener to remove */ public void removeMoveListener(PlayerMoveListener listener) { if(this.playerMoveListeners.contains(listener)) this.playerMoveListeners.remove(listener); } }