2020-02-13 19:46:00 +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/>.
|
|
|
|
*/
|
|
|
|
|
2020-02-05 15:01:40 +01:00
|
|
|
package de.itsblue.ConnectFour;
|
2020-02-17 08:38:16 +01:00
|
|
|
|
2020-02-14 19:21:49 +01:00
|
|
|
import java.awt.*;
|
2020-02-05 15:29:52 +01:00
|
|
|
|
2020-02-16 19:46:57 +01:00
|
|
|
/**
|
2020-02-17 08:38:16 +01:00
|
|
|
* Plate models to plate or 'coin' to be inserted into game grid. It therefore
|
|
|
|
* has a type (X or O) which comes with a color (X = RED; O = BLACK) and a value
|
|
|
|
* (X = -1; O = 1) for further processing. this is a helper class and does not
|
|
|
|
* come with any standalone usage.
|
2020-02-16 19:46:57 +01:00
|
|
|
*
|
|
|
|
* @author Oliver Schappacher
|
|
|
|
* @author Dorian Zedler
|
|
|
|
*/
|
2020-02-14 19:21:49 +01:00
|
|
|
public class Plate {
|
2020-02-05 15:01:40 +01:00
|
|
|
|
2020-02-14 19:21:49 +01:00
|
|
|
/**
|
|
|
|
* Enum containing all plate types
|
|
|
|
*/
|
2020-02-24 22:54:37 +01:00
|
|
|
public enum PlateType {
|
2020-02-05 15:29:52 +01:00
|
|
|
X, O
|
|
|
|
}
|
|
|
|
|
2020-02-14 19:21:49 +01:00
|
|
|
/**
|
|
|
|
* The tpe of the plate object
|
|
|
|
*/
|
2020-02-05 15:29:52 +01:00
|
|
|
private PlateType type;
|
|
|
|
|
2020-02-14 19:21:49 +01:00
|
|
|
/**
|
|
|
|
* Constructor
|
2020-02-16 19:46:57 +01:00
|
|
|
*
|
2020-02-14 19:21:49 +01:00
|
|
|
* @param type type of the plate
|
|
|
|
*/
|
2020-02-24 22:54:37 +01:00
|
|
|
public Plate(PlateType type) {
|
2020-02-16 19:46:57 +01:00
|
|
|
this.type = type;
|
2020-02-05 15:29:52 +01:00
|
|
|
}
|
|
|
|
|
2020-02-14 19:21:49 +01:00
|
|
|
/**
|
|
|
|
* Function to get the type of the plate
|
2020-02-16 19:46:57 +01:00
|
|
|
*
|
2020-02-14 19:21:49 +01:00
|
|
|
* @return PlateType
|
|
|
|
*/
|
2020-02-16 19:46:57 +01:00
|
|
|
public PlateType getType() {
|
2020-02-14 19:21:49 +01:00
|
|
|
return this.type;
|
2020-02-05 15:29:52 +01:00
|
|
|
}
|
|
|
|
|
2020-02-14 19:21:49 +01:00
|
|
|
/**
|
2020-02-16 19:46:57 +01:00
|
|
|
* Function to get the type of the plate as int
|
2020-02-14 19:21:49 +01:00
|
|
|
*
|
2020-02-16 19:46:57 +01:00
|
|
|
* @return plate type as int (O=1; X=-1)
|
2020-02-14 19:21:49 +01:00
|
|
|
*/
|
2020-02-16 19:46:57 +01:00
|
|
|
public int getValue() {
|
2020-02-24 22:54:37 +01:00
|
|
|
return Plate.getValue(this.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to get a PlateType as int
|
|
|
|
*
|
|
|
|
* @return plate type as int (O=1; X=-1)
|
|
|
|
*/
|
|
|
|
public static int getValue(PlateType type) {
|
|
|
|
switch (type) {
|
|
|
|
case O:
|
|
|
|
return 1;
|
|
|
|
case X:
|
|
|
|
return -1;
|
|
|
|
default:
|
|
|
|
return 0;
|
2020-02-16 19:46:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to get the color of the plate
|
|
|
|
*
|
|
|
|
* @return the color of the plate
|
|
|
|
*/
|
|
|
|
public Color getColor() {
|
2020-02-24 22:54:37 +01:00
|
|
|
return Plate.getColor(this.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to get the color of a certian PlateType
|
|
|
|
*
|
|
|
|
* @return the color of the PlateType
|
|
|
|
*/
|
|
|
|
public static Color getColor(PlateType type) {
|
|
|
|
switch (type) {
|
|
|
|
case O:
|
|
|
|
return Color.BLACK;
|
|
|
|
case X:
|
|
|
|
return Color.RED;
|
|
|
|
default:
|
|
|
|
return Color.WHITE;
|
2020-02-16 19:46:57 +01:00
|
|
|
}
|
2020-02-05 15:01:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|