import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBuilder;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Text;
public class MouseClickHandler implements EventHandler<MouseEvent> {
gamePane pane = new gamePane(650, 700, 3);
int firstCol, firstRow, cardCol, cardRow, clickNum;
int pileNum[] = new int[1];
Card pileCard1[] = new Card[60];
Card pileCard2[][] = new Card[5][12];
Card handCard[][] = new Card[2][8];
Card disCard[] = new Card[5];
Card disCard1[][] = new Card[5][12];
Card playerCard[][] = new Card[5][12];
Card computerCard[][] = new Card[5][12];
AnchorPane pilePane = new AnchorPane();
AnchorPane handPane[] = new AnchorPane[2];
AnchorPane disPane[] = new AnchorPane[5];
AnchorPane playPane[] = new AnchorPane[5];
int disNum[] = new int[5];
int playNum[] = new int[10];
int t[] = new int[10];
Button pointBtn[] = new Button[10];
Text newText[] = new Text[10];
Text pileNumText = new Text();
Text newpileNumText = new Text();
Thread thread;
int disCardIndex;
int handCardTurn;
boolean throwCards = false;
int rounds;
int playerPoint[] = new int[3];
int computerPoint[] = new int[3];
Button dealBtn = new Button();
Button undoBtn = new Button();
boolean undo = false;
public MouseClickHandler(gamePane pane5, Card card[], Card pileC[][],
Card card1[][], Card card2[], Card card3[][], Card card4[][],
Card card5[][], int col1, int row1, int col2, int row2, int num,
int handTurn, int dis[], int play[], int text[], int pile[],
AnchorPane pane1, AnchorPane pane2[], AnchorPane pane3[],
AnchorPane pane4[], Button btn[], Text newt[], Text pileNumT,
Text newPile, Thread t, int r, Button deal, Button undo) {
pane = pane5;
pileCard1 = card;
pileCard2 = pileC;
handCard = card1;
disCard = card2;
disCard1 = card3;
playerCard = card4;
computerCard = card5;
firstCol = col1;
firstRow = row1;
cardCol = col2;
cardRow = row2;
clickNum = num;
handCardTurn = handTurn;
disNum = dis;
playNum = play;
this.t = text;
pileNum = pile;
pilePane = pane1;
handPane = pane2;
pointBtn = btn;
newText = newt;
disPane = pane3;
playPane = pane4;
pileNumText = pileNumT;
newpileNumText = newPile;
thread = t;
rounds = r;
dealBtn = deal;
undoBtn = undo;
}
public void handle(MouseEvent mouEvt) {
double x = mouEvt.getX(), y = mouEvt.getY();
if (clickNum == 0 && y > 630 && y < 690 && x > 30 && x < 430) {
firstCol = cardCol = (int) ((x - 30) / 50);
firstRow = cardRow = 0;
handCard[1][cardCol + cardRow].setOpacity(0.5);
clickNum++;
} else if (clickNum == 1) {
if (x > 30 && x < 80)
disCardIndex = 0;
if (x > 110 && x < 160)
disCardIndex = 1;
if (x > 190 && x < 240)
disCardIndex = 2;
if (x > 270 && x < 320)
disCardIndex = 3;
if (x > 350 && x < 400)
disCardIndex = 4;
if (x > 30 && x < 430 && y > 630 && y < 690) {
cardCol = (int) ((x - 30) / 50);
if (firstCol == cardCol && firstRow == cardRow) {
handCard[1][firstCol + firstRow].setOpacity(1);
clickNum = 0;
} else {
handCard[1][firstCol + firstRow].setOpacity(1);
handCard[1][cardCol + cardRow].setOpacity(0.5);
firstCol = cardCol;
firstRow = cardRow;
}
} else if (x > 30 && x < 400 && y > 320 && y < 380) {
if (disCard[disCardIndex].type == handCard[1][cardCol + cardRow].type) {
handCard[1][cardCol + cardRow].setOpacity(1);
cardAction cardAct = new cardAction();
disCard1[disCardIndex][disNum[disCardIndex]] = cardAct
.throwCards(handCard[1][cardCol + cardRow],
handPane[1], disPane[disCardIndex],
handCard, disCardIndex,
disNum[disCardIndex]);
throwCards = true;
clickNum++;
disNum[disCardIndex]++;
if (clickNum == 2) {
undoBtn.setDisable(false);
undoBtn.setOnMouseClicked(new EventHandler<MouseEvent>() {
public void handle(MouseEvent e) {
cardAction cardAct = new cardAction();
handCard[1][cardCol + cardRow] = cardAct
.undoAction(handCard[1][cardCol
+ cardRow],
disPane[disCardIndex],
handPane[1], cardCol);
throwCards = false;
clickNum--;
disCard1[disCardIndex][disNum[disCardIndex]] = null;
disNum[disCardIndex]--;
undoBtn.setDisable(true);
clickNum = 0;
}
});
}
}
} else if (y > 380 && y < 630) {
if (handCard[1][cardCol + cardRow].type == disCard[disCardIndex].type) {
handCard[1][cardCol + cardRow].setOpacity(1);
cardAction cardAct = new cardAction();
if (playNum[disCardIndex] == 0
|| (playNum[disCardIndex] != 0 && playerCard[disCardIndex][playNum[disCardIndex] - 1].number <= handCard[1][cardCol
+ cardRow].number)) {
cardAct.playCards(handCard[1][cardCol + cardRow],
handPane[1], playPane[disCardIndex], handCard,
disCardIndex, playNum[disCardIndex]);
throwCards = false;
playerCard[disCardIndex][playNum[disCardIndex]] = handCard[1][cardCol
+ cardRow];
playNum[disCardIndex]++;
clickNum++;
gameResult gr = new gameResult();
gr.playerPointResult(playerCard, playNum, t);
for (int i = 0; i < 10; i++) {
if (t[i] == 0)
newText[i].setText(t[i] + ".0");
else
newText[i].setText(t[i] + "");
pointBtn[i].textProperty().bind(
newText[i].textProperty());
}
playerPoint[3 - rounds] = t[0] + t[1] + t[2] + t[3]
+ t[4];
if (clickNum == 2) {
undoBtn.setDisable(false);
undoBtn.setOnMouseClicked(new EventHandler<MouseEvent>() {
public void handle(MouseEvent e) {
cardAction cardAct = new cardAction();
handCard[1][cardCol + cardRow] = cardAct
.undoAction(handCard[1][cardCol
+ cardRow],
playPane[disCardIndex],
handPane[1], cardCol);
throwCards = true;
playerCard[disCardIndex][playNum[disCardIndex]] = null;
playNum[disCardIndex]--;
gameResult gr = new gameResult();
gr.playerPointResult(playerCard, playNum, t);
for (int i = 0; i < 10; i++) {
if (t[i] == 0)
newText[i].setText(t[i] + ".0");
else
newText[i].setText(t[i] + "");
pointBtn[i].textProperty().bind(
newText[i].textProperty());
}
playerPoint[3 - rounds] = t[0] + t[1]
+ t[2] + t[3] + t[4];
undoBtn.setDisable(true);
clickNum = 0;
}
});
}
} else if (playNum[disCardIndex] > 0
&& (handCard[1][cardCol + cardRow].number == 0 && playerCard[disCardIndex][playNum[disCardIndex] - 1].number != 0)) {
handCard[1][cardCol + cardRow].setOpacity(1);
clickNum = 0;
} else {
clickNum = 0;
}
} else {
handCard[1][cardCol + cardRow].setOpacity(1);
clickNum = 0;
}
}
} else if (clickNum == 2) {
if (y > 320 && y < 380) {
int disIndex = 0;
if (x > 30 && x < 80)
disIndex = 0;
if (x > 110 && x < 160)
disIndex = 1;
if (x > 190 && x < 240)
disIndex = 2;
if (x > 270 && x < 320)
disIndex = 3;
if (x > 350 && x < 400)
disIndex = 4;
if (x > 30 && x < 400) {
if ((throwCards != true || (throwCards == true && disCardIndex != disIndex))
&& disNum[disIndex] != 0) {
cardAction cardAct = new cardAction();
handCard[1][cardCol + cardRow] = cardAct
.drawCardsFromDiscard(
disCard1[disIndex][disNum[disIndex] - 1],
disPane[disIndex], handPane[1],
handCard, cardCol, 310);
disCard1[disIndex][disNu