Пример #1
0
//-----------------------------------------------------------------------------------------
    public bool CheckIfLegalHole(pinPair[] pary, pinPair TargetedPair)
    {
        bool legality = false;
        int  xCoor    = TargetedPair.x;
        int  yCoor    = TargetedPair.y;

        int[,] buffor = new int[, ] {
            { 1, 1 }, { -1, -1 }, { 1, -1 }, { -1, 1 }, { 0, 2 }, { 0, -2 }
        };
        if (this.pin == null)                  //czy otwór dla którego wywołuję jest pusty?
        {
            for (int i = 0; i <= 5; i++)       //robię jeden wektor, sprawdzam czy jakaś para się zgadza, robię kolejny wektor, cztery razy
            {
                foreach (pinPair pair in pary) //10 razy

                {
                    if (pair.x == (xCoor + buffor [i, 0]) && pair.y == yCoor + buffor [i, 1] && pair.pin != null)                     //sprawdzam pozycję dowolnego otworu i czy jest zajęty, jak tak to idę dalej
                    {
                        foreach (pinPair pair_ in pary)
                        {
                            if (pair_.x == xCoor + 2 * buffor [i, 0] && pair_.y == yCoor + 2 * buffor [i, 1] && pair_ == this)                             //sprawdzam czy po przekątnej jest wybrany otwór
                            {
                                legality = true;
                            }
                        }
                    }
                }
            }
        }
        return(legality);
    }
Пример #2
0
 //-----------------------------------------------------------------------------------------
 public void MakeMove(pinPair targetPair, pinPair InBetween)
 {
     if (targetPair.pin == null)
     {
         targetPair.pin = this.pin;
         this.pin       = null;
     }
 }
Пример #3
0
 //-----------------------------------------------------------------------------------------
 private void LegalityCheckGlobalHoles(pinPair targetedPair)
 {
     foreach (pinPair para in pairs)
     {
         if (para.CheckIfLegalHole(pairs, targetedPair))
         {
             para.hole.gameObject.tag = "legal";
         }
     }
 }
Пример #4
0
    //-----------------------------------------------------------------------------------------

    void Start()
    {
        //SET UP, deklaracja par--------------------------------------------------
        pairs = new pinPair[M1.Length];
        czas  = new timer(timedisplay, EndPanel, reason);
        Debug.Log("M1 length" + M1.Length);
        for (int i = 0; i <= M1.Length - 1; i++)
        {
            pairs [i] = new pinPair(M1 [i], pionki [i], (int)M1 [i].transform.position.x, (int)M1 [i].transform.position.z);
        }
        pairs[0].pin.SetActive(false);
        pairs[0].CancelPin();
        pionki [0] = null;
        GameOn     = true;
        //koniec deklaracji par------------------------------------------

        LegalityCheckGlobalPins();
    }
Пример #5
0
    //-----------------------------------------------------------------------------------------
    private void UpdateMouse()
    {
        RaycastHit hit;

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 25.0f))
        {
            mouseOver.x = (int)hit.point.x;
            mouseOver.y = (int)hit.point.z;

            if (pinSaved && hit.collider.tag == "legal" && pair_temp1.pin.transform.position == station.transform.position)
            {
                otwor_temp     = hit.collider.gameObject;
                otwor_temp.tag = "Illegal";
                foreach (pinPair temp in pairs)
                {
                    if (temp.hole == hit.collider.gameObject && temp.pin == null)
                    {
                        holeSaved      = true;
                        pair_temp2     = temp;                    //przypisuje parę z otworu
                        startOperation = true;
                    }
                }
            }

            if (!pinSaved && hit.collider.tag == "legal")
            {
                SetAllPinsIllegal(pairs);
                pionek_temp     = hit.collider.gameObject;
                pionek_temp.tag = "Illegal";
                foreach (pinPair temp in pairs)
                {
                    if (temp.x == mouseOver.x && temp.y == mouseOver.y)
                    {
                        pinSaved   = true;
                        pair_temp1 = temp;                        //przypisuje parę z pinu
                    }
                }
                LegalityCheckGlobalHoles(pair_temp1);
            }
        }
    }
Пример #6
0
    //-----------------------------------------------------------------------------------------
    public void MovementOperation(pinPair In, pinPair Out)
    {
        int x_new = Out.x - In.x;
        int y_new = Out.y - In.y;

        x_new = In.x + x_new / 2;
        y_new = In.y + y_new / 2;

        foreach (pinPair search in pairs)
        {
            if (search.x == x_new && search.y == y_new)
            {
                Debug.Log("movement operation finished");
                search.pin.SetActive(false);
                search.CancelPin();
                Out.AssignPin(In.pin);
                In.CancelPin();
                pinSaved   = false;
                holeSaved  = false;
                pair_temp1 = null;
                pair_temp2 = null;
            }
        }
    }