bool checkXLeadDiag(Buttn[] but, Buttn clicked) { int leadDiag = 0; if ((clicked.getX() == 0 && clicked.getY() == 2) || (clicked.getX() == 1 && clicked.getY() == 1) || (clicked.getX() == 2 && clicked.getY() == 0)) { for (int i = 0; i < 9; i = i + 4) { if (but[i].getText() == "X") { leadDiag++; } else if (but[i].getText() == "O") { leadDiag = 0; break; } } } else if (leadDiag == 2) { for (int i = 0; i < 9; i = i + 4) { if (but[i].getText() == "") { but[i].setText("O"); return(true); } } } return(false); }
bool checkXRow(Buttn[] but, Buttn clicked) { int ys = 0; for (int i = (2 - clicked.getY()) * 3; i < (2 - clicked.getY()) * 3 + 3; i++) { if (but[i].getText() == "X") { ys++; } else if (but[i].getText() == "O") { ys = 0; break; } } if (ys == 2) { for (int i = (2 - clicked.getY()) * 3; i < (2 - clicked.getY()) * 3 + 3; i++) { if (but[i].getText() == "") { but[i].setText("O"); return(true); } } } return(false); }
void ChngTxt(Buttn x, Buttn[] y) { bool mid = false; int row = 0; int column = 0; int LeadDiag = 0; int Diag = 0; if (clicks % 2 == 0 && x.getText() == "") { x.setText("X"); xs++; if (xs > 2) { if (x.getX() - x.getY() == 0 || x.getX() - x.getY() == 2 || x.getX() - x.getY() == -2) { mid = true; } for (int i = 0; i < 9; i++) { if (y[i].getX() == x.getX() && y[i].getText() == "X") { column++; } if (y[i].getY() == x.getY() && y[i].getText() == "X") { row++; } if (mid && ((y[i].getX() == 0 && y[i].getY() == 2) || (y[i].getX() == 1 && y[i].getY() == 1) || (y[i].getX() == 2 && y[i].getY() == 0)) && y[i].getText() == "X") { LeadDiag++; } if (mid && ((y[i].getX() == 0 && y[i].getY() == 0) || (y[i].getX() == 1 && y[i].getY() == 1) || (y[i].getX() == 2 && y[i].getY() == 2)) && y[i].getText() == "X") { Diag++; } } if (row == 3 || column == 3 || LeadDiag == 3 || Diag == 3) { panel.SetActive(true); panelText.text = "X won"; } } clicks++; } if (clicks == 9 && (row != 3 && column != 3 && LeadDiag != 3 && Diag != 3)) { panel.SetActive(true); panelText.text = "Draw"; } }
bool checkXDiagonal(Buttn[] but, Buttn clicked) { int diag = 0; if (clicked.getX() == clicked.getY()) { for (int i = 2; i < 7; i = i + 2) { if (but[i].getText() == "X") { diag++; } else if (but[i].getText() == "O") { diag = 0; break; } } } if (diag == 2) { for (int i = 2; i < 7; i = i + 2) { if (but[i].getText() == "") { but[i].setText("O"); return(true); } } } return(false); }