private void SelectChessman(int x, int y) { if (Chessmoves[x, y] == null) { return; } if (Chessmoves[x, y].isWhite != isWhiteTurn) { return; } bool hasAtleastOneMove = false; allowedMoves = Chessmoves[x, y].PossibleMove(); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (allowedMoves[i, j]) { hasAtleastOneMove = true; } } } allowedMoves = Chessmoves[x, y].PossibleMove(); selectedChessman = Chessmoves[x, y]; previousMat = selectedChessman.GetComponent <MeshRenderer>().material; selectedMat.mainTexture = previousMat.mainTexture; selectedChessman.GetComponent <MeshRenderer>().material = selectedMat; BoardHighlights.Instance.HighlightAllowedMoves(allowedMoves); }
private void MoveChessman(int x, int y) { if (allowedMoves[x, y]) { Chessmove c = Chessmoves[x, y]; if (c != null && c.isWhite != isWhiteTurn) { //if its the king if (c.GetType() == typeof(King)) { EndGame(); return; } //Destroyed A peice activeChessman.Remove(c.gameObject); Destroy(c.gameObject); } if (x == EnPassantMove[0] && y == EnPassantMove[1]) { if (isWhiteTurn) { c = Chessmoves[x, y - 1]; activeChessman.Remove(c.gameObject); Destroy(c.gameObject); } else { c = Chessmoves[x, y + 1]; activeChessman.Remove(c.gameObject); Destroy(c.gameObject); } } EnPassantMove[0] = -1; EnPassantMove[1] = -1; if (selectedChessman.GetType() == typeof(Pawn)) { if (y == 7) { activeChessman.Remove(selectedChessman.gameObject); Destroy(selectedChessman.gameObject); SpawnChess(9, x, y); selectedChessman = Chessmoves[x, y]; } else if (y == 0) { activeChessman.Remove(selectedChessman.gameObject); Destroy(selectedChessman.gameObject); SpawnChess(3, x, y); selectedChessman = Chessmoves[x, y]; } if (selectedChessman.CurrentY == 1 && y == 3) { EnPassantMove[0] = x; EnPassantMove[1] = y - 1; } else if (selectedChessman.CurrentY == 6 && y == 4) { EnPassantMove[0] = x; EnPassantMove[1] = y + 1; } } Chessmoves[selectedChessman.CurrentX, selectedChessman.CurrentY] = null; selectedChessman.transform.position = GetTileCenter(x, y); selectedChessman.SetPosition(x, y); Chessmoves[x, y] = selectedChessman; isWhiteTurn = !isWhiteTurn; } selectedChessman.GetComponent <MeshRenderer>().material = previousMat; BoardHighlights.Instance.Hidehighlights(); selectedChessman = null; }