2020-02-24 22:54:37 +01:00
|
|
|
/*
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package de.itsblue.ConnectFour.player;
|
|
|
|
|
|
|
|
import de.itsblue.ConnectFour.Plate.*;
|
2020-02-25 02:10:57 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2020-02-24 22:54:37 +01:00
|
|
|
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;
|
|
|
|
|
2020-02-25 02:10:57 +01:00
|
|
|
/**
|
|
|
|
* An array containing all move listeners
|
|
|
|
*/
|
|
|
|
ArrayList<PlayerMoveListener> playerMoveListeners = new ArrayList<PlayerMoveListener>();
|
|
|
|
|
2020-02-24 22:54:37 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2020-02-25 02:10:57 +01:00
|
|
|
public Player(ButtonRow gameControllingButtonRow, PlateType usingPlateType) {
|
2020-02-24 22:54:37 +01:00
|
|
|
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) {
|
2020-02-25 02:10:57 +01:00
|
|
|
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);
|
2020-02-24 22:54:37 +01:00
|
|
|
}
|
|
|
|
}
|