Ejemplo n.º 1
0
    //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();
            }
        }
    }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
 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");
 }
Ejemplo n.º 4
0
    //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;
        }
    }
Ejemplo n.º 5
0
 public override int GetHashCode()
 {
     return(CrossOrCircle.GetHashCode() + Grid.GetHashCode());
 }
Ejemplo n.º 6
0
 public Piece(CrossOrCircle crossOrCircle, Grid grid, bool cursor = false)
 {
     CrossOrCircle = crossOrCircle;
     Grid          = grid;
     Cursor        = cursor;
 }