private void Start() { whoTurn = chessState.Black; storeChess = GameObject.FindWithTag("Parent").transform; grid = new int[15, 15]; gameStart = true; }
public bool ChessPos(int[] pos) { if (!gameStart) { return(false); } //Camera position(0,0),but to the board is actually (7,7); //So the x is restricted in (0,14), the same to the y Pos; pos[0] = Mathf.Clamp(pos[0], 0, 14); pos[1] = Mathf.Clamp(pos[1], 0, 14); //float width = board.GetComponent<RectTransform>().rect.width; //float height = board.GetComponent<RectTransform>().rect.height; //Vector3 startPos = board.transform.position; //startPos.x -= width * canvas.transform.localScale.x / 2; //startPos.y += height * canvas.transform.localScale.y / 2; //if is Black turn, we spawn black prefabs in gird[7,7], but actually is woldPos(0,0); if (whoTurn == chessState.Black) { GameObject blackChess = Instantiate(prefabs[0], new Vector3(pos[0] - 7, pos[1] - 7), Quaternion.identity); //set balck as 1 grid[pos[0], pos[1]] = 1; //add this transform into our stack chessStack.Push(blackChess.transform); //store blackChess prefabs blackChess.transform.SetParent(storeChess); if (hasWinner(pos)) { GameOver(); } whoTurn = chessState.White; } else if (whoTurn == chessState.White) { GameObject whiteChess = Instantiate(prefabs[1], new Vector3(pos[0] - 7, pos[1] - 7), Quaternion.identity); //set white as 2 grid[pos[0], pos[1]] = 2; //add this transform into our stack chessStack.Push(whiteChess.transform); //store whiteChess prefabs whiteChess.transform.SetParent(storeChess); if (hasWinner(pos)) { GameOver(); } whoTurn = chessState.Black; } return(true); }