public void EnableThis(DominoPiece piece)
 {
     dominoPiece = piece;
     this.GetComponent <Image>().sprite  = dominoPiece.sprite;
     this.GetComponent <Image>().enabled = true;
 }
Exemple #2
0
    IEnumerator SetUp()
    {
        for (int i = 0; i < player1hand.Length; i++)
        {
            int         random      = UnityEngine.Random.Range(0, holder.dominoPieces.Length);
            DominoPiece dominoPiece = holder.dominoPieces[random];
            RemoveAt <DominoPiece>(ref holder.dominoPieces, random);
            player1hand[i].GetComponent <Domino>().dominoPiece = dominoPiece;
            player1hand[i].SetActive(true);
            player1hand[i].GetComponent <Domino>().isInPlayer1Hand = true;
            player1hand[i].GetComponent <Domino>().UpdateGraphics();
            player1hand[i].GetComponent <Domino>().UpdateAvailability();
            if (player1hand[i].GetComponent <Domino>().dominoPiece.isDoublePiece)
            {
                player1hand[i].GetComponent <Domino>().UpdateAvailability();
                if (player1hand[i].GetComponent <Domino>().dominoPiece.totalValue > highestDouble)
                {
                    highestDouble          = player1hand[i].GetComponent <Domino>().dominoPiece.totalValue;
                    indexOfBiggestPiece    = i;
                    playerWithBiggestPiece = 1;
                }
            }
        }

        yield return(new WaitForSeconds[1]);

        for (int i = 0; i < player2hand.Length; i++)
        {
            int         random      = UnityEngine.Random.Range(0, holder.dominoPieces.Length);
            DominoPiece dominoPiece = holder.dominoPieces[random];
            RemoveAt <DominoPiece>(ref holder.dominoPieces, random);
            player2hand[i].GetComponent <Domino>().dominoPiece = dominoPiece;
            player2hand[i].SetActive(true);
            player2hand[i].GetComponent <Domino>().isInPlayer2Hand = true;
            player2hand[i].GetComponent <Domino>().UpdateGraphics();
            player2hand[i].GetComponent <Domino>().UpdateAvailability();
            if (player2hand[i].GetComponent <Domino>().dominoPiece.isDoublePiece)
            {
                player2hand[i].GetComponent <Domino>().UpdateAvailability();
                if (player2hand[i].GetComponent <Domino>().dominoPiece.totalValue > highestDouble)
                {
                    highestDouble          = player2hand[i].GetComponent <Domino>().dominoPiece.totalValue;
                    indexOfBiggestPiece    = i;
                    playerWithBiggestPiece = 2;
                }
            }
        }

        yield return(new WaitForSeconds[1]);


        if (playerWithBiggestPiece == 1)
        {
            currentState = State.Player1Turn;
            Debug.Log(currentState);
        }

        if (playerWithBiggestPiece == 2)
        {
            currentState = State.Player2Turn;
            StartCoroutine(Player2Turn());
            Debug.Log(currentState);
        }
    }
    public void PlayPiece(DominoPiece piece)
    {
        hasBeenPlaced = false;

        if (totalPlayedPieces == 0)
        {
            startingDomino.SetActive(true);
            startingDomino.GetComponent <DominoBoard>().EnableThis(piece);

            startingDomino.GetComponent <DominoBoard>().isRightPositionFree = true;
            startingDomino.GetComponent <DominoBoard>().isLeftPositionFree  = true;

            rightPositionValue = startingDomino.GetComponent <DominoBoard>().dominoPiece.upValue;
            leftPositionValue  = startingDomino.GetComponent <DominoBoard>().dominoPiece.downValue;

            lastPlayedRightDomino = startingDomino;
            lastPlayedLeftDomino  = startingDomino;

            totalPlayedPieces++;
            hasBeenPlaced = true;
        }
        else if (totalPlayedPieces > 0 && totalPlayedPieces <= 14)
        {
            if (leftPositionValue == piece.downValue || rightPositionValue == piece.downValue || leftPositionValue == piece.upValue || leftPositionValue == piece.downValue)
            {
                if (leftPositionValue == piece.downValue && !hasBeenPlaced)
                {
                    lastPlayedLeftDomino.GetComponent <DominoBoard>().leftPosition.SetActive(true);
                    dominoToEnable = lastPlayedLeftDomino.GetComponent <DominoBoard>().leftPosition;
                    dominoToEnable.GetComponent <DominoBoard>().EnableThis(piece);
                    lastPlayedLeftDomino = dominoToEnable;
                    leftPositionValue    = piece.upValue;
                    hasBeenPlaced        = true;
                    Debug.Log("Matching leftSide with downValue");
                }
                if (leftPositionValue == piece.upValue && !hasBeenPlaced)
                {
                    lastPlayedLeftDomino.GetComponent <DominoBoard>().leftPosition.SetActive(true);
                    dominoToEnable = lastPlayedLeftDomino.GetComponent <DominoBoard>().leftPosition;
                    dominoToEnable.GetComponent <DominoBoard>().EnableThis(piece);
                    lastPlayedLeftDomino = dominoToEnable;
                    //lastPlayedLeftDomino.transform.Rotate(0, 0, -90);
                    leftPositionValue = piece.downValue;
                    hasBeenPlaced     = true;

                    Debug.Log("Matching leftSide with upValue");
                }

                if (rightPositionValue == piece.downValue && !hasBeenPlaced)
                {
                    lastPlayedRightDomino.GetComponent <DominoBoard>().rightPosition.SetActive(true);
                    dominoToEnable = lastPlayedRightDomino.GetComponent <DominoBoard>().rightPosition;
                    dominoToEnable.GetComponent <DominoBoard>().EnableThis(piece);
                    lastPlayedRightDomino = dominoToEnable;
                    rightPositionValue    = piece.upValue;
                    //lastPlayedRightDomino.transform.Rotate(0, 0, -90);
                    hasBeenPlaced = true;
                    Debug.Log("Matching right side with downValue");
                }
                if (rightPositionValue == piece.upValue && !hasBeenPlaced)
                {
                    lastPlayedRightDomino.GetComponent <DominoBoard>().rightPosition.SetActive(true);
                    dominoToEnable = lastPlayedRightDomino.GetComponent <DominoBoard>().rightPosition;
                    dominoToEnable.GetComponent <DominoBoard>().EnableThis(piece);
                    lastPlayedRightDomino = dominoToEnable;
                    leftPositionValue     = piece.downValue;
                    //lastPlayedRightDomino.transform.Rotate(0, 0, -90);

                    hasBeenPlaced = true;

                    Debug.Log("Matching right side with upValue");
                }
            }
        }
    }