package card;
import game.SwingGame;
import game.AbstractGame.MSG_TYPES;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
public class SwingCard extends Card {
JLabel face;
public SwingCard(int color, int value, int playerId, SwingGame swingGame) {
super(color, value, playerId, swingGame);
}
public void setFace(JLabel face){
this.face = face;
face.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
face.setFont(((Font) g.getFont()).deriveFont(g.getFontSize()*2));
addMouseListener();
}
public JLabel getFace(){
return face;
}
private void addMouseListener(){
face.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
if(face.getBackground() == Color.pink){
g.removeSelectedCards();
face.setBackground(Color.black);
//System.out.println("Removed card #" + clickedCard + "(" + card.getColorInt() + ", " + card.getValue() + ")");
if(g.getSelectedCards() == 0){
g.resetMoveValues();
}
}
if(!g.isUseColor() && !g.isUseValue() && !g.isTrashCard() && !g.isPlaceCard()){
g.printMessage("Please choose move type first", MSG_TYPES.ERROR);
return;
}
if(playerId == g.getCurrentPlayerIndex()){
if(g.isUseColor() || g.isUseValue()){
g.printMessage("Please don't select your own cards!", MSG_TYPES.ERROR);
return;
} else if((g.isTrashCard() || g.isPlaceCard()) && g.getSelectedCards() == 1){
g.printMessage("You already selected a card!", MSG_TYPES.ERROR);
return;
}
} else if(playerId != g.getCurrentPlayerIndex() && (g.isTrashCard() || g.isPlaceCard())){
g.printMessage("Please select your own cards", MSG_TYPES.ERROR);
return;
}
if(g.getSelectedPlayer() == -1){
g.setSelectedPlayer(playerId);
g.setChosenColor(color);
g.setChosenValue(value);
g.addSelectedCards();
face.setBackground(Color.pink);
return;
}
if(g.getSelectedPlayer() != playerId){
g.printMessage("Please choose a card of the selected player or unselect all cards and choose another player.", MSG_TYPES.ERROR);
return;
}
if(g.getChosenColor() == -1){
g.setChosenColor(color);
}
if(g.getChosenValue() == -1){
g.setChosenValue(value);
}
if(face.getBackground() == Color.black){
if(g.isUseColor()){
if(g.getChosenColor() == color){
if(face.getBackground() != Color.pink){
g.addSelectedCards();
face.setBackground(Color.pink);
//System.out.println("Added card #" + clickedCard + "(" + intColorToText(card.getColorInt()) + ", " + card.getValue() + ")");
}
}
} else if(g.isUseValue()){
if(g.getChosenValue() == value){
if(face.getBackground() != Color.pink){
g.addSelectedCards();
face.setBackground(Color.pink);
//System.out.println("Added card #" + clickedCard + "(" + intColorToText(card.getColorInt()) + ", " + card.getValue() + ")");
}
}
}
}
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
});
}
}