//Player's move public void PlayerMove(GameObject button) { bool isFree = button.GetComponent <Cell>().innerValue == null; if (GameManager.instance.curPlayer != Player.User || !isFree) { return; } button.GetComponent <Cell>().SpawnFigure(nowFigureMoving); if (!IsThereAWinner()) { if (!Ai.IsThereAnyFreeCell()) { GameManager.instance.Increment(0, 0, 1); EndGameBoard.GetComponentInChildren <TMP_Text>().text = "DRAW"; EndGameBoard.transform.localScale = Vector2.one; } else { //Swap moving figure nowFigureMoving = (nowFigureMoving == CrossOrCircle.Cross) ? CrossOrCircle.Circle : CrossOrCircle.Cross; //Swap movin player GameManager.instance.curPlayer = Player.Computer; MakeComputerMove(); } } }
public override bool Equals(object obj) { if (!(obj is Piece)) { return(false); } Piece other = obj as Piece; return(CrossOrCircle.Equals(other.CrossOrCircle) && Grid.Equals(other.Grid)); }
public void SpawnFigure(CrossOrCircle crossOrCircle) { CrossOrCircleGO = Instantiate( crossOrCircle == CrossOrCircle.Circle ? GameManager.instance.circlePrefab : GameManager.instance.crossPrefab, transform.position, Quaternion.identity); CrossOrCircleGO.transform.localScale *= 0.4f; CrossOrCircleGO.transform.SetParent(this.gameObject.transform); gameObject.GetComponent <Button>().interactable = false; innerValue = crossOrCircle; Debug.Log(crossOrCircle.ToString() + " is spawned"); }
//Computer's move private void MakeComputerMove() { Ai.CalculateMoveCell().SpawnFigure(nowFigureMoving); if (!IsThereAWinner()) { //Swap moving figure nowFigureMoving = (nowFigureMoving == CrossOrCircle.Cross) ? CrossOrCircle.Circle : CrossOrCircle.Cross; //Swap movin player GameManager.instance.curPlayer = Player.User; } }
public override int GetHashCode() { return(CrossOrCircle.GetHashCode() + Grid.GetHashCode()); }
public Piece(CrossOrCircle crossOrCircle, Grid grid, bool cursor = false) { CrossOrCircle = crossOrCircle; Grid = grid; Cursor = cursor; }