コード例 #1
0
ファイル: BlackControl.cs プロジェクト: Ryneqq/PureCheckers
 public void Clicked()
 {
     Variables.Checker = "Black";
     if (Variables.Moved)
     {
         move = GetComponent <RectTransform> ();            // zapisanie RectTransforma do zmiennej move
         //przeliczanie pozycji pionka
         positionX  = GetComponent <RectTransform> ().anchoredPosition.x;
         positionY  = GetComponent <RectTransform> ().anchoredPosition.y;
         MyPosition = Variables.ReturnIndex(positionX, positionY);
         //odnalezienie obiektu kreujacego guziki, ktore pozwalaja na ruch pionka
         CB = GameObject.Find("Main Camera").GetComponent <CreateButton> ();
         // tworzenie guzikow, przesylam do funkcji initialize referencje zmiennej move
         CB.Initialize(MyPosition, ref move);
         Variables.Moved       = false;
         Variables.LastClicked = MyPosition;
     }
     else             //jezeli nie chemy ruszyc tym pionkiem wystarczy ze nacisniemy inny pionek i guziki zostana usuniete
     {
         GameObject[] ActiveList = GameObject.FindGameObjectsWithTag("Active");
         foreach (GameObject Act in ActiveList)
         {
             Destroy(Act.gameObject);
         }
         Variables.Moved = true;
         positionX       = GetComponent <RectTransform>().anchoredPosition.x;
         positionY       = GetComponent <RectTransform>().anchoredPosition.y;
         MyPosition      = Variables.ReturnIndex(positionX, positionY);
         if (Variables.LastClicked.x != MyPosition.x || Variables.LastClicked.y != MyPosition.y)
         {
             Clicked();
         }
     }
 }
コード例 #2
0
ファイル: ButtonControl.cs プロジェクト: Ryneqq/PureCheckers
    public void Clicked()
    {
        Variables.Moved = true;         // dokonalismy wyboru ruchu
        Destroy(this.gameObject);       // niszczymy nacisnietego active buttona
        CB         = GameObject.Find("Main Camera").GetComponent <CreateButton>();
        StartIndex = CB.StartingPostion;
        positionX  = GetComponent <RectTransform>().anchoredPosition.x;
        positionY  = GetComponent <RectTransform>().anchoredPosition.y;
        CB.MoveYourAss.anchoredPosition = new Vector2(positionX, positionY);
        BoardPresence = Variables.ReturnIndex(positionX, positionY);

        if (Variables.Board [StartIndex.y, StartIndex.x] == 311 || Variables.Board [StartIndex.y, StartIndex.x] == 312)
        {
            KingJumpin = true;
        }         // Jezeli król bil
        if (Variables.Board [StartIndex.y, StartIndex.x] == 31 || Variables.Board [StartIndex.y, StartIndex.x] == 32)
        {
            NormalJumpin = true;
        }         // Normalny pionek bił

        // wyszukuje wszystkie zaznaczone pionki i zmieniam je na podstawowe
        for (int i = 0; i < 8; i++)
        {
            for (int j = 0; j < 8; j++)
            {
                if (Variables.Board [i, j] == 31)
                {
                    Variables.Board [i, j] = 1;
                }
                if (Variables.Board [i, j] == 32)
                {
                    Variables.Board [i, j] = 2;
                }
                if (Variables.Board [i, j] == 311)
                {
                    Variables.Board [i, j] = 11;
                }
                if (Variables.Board [i, j] == 312)
                {
                    Variables.Board [i, j] = 12;
                }
            }
        }
        WhichOne = Variables.Board [StartIndex.y, StartIndex.x];
        Variables.Board [StartIndex.y, StartIndex.x]       = 0;
        Variables.Board [BoardPresence.y, BoardPresence.x] = WhichOne;

        if (Variables.Checker == "King" && KingJumpin)           // Jezeli skoczyl to zbij pionki
        {
            if (Variables.Turn == "White")
            {
                Variables.Board [BoardPresence.y, BoardPresence.x] = 311;
                Variables.MarkedForDeath(StartIndex, BoardPresence);
                GameObject[] CheckerList = GameObject.FindGameObjectsWithTag("ButtonTag");                  // w taki sposob się dostaje do obiektów
                foreach (GameObject Checker in CheckerList)
                {
                    positionX  = Checker.GetComponent <RectTransform> ().anchoredPosition.x;
                    positionY  = Checker.GetComponent <RectTransform> ().anchoredPosition.y;
                    CheckIndex = Variables.ReturnIndex(positionX, positionY);
                    if (Variables.Board [CheckIndex.y, CheckIndex.x] == 62)
                    {
                        Variables.Board [CheckIndex.y, CheckIndex.x] = 0;
                        //Destroy (Checker.gameObject);
                        Checker.gameObject.tag = "dead";
                        Checker.GetComponent <Button>().enabled = false;
                        Checker.GetComponent <RectTransform>().anchoredPosition = new Vector2(Variables.graveyardX[Variables.graveyardK], Variables.graveyardY[Variables.graveyardJ]);
                        Variables.graveyardJ++;
                        if (Variables.graveyardJ > 5)
                        {
                            Variables.graveyardJ = 0;
                            Variables.graveyardK++;
                        }
                        Variables.Player1--;
                    }
                }
            }
            else if (Variables.Turn == "Black")
            {
                Variables.Board [BoardPresence.y, BoardPresence.x] = 312;
                Variables.MarkedForDeath(StartIndex, BoardPresence);
                GameObject[] CheckerList = GameObject.FindGameObjectsWithTag("ButtonTag");                  // w taki sposob się dostaje do obiektów
                foreach (GameObject Checker in CheckerList)
                {
                    positionX  = Checker.GetComponent <RectTransform> ().anchoredPosition.x;
                    positionY  = Checker.GetComponent <RectTransform> ().anchoredPosition.y;
                    CheckIndex = Variables.ReturnIndex(positionX, positionY);
                    if (Variables.Board [CheckIndex.y, CheckIndex.x] == 61)
                    {
                        Variables.Board [CheckIndex.y, CheckIndex.x] = 0;
                        //Destroy (Checker.gameObject);
                        Checker.gameObject.tag = "dead";
                        Checker.GetComponent <Button>().enabled = false;
                        Checker.GetComponent <RectTransform>().anchoredPosition = new Vector2(Variables.graveyardX[Variables.graveyardKBl], Variables.graveyardY[Variables.graveyardJBl]);
                        Variables.graveyardJBl--;
                        if (Variables.graveyardJBl < 1)
                        {
                            Variables.graveyardJBl = 6;
                            Variables.graveyardKBl--;
                        }
                        Variables.Player2--;
                    }
                }
            }
            // Wyrzuć guziki które są już nie potrzebne
            GameObject[] ActiveList = GameObject.FindGameObjectsWithTag("Active");
            foreach (GameObject Act in ActiveList)
            {
                Destroy(Act.gameObject);
            }

            ContinueBeating();

            if (KingJumpin)               // Jezeli istnieje nastepne bicie to wylacz wszystkie mozliwe guziki
            {
                Variables.Destroyed = true;
                GameObject[] CheckerList = GameObject.FindGameObjectsWithTag("ButtonTag");                  // w taki sposob się dostaje do obiektów
                Button       temp;
                foreach (GameObject Checker in CheckerList)
                {
                    temp         = Checker.GetComponent <Button> ();
                    temp.enabled = false;
                }
                CB.Initialize(BoardPresence, ref CB.MoveYourAss);
            }
            else                                                                           // Jezeli nie to włacz guziki, zmien ture
            {
                GameObject[] CheckerList = GameObject.FindGameObjectsWithTag("ButtonTag"); // w taki sposob się dostaje do obiektów
                Button       temp;
                foreach (GameObject Checker in CheckerList)
                {
                    temp         = Checker.GetComponent <Button> ();
                    temp.enabled = true;
                }
                if (Variables.Turn == "White")
                {
                    Variables.Board [BoardPresence.y, BoardPresence.x] = 11;
                }
                else if (Variables.Turn == "Black")
                {
                    Variables.Board [BoardPresence.y, BoardPresence.x] = 12;
                }
                ActiveList = GameObject.FindGameObjectsWithTag("Active");
                foreach (GameObject Act in ActiveList)
                {
                    Destroy(Act.gameObject);
                }
                Variables.TurnChange = true;                 //zmiana rundy
            }
        }
        else if ((Variables.Checker == "White" || Variables.Checker == "Black") && NormalJumpin == true)             // Jezeli pionek nie jest krolem
        {
            if (Variables.Checker == "White" && Variables.Turn == "White")
            {
                Variables.MarkedForDeath(StartIndex, BoardPresence);
                Variables.Board [BoardPresence.y, BoardPresence.x] = 31;
                GameObject[] CheckerList = GameObject.FindGameObjectsWithTag("ButtonTag");                  // w taki sposob się dostaje do obiektów
                foreach (GameObject Checker in CheckerList)
                {
                    positionX  = Checker.GetComponent <RectTransform> ().anchoredPosition.x;
                    positionY  = Checker.GetComponent <RectTransform> ().anchoredPosition.y;
                    CheckIndex = Variables.ReturnIndex(positionX, positionY);
                    if (Variables.Board [CheckIndex.y, CheckIndex.x] == 62)
                    {
                        Variables.Board [CheckIndex.y, CheckIndex.x] = 0;
                        //Destroy (Checker.gameObject);
                        Checker.gameObject.tag = "dead";
                        Checker.GetComponent <Button>().enabled = false;
                        Checker.GetComponent <RectTransform>().anchoredPosition = new Vector2(Variables.graveyardX[Variables.graveyardK], Variables.graveyardY[Variables.graveyardJ]);
                        Variables.graveyardJ++;
                        if (Variables.graveyardJ > 5)
                        {
                            Variables.graveyardJ = 0;
                            Variables.graveyardK++;
                        }
                        Variables.Player1--;
                    }
                }
            }
            if (Variables.Checker == "Black" && Variables.Turn == "Black")
            {
                Variables.MarkedForDeath(StartIndex, BoardPresence);
                Variables.Board [BoardPresence.y, BoardPresence.x] = 32;
                GameObject[] CheckerList = GameObject.FindGameObjectsWithTag("ButtonTag");                  // w taki sposob się dostaje do obiektów
                foreach (GameObject Checker in CheckerList)
                {
                    positionX  = Checker.GetComponent <RectTransform> ().anchoredPosition.x;
                    positionY  = Checker.GetComponent <RectTransform> ().anchoredPosition.y;
                    CheckIndex = Variables.ReturnIndex(positionX, positionY);
                    if (Variables.Board [CheckIndex.y, CheckIndex.x] == 61)
                    {
                        Variables.Board [CheckIndex.y, CheckIndex.x] = 0;
                        //Destroy (Checker.gameObject);
                        Checker.gameObject.tag = "dead";
                        Checker.GetComponent <Button>().enabled = false;
                        Checker.GetComponent <RectTransform>().anchoredPosition = new Vector2(Variables.graveyardX[Variables.graveyardKBl], Variables.graveyardY[Variables.graveyardJBl]);
                        Variables.graveyardJBl--;
                        if (Variables.graveyardJBl < 1)
                        {
                            Variables.graveyardJBl = 6;
                            Variables.graveyardKBl--;
                        }
                        Variables.Player2--;
                    }
                }
            }

            GameObject[] ActiveList = GameObject.FindGameObjectsWithTag("Active");
            foreach (GameObject Act in ActiveList)
            {
                Destroy(Act.gameObject);
            }

            ContinueBeating();

            if (NormalJumpin)               // Jezeli istnieje nastepne bicie to wylacz wszystkie mozliwe guziki
            {
                Variables.Destroyed = true;
                GameObject[] CheckerList = GameObject.FindGameObjectsWithTag("ButtonTag");                  // w taki sposob się dostaje do obiektów
                Button       temp;
                foreach (GameObject Checker in CheckerList)
                {
                    temp         = Checker.GetComponent <Button> ();
                    temp.enabled = false;
                }
                CB.Initialize(BoardPresence, ref CB.MoveYourAss);
            }
            else
            {
                GameObject[] CheckerList = GameObject.FindGameObjectsWithTag("ButtonTag");                  // w taki sposob się dostaje do obiektów
                Button       temp;
                foreach (GameObject Checker in CheckerList)
                {
                    temp         = Checker.GetComponent <Button> ();
                    temp.enabled = true;
                }
                if (Variables.Turn == "White")
                {
                    Variables.Board [BoardPresence.y, BoardPresence.x] = 1;
                }
                else if (Variables.Turn == "Black")
                {
                    Variables.Board [BoardPresence.y, BoardPresence.x] = 2;
                }
                ActiveList = GameObject.FindGameObjectsWithTag("Active");
                foreach (GameObject Act in ActiveList)
                {
                    Destroy(Act.gameObject);
                }
                Variables.TurnChange = true;                 //zmiana rundy
            }
        }
        else             // jezeli nie występuje bicie
        {
            Variables.Destroyed  = false;
            Variables.TurnChange = true;             //zmiana rundy
        }
    }