Exemplo n.º 1
0
    /// <summary>
    /// 合成
    /// </summary>
    /// <param name="C1">クリスタル</param>
    /// <param name="C2">クリスタル</param>
    public void compound(GameObject C1, GameObject C2)
    {
        //setUnChooseAll ();
        Circel C1Circel = C1.GetComponent <Circel> ();

        //Levelにより、クリスタルの数が変わる
        C1.transform.GetChild(C1Circel.circelLevel).gameObject.SetActive(false);
        C1Circel.circelLevel += C2.GetComponent <Circel> ().circelLevel;
        C1.transform.GetChild(C1Circel.circelLevel).gameObject.SetActive(true);
        //光る
        C1.transform.GetChild(0).gameObject.SetActive(true);
        //setCircelState (C1, STATE.CHOOSED);
        nowChoosedLevel = C1Circel.circelLevel;
        //魔法のボタンを隠す
        HideButtonUI();
        ShowButtonUI();
        //合成されたクリスタルを隠す
        if (C2.GetComponent <Circel> ().circelLevel > 1)
        {
            C2.transform.GetChild(C2.GetComponent <Circel> ().circelLevel).gameObject.SetActive(false);
            C2.GetComponent <Circel> ().circelLevel = 1;
            C2.transform.GetChild(C2.GetComponent <Circel> ().circelLevel).gameObject.SetActive(true);
            int childNum = C2.transform.childCount;
            for (int j = 7; j < childNum; j++)
            {
                crystals.Remove(C2.transform.GetChild(7).gameObject);
                Destroy(C2.transform.GetChild(7).gameObject);
            }
        }
        crystals.Remove(C2.gameObject);
        Destroy(C2.gameObject);
        //setCircelState (C2, STATE.COMPOUNDED);
        C2.SetActive(false);
    }
Exemplo n.º 2
0
        public static int Solution(int[] A)
        {
            if (A == null)
            {
                return(0);
            }
            if (A.Length < 2)
            {
                return(0);
            }
            Circel[] circels = new Circel[A.Length];
            for (int i = 0; i < A.Length; i++)
            {
                circels[i] = new Circel(i - A[i], i + A[i]);
            }
            circels = circels.OrderBy(c => c.first).ToArray();
            int [] openings = new int[circels.Length];
            for (int i = 0; i < circels.Length; i++)
            {
                Circel circel = circels[i];
                openings[i] = circel.first;
            }
            int maxOpenning = openings[openings.Length - 1];
            int count       = 0;

            for (int i = 0; i < circels.Length; i++)
            {
                Circel circel         = circels[i];
                int    indexOfOpening = Array.BinarySearch(openings, (int)circel.last + 1);
                if (indexOfOpening < 0)
                {
                    for (int j = (int)circel.last + 2; j <= maxOpenning; j++)
                    {
                        indexOfOpening = Array.BinarySearch(openings, j);
                        if (indexOfOpening > 0)
                        {
                            break;
                        }
                    }
                }
                if (indexOfOpening < 0)
                {
                    count += circels.Length - (i + 1);
                }
                else
                {
                    count += indexOfOpening - (i + 1);
                }
            }
            return(count);
        }
        public static int Solution(int[] A)
        {
            if (A == null)
                return 0;
            if (A.Length < 2)
                return 0;
            Circel[] circels = new Circel[A.Length];
            for (int i = 0; i < A.Length; i++)
            {
                circels[i] = new Circel(i-A[i],i+A[i]);
            }
            circels = circels.OrderBy(c => c.first).ToArray();
            int [] openings = new int[circels.Length];
            for (int i = 0; i < circels.Length; i++)
            {
                Circel circel = circels[i];
                openings[i] = circel.first;
            }
            int maxOpenning = openings[openings.Length - 1];
            int count = 0;
            for (int i = 0; i < circels.Length; i++)
            {
                Circel circel = circels[i];
                int indexOfOpening = Array.BinarySearch(openings,(int)circel.last+1 );
                if (indexOfOpening < 0)
                {
                    for (int j = (int)circel.last+2; j <= maxOpenning; j++)
                    {
                        indexOfOpening = Array.BinarySearch(openings,j);
                        if(indexOfOpening>0)
                        { break;}
                    }

                }
                if (indexOfOpening < 0)
                    count += circels.Length - (i+1);
                else
                    count += indexOfOpening- (i+1);
            }
            return count;
        }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            //床、クリスタル、ボタンをタッチできる
            int        layerMask = (1 << 10) | (1 << 5) | (1 << 8);
            Ray        ray       = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit       = new RaycastHit();
            if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
            {
                GameObject obj = hit.collider.gameObject;
                pos = hit.point;
                switch (obj.layer)
                {
                //クリスタル
                case 8:
                    Circel circle = obj.transform.parent.gameObject.GetComponent <Circel> ();
                    if (circle.c_State == Circel.STATE.CHOOSED && circle.circelLevel < 5)
                    {
                        tempCircel = circelControl.crystalGenerat(hit.point);
                        if (tempCircel != null)
                        {
                            circelControl.compound(obj.transform.parent.gameObject, tempCircel);
                        }
                    }

                    break;

                //床
                case 10:
                    circelControl.CheckExist();
                    tempCircel = circelControl.crystalGenerat(hit.point);
                    break;

                //ボタン
                case 5:
                    //isButton = true;
                    break;
                }
            }
        }

        if (Input.GetMouseButton(0))
        {
            //床しか反応がない
            int        layerMask = (1 << 10);
            Ray        ray       = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit       = new RaycastHit();
            if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
            {
                if (tempCircel != null)                  /*
                                                          * tempCircel.GetComponent<Circel> ().isMove = true;
                                                          * pos = hit.point - pos;
                                                          * pos.y = tempCircel.transform.position.y;
                                                          * tempCircel.transform.position += pos;
                                                          * pos = hit.point;*/
                {
                    tempCircel.transform.position = hit.point;
                }

                /*else{
                 *      if(!isButton){
                 *              //選択範囲の計算
                 *              float dis = Vector3.Distance (pos, hit.point)/2;
                 *              float x = hit.point.x - pos.x;
                 *              float z = hit.point.z - pos.z;
                 *              float angle = Mathf.Atan2 (z, x) * Mathf.Rad2Deg;
                 *              Vector3 selectPos = new Vector3 (pos.x + (Mathf.Cos (Mathf.Deg2Rad * angle) * dis), 0, pos.z + (Mathf.Sin (Mathf.Deg2Rad * angle) * dis));
                 *              if (range == null) {
                 *                      range = Instantiate (rangeObject, selectPos, Quaternion.identity) as GameObject;
                 *              }
                 *              range.transform.localScale = new Vector3 (x, 1, z);
                 *              range.transform.position = selectPos;
                 *
                 *      }
                 * }*/
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            if (tempCircel != null)
            {
                tempCircel.GetComponent <Circel>().isMove = false;
            }
            tempCircel = null;
            //isButton = false;

            /*if (range != null) {
             *      range.GetComponent<CircleSelect> ().SetChooseInRange ();
             *      range = null;
             * }*/
        }
    }