Exemplo n.º 1
0
 public void ResetHand()
 {
     spinner = null;
     center  = null;
     foreach (DominoController domino in horizontalDominoes)
     {
         Destroy(domino.gameObject);
     }
     foreach (DominoController domino in verticalDominoes)
     {
         Destroy(domino.gameObject);
     }
     horizontalDominoes.Clear();
     verticalDominoes.Clear();
     isSpinnerPlaced         = false;
     putPosition             = PutPosition.NA;
     generalHorizontalOffset = 0;
     generalVerticalOffset   = 0;
     numberLeft  = 0;
     numberRight = 0;
     numberUp    = 0;
     numberDown  = 0;
     horizontalPositions.Clear();
     verticalPositions.Clear();
     horizontalRotations.Clear();
     verticalRotations.Clear();
     resetBoundaryPosition();
     fixOffset       = 0;
     isSpinnerOffset = false;
 }
Exemplo n.º 2
0
 void countPositionNumber(PutPosition putPosition)
 {
     if (putPosition == PutPosition.Left)
     {
         numberLeft++;
     }
     if (putPosition == PutPosition.Right)
     {
         numberRight++;
     }
     if (putPosition == PutPosition.Up)
     {
         numberUp++;
     }
     if (putPosition == PutPosition.Down)
     {
         numberDown++;
     }
     if (putPosition == PutPosition.NA)
     {
     }
 }
Exemplo n.º 3
0
    public void Add(DominoController playedDomino, DominoController historyDomino)
    {
        putPosition = PutPosition.NA;
        if (playedDomino == null)
        {
            throw new ArgumentNullException("playedDomino");
        }
        playedDomino.isObservableByAll = true;

        if (historyDomino == null)
        {
            center = playedDomino;
            center.offsetHorizontal = 0.0f;
            center.offsetVertical   = 0.0f;
            // Set Spinner
            Vector3 tempVector = OriginalPosition(playedDomino);
            if (playedDomino.direction == DominoController.Direction.Vertical)
            {
                isSpinnerPlaced = true;
                spinner         = playedDomino;
                horizontalDominoes.Add(playedDomino);
                verticalDominoes.Add(playedDomino);
                horizontalPositions.Add(new Vector3(playedDomino.transform.position.x, playedDomino.transform.position.y));
                verticalPositions.Add(new Vector3(playedDomino.transform.position.x, playedDomino.transform.position.y));
                horizontalRotations.Add(playedDomino.transform.rotation);
                verticalRotations.Add(playedDomino.transform.rotation);
            }
            else
            {
                horizontalDominoes.Add(playedDomino);
                horizontalPositions.Add(new Vector3(playedDomino.transform.position.x, playedDomino.transform.position.y));
                horizontalRotations.Add(playedDomino.transform.rotation);
            }
            return;
        }

        if (horizontalDominoes.Count > 0 && (historyDomino.Equals(horizontalDominoes[0]) || historyDomino.Equals(horizontalDominoes[horizontalDominoes.Count - 1])))
        {
            if (playedDomino.direction == DominoController.Direction.Horizontal && historyDomino.direction == DominoController.Direction.Horizontal)
            {
                if (playedDomino.rightValue == historyDomino.leftValue)
                {
                    putPosition = PutPosition.Left;
                }
                if (playedDomino.leftValue == historyDomino.rightValue)
                {
                    putPosition = PutPosition.Right;
                }
            }
            if (playedDomino.direction == DominoController.Direction.Horizontal && historyDomino.direction == DominoController.Direction.Vertical)
            {
                if (playedDomino.rightValue == historyDomino.upperValue)
                {
                    putPosition = PutPosition.Left;
                }
                if (playedDomino.leftValue == historyDomino.upperValue)
                {
                    putPosition = PutPosition.Right;
                }
            }
            if (playedDomino.direction == DominoController.Direction.Vertical && historyDomino.direction == DominoController.Direction.Horizontal)
            {
                if (playedDomino.upperValue == historyDomino.leftValue)
                {
                    putPosition = PutPosition.Left;
                }
                if (playedDomino.upperValue == historyDomino.rightValue)
                {
                    putPosition = PutPosition.Right;
                }
            }
        }
        else if (verticalDominoes.Count > 0 && (historyDomino.Equals(verticalDominoes[0]) || historyDomino.Equals(verticalDominoes[verticalDominoes.Count - 1])))
        //else
        {
            if (playedDomino.direction == DominoController.Direction.Vertical && historyDomino.direction == DominoController.Direction.Vertical)
            {
                if (playedDomino.lowerValue == historyDomino.upperValue)
                {
                    putPosition = PutPosition.Up;
                }
                if (playedDomino.upperValue == historyDomino.lowerValue)
                {
                    putPosition = PutPosition.Down;
                }
            }
            if (playedDomino.direction == DominoController.Direction.Horizontal && historyDomino.direction == DominoController.Direction.Vertical)
            {
                if (playedDomino.leftValue == historyDomino.upperValue)
                {
                    putPosition = PutPosition.Up;
                }
                if (playedDomino.leftValue == historyDomino.lowerValue)
                {
                    putPosition = PutPosition.Down;
                }
            }
            if (playedDomino.direction == DominoController.Direction.Vertical && historyDomino.direction == DominoController.Direction.Horizontal)
            {
                if (playedDomino.lowerValue == historyDomino.leftValue)
                {
                    putPosition = PutPosition.Up;
                }
                if (playedDomino.upperValue == historyDomino.leftValue)
                {
                    putPosition = PutPosition.Down;
                }
            }
        }

        countPositionNumber(putPosition);
        setGeneralOffset();

        if (putPosition == PutPosition.Left)
        {
//            Debug.Log("place left");
            horizontalDominoes.Insert(0, playedDomino);


            // calculate offset
            // both horizontal
            if (historyDomino.direction == playedDomino.direction)
            {
                playedDomino.offsetHorizontal = historyDomino.offsetHorizontal - dominoScale * (interval + Constants.dominoHeight);
                playedDomino.offsetVertical   = historyDomino.offsetVertical;
            }
            // one horizontal one vertical
            if (historyDomino.direction != playedDomino.direction)
            {
                playedDomino.offsetHorizontal = historyDomino.offsetHorizontal - (interval + 0.5f * dominoScale * (Constants.dominoHeight + Constants.dominoWidth));
                playedDomino.offsetVertical   = historyDomino.offsetVertical;
            }
            // set spinner
            if (!isSpinnerPlaced && playedDomino.direction == DominoController.Direction.Vertical)
            {
                spinner = playedDomino;
                verticalDominoes.Add(playedDomino);
                verticalPositions.Add(OriginalPosition(playedDomino));
                verticalRotations.Add(playedDomino.transform.rotation);
                isSpinnerPlaced = true;
            }
            horizontalPositions.Insert(0, OriginalPosition(playedDomino));
            horizontalRotations.Insert(0, playedDomino.transform.rotation);
        }
        else if (putPosition == PutPosition.Right)
        {
//            Debug.Log("place right");
            horizontalDominoes.Add(playedDomino);

            // calculate offset
            // both horizontal
            if (historyDomino.direction == playedDomino.direction)
            {
                playedDomino.offsetHorizontal = historyDomino.offsetHorizontal + dominoScale * (interval + Constants.dominoHeight);
                playedDomino.offsetVertical   = historyDomino.offsetVertical;
            }
            // one horizontal one vertical
            if (historyDomino.direction != playedDomino.direction)
            {
                playedDomino.offsetHorizontal = historyDomino.offsetHorizontal + (interval + 0.5f * dominoScale * (Constants.dominoHeight + Constants.dominoWidth));
                playedDomino.offsetVertical   = historyDomino.offsetVertical;
            }
            // set spinner
            if (!isSpinnerPlaced && playedDomino.direction == DominoController.Direction.Vertical)
            {
                spinner = playedDomino;
                verticalDominoes.Add(playedDomino);
                verticalPositions.Add(OriginalPosition(playedDomino));
                verticalRotations.Add(playedDomino.transform.rotation);
                isSpinnerPlaced = true;
            }
            horizontalPositions.Add(OriginalPosition(playedDomino));
            horizontalRotations.Add(playedDomino.transform.rotation);
        }
        //VERTICAL
        else if (putPosition == PutPosition.Up)
        {
//            Debug.Log("place up");
            verticalDominoes.Insert(0, playedDomino);

            // both vertical
            if (historyDomino.direction == playedDomino.direction)
            {
                playedDomino.offsetVertical   = historyDomino.offsetVertical + (interval + dominoScale * Constants.dominoHeight);
                playedDomino.offsetHorizontal = historyDomino.offsetHorizontal;
            }
            // one horizontal one vertical
            if (historyDomino.direction != playedDomino.direction)
            {
                playedDomino.offsetVertical   = historyDomino.offsetVertical + (interval + 0.5f * dominoScale * (Constants.dominoHeight + Constants.dominoWidth));
                playedDomino.offsetHorizontal = historyDomino.offsetHorizontal;
            }
            verticalPositions.Insert(0, OriginalPosition(playedDomino));
            verticalRotations.Insert(0, playedDomino.transform.rotation);
        }
        else if (putPosition == PutPosition.Down)
        {
//            Debug.Log("place down");
            verticalDominoes.Add(playedDomino);

            // both vertical
            if (historyDomino.direction == playedDomino.direction)
            {
                playedDomino.offsetVertical   = historyDomino.offsetVertical - (interval + dominoScale * Constants.dominoHeight);
                playedDomino.offsetHorizontal = historyDomino.offsetHorizontal;
            }
            // one horizontal one vertical
            if (historyDomino.direction != playedDomino.direction)
            {
                playedDomino.offsetVertical   = historyDomino.offsetVertical - (interval + 0.5f * dominoScale * (Constants.dominoHeight + Constants.dominoWidth));
                playedDomino.offsetHorizontal = historyDomino.offsetHorizontal;
            }
            verticalPositions.Add(OriginalPosition(playedDomino));
            verticalRotations.Add(playedDomino.transform.rotation);
        }
        else
        {
            throw new ArgumentException("No valid historyDomino", "historyDomino");
        }

        for (int i = 0; i < horizontalDominoes.Count; i++)
        {
            horizontalPositions[i] = OriginalPosition(horizontalDominoes[i]);
        }
        for (int i = 0; i < verticalDominoes.Count; i++)
        {
            verticalPositions[i] = OriginalPosition(verticalDominoes[i]);
        }

        findBoundaryPosition();

        //Debug.Log("leftmost: " + leftMost.x);
        //Debug.Log("rightmost " + rightMost.x);


        for (int i = 0; i < horizontalDominoes.Count; i++)
        {
            SetPlayedDominoPosition(horizontalDominoes[i], horizontalPositions[i], horizontalRotations[i]);
            if (leftMost != Vector3.zero && horizontalPositions[i].x < leftMost.x)
            {
                SetRotateDomino(horizontalDominoes[i], new Vector3(leftMost.x - 0.5f * dominoScale * Constants.dominoWidth, leftMost.y));
            }
            if (rightMost != Vector3.zero && horizontalPositions[i].x > rightMost.x)
            {
                SetRotateDomino(horizontalDominoes[i], new Vector3(rightMost.x + 0.5f * dominoScale * Constants.dominoWidth, rightMost.y));
            }
        }
        float camSize = mainCamera.orthographicSize;

        if (horizontalDominoes[0].transform.position.y > camSize - 2 ||
            horizontalDominoes[horizontalDominoes.Count - 1].transform.position.y < -camSize + 2)
        {
            mainCamera.orthographicSize += 1f;
        }
        for (int i = 0; i < verticalDominoes.Count; i++)
        {
            SetPlayedDominoPosition(verticalDominoes[i], verticalPositions[i], verticalRotations[i]);
            if (upMost != Vector3.zero && verticalPositions[i].y > upMost.y)
            {
                SetRotateDomino(verticalDominoes[i], new Vector3(upMost.x, upMost.y + 0.5f * dominoScale * Constants.dominoWidth));
            }
            if (downMost != Vector3.zero && verticalPositions[i].y < downMost.y)
            {
                SetRotateDomino(verticalDominoes[i], new Vector3(downMost.x, downMost.y - 0.5f * dominoScale * Constants.dominoWidth));
            }
        }

        resetBoundaryPosition();
    }