Ejemplo n.º 1
0
    new void Start()
    {
        base.Start ();

        puzzleValues = new int[,] {{0,0,1,0,3},
                                    {0,2,2,2,3},
                                    {2,0,1,3,1},
                                    {2,3,3,1,1}};

        dominosaGrid = new DominosaGridPosition[4, 5];
        float width = 0.4f;
        float height = 0.4f;
        float originX = 1.08f;
        float originY = 0.8f;
        for (int i = 0; i < 4; i++) {
            originX = 1.08f;
            for(int j = 0; j < 5; j++){
                DominosaRect rect = new DominosaRect(originX,originY,width,height);
                dominosaGrid[i,j] = new DominosaGridPosition(rect);
                originX -= (width + 0.03f);
            }
            originY -= (height + 0.03f);
        }

        draggingLimits = new DominosaRect (1.485f, 1.215f, 2.97f, 2.43f);

        mouseDownFlag = false;
        dragging = false;
        draggedObject = null;

        movingObject = null;
        rotatingObject = null;
    }
Ejemplo n.º 2
0
 public DominosaGridPosition(DominosaRect rect)
 {
     this.rect = rect;
     used = false;
     placedValue = -1;
 }
Ejemplo n.º 3
0
    /*
    public override void EnablePuzzle(bool enable)
    {
        print ("ENABLE DOMINOSA: " + enable);
        this.enabled = enable;
        toolbox.currentPuzzle = this;
        //dominosaLimits.SendMessage("EnablePuzzle", enable);
    }
    */
    public void dominosaPieceFinishedMoving(GameObject piece)
    {
        DominosaRect pieceRect = new DominosaRect (piece);
        if (rotatingObject != null) {
            if(piece.GetInstanceID() == rotatingObject.GetInstanceID()){
                //Debug.Log("Old Rect: O - " + pieceRect.originX + "," + pieceRect.originY + " S - " + pieceRect.width + "," + pieceRect.height);
                pieceRect = new DominosaRect (piece ,true);
                //Debug.Log("New Rect: O - " + pieceRect.originX + "," + pieceRect.originY + " S - " + pieceRect.width + "," + pieceRect.height);

            }
        }
        Vector3 newPiecePosition;

        DominosaPieceScript pieceScript = piece.GetComponent<DominosaPieceScript>();

        resetDominosaGridPosition (piece);

        for (int i = 0; i < 4; i++) {
            bool shouldBreak = false;
            for(int j = 0; j < 5; j++){
                DominosaGridPosition gridPosition = dominosaGrid[i,j];
                bool overlapsOccurs = doRectsOverlap(pieceRect, gridPosition.rect);
                if(overlapsOccurs){
                    bool canPlaceIt = false;
                    if(gridPosition.used){
                        canPlaceIt = false;
                    }else{
                        if(pieceScript != null){
                            if(i == 3){
                                if(j == 4){
                                    canPlaceIt = false;
                                }else{
                                    if(pieceScript.horizontal){
                                        canPlaceIt = true;
                                    }else{
                                        canPlaceIt = false;
                                    }
                                }
                            }else{
                                if(j == 4){
                                    if(pieceScript.horizontal){
                                        canPlaceIt = false;
                                    }else{
                                        canPlaceIt = true;
                                    }
                                }else{
                                    if(pieceScript.horizontal){
                                        DominosaGridPosition nextPosition = dominosaGrid[i,j+1];
                                        if(nextPosition.used){
                                            canPlaceIt = false;
                                        }else{
                                            canPlaceIt = true;
                                        }
                                    }else{
                                        DominosaGridPosition nextPosition = dominosaGrid[i + 1,j];
                                        if(nextPosition.used){
                                            canPlaceIt = false;
                                        }else{
                                            canPlaceIt = true;
                                        }
                                    }
                                }
                            }
                        }else{
                            canPlaceIt = false;
                        }
                    }
                    if(canPlaceIt){
                        pieceScript.placedOnGrid = true;
                        pieceScript.arrayPosition = new DominosaArrayPosition(i,j);
                        newPiecePosition = new Vector3(gridPosition.rect.originX - pieceRect.width/2.0f,gridPosition.rect.originY - pieceRect.height/2.0f,piece.transform.localPosition.z);
                        if(useSmoothing){
                            beginSmoothMovementForObject(piece,newPiecePosition);
                        }else{
                            newPiecePosition.z = -0.3f;
                            piece.transform.localPosition = newPiecePosition;
                        }
                        gridPosition.used = true;
                        gridPosition.placedValue = pieceScript.value1;
                        dominosaGrid[i,j] = gridPosition;
                        if(pieceScript.horizontal){
                            DominosaGridPosition nextPosition = dominosaGrid[i,j+1];
                            nextPosition.used = true;
                            nextPosition.placedValue = pieceScript.value2;
                            dominosaGrid[i,j+1] = nextPosition;
                        }else{
                            DominosaGridPosition nextPosition = dominosaGrid[i+1,j];
                            nextPosition.used = true;
                            nextPosition.placedValue = pieceScript.value2;
                            dominosaGrid[i+1,j] = nextPosition;
                        }
                        shouldBreak = true;
                        break;
                    }
                }
            }
            if(shouldBreak){
                break;
            }
        }
        if (checkPuzzleSolution ()) {
            this.solvePuzzle();
            //changePiecesColor();
            Debug.Log("Puzzle solved!!");
        }
    }
Ejemplo n.º 4
0
    bool doRectsOverlap(DominosaRect rect1, DominosaRect rect2)
    {
        bool overlapsX1 = (rect1.originX <= rect2.originX && rect1.originX >= (rect2.originX - rect2.width));
        bool overlapsX2 = (rect2.originX <= rect1.originX && rect2.originX >= (rect1.originX - rect1.width));

        bool overlapsX = overlapsX1 || overlapsX2;

        bool overlapsY1 = (rect1.originY <= rect2.originY && rect1.originY >= (rect2.originY - rect2.height));
        bool overlapsY2 = (rect2.originY <= rect1.originY && rect2.originY >= (rect1.originY - rect1.height));

        bool overlapsY = overlapsY1 || overlapsY2;

        return overlapsX && overlapsY;
    }
Ejemplo n.º 5
0
    public override void autoSolvePuzzle()
    {
        if (!this.isFinished) {
            base.autoSolvePuzzle ();

            GameObject[] dominosaPieces = GameObject.FindGameObjectsWithTag("DominosaPiece");

            int count = 0;
            int i = 0;
            int j = 0;
            foreach(GameObject piece in dominosaPieces){
                /*
                DominosaPieceScript pieceScript = piece.GetComponent<DominosaPieceScript>();
                pieceScript.horizontal = false;
                pieceScript.placedOnGrid = true;
                 */

                piece.transform.eulerAngles = Vector3.zero;
                j = count % 5;
                if(count < 5){
                    i = 0;
                }else{
                    i = 2;
                }
                DominosaRect pieceRect = new DominosaRect(piece);
                DominosaGridPosition gridPosition = dominosaGrid[i,j];
                Vector3 newPiecePosition = new Vector3(gridPosition.rect.originX - pieceRect.width/2.0f,gridPosition.rect.originY - pieceRect.height/2.0f,piece.transform.localPosition.z);

                piece.transform.localPosition = newPiecePosition;
                count++;
            }
            //changePiecesColor();
        }
    }