/* 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; import java.awt.*; /** * 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. * * @author Oliver Schappacher * @author Dorian Zedler */ public class Plate { /** * Enum containing all plate types */ public enum PlateType { X, O } /** * The tpe of the plate object */ private PlateType type; /** * Constructor * * @param type type of the plate */ public Plate(PlateType type) { this.type = type; } /** * Function to get the type of the plate * * @return PlateType */ public PlateType getType() { return this.type; } /** * Function to get the type of the plate as int * * @return plate type as int (O=1; X=-1) */ public int getValue() { return Plate.getValue(this.type); } /** * Function to get the type of the plate as string * * @return "yellow" or "red" */ public String getName() { return Plate.getName(this.type); } /** * Function to get the type of the plate as string * * @param type plate type * * @return "yellow" or "red" */ public static String getName(PlateType type) { switch (type) { case O: return "yellow"; case X: return "red"; default: return ""; } } /** * 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; } } /** * Function to get the color of the plate * * @return the color of the plate */ public Color getColor() { 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) { float[] hsb = new float[3]; switch (type) { case O: Color.RGBtoHSB(249, 227, 6, hsb); break; case X: Color.RGBtoHSB(246, 33, 61, hsb); break; } return Color.getHSBColor(hsb[0], hsb[1], hsb[2]); } }