Esempio n. 1
0
 protected void btnAdd_Click(Object Sender, EventArgs e)
 {
     if (Request.Form[hdnId.UniqueID] == "0")
     {
         oFloor.Add(txtName.Text, (chkEnabled.Checked ? 1 : 0));
     }
     else
     {
         oFloor.Update(Int32.Parse(Request.Form[hdnId.UniqueID]), txtName.Text, (chkEnabled.Checked ? 1 : 0));
     }
     if (Request.Form[hdnOrder.UniqueID] != "")
     {
         string strOrder = Request.Form[hdnOrder.UniqueID];
         int    intCount = 0;
         while (strOrder != "")
         {
             intCount++;
             int intId = Int32.Parse(strOrder.Substring(0, strOrder.IndexOf("&")));
             strOrder = strOrder.Substring(strOrder.IndexOf("&") + 1);
             oFloor.UpdateOrder(intId, intCount);
         }
     }
     Response.Redirect(Request.Path);
 }
Esempio n. 2
0
    public Floor generateFloor(Style s)
    {
        Floor f = new Floor();


        f.Add(new Room(s, Vector2.zero));


        //
        int winPathCount = UnityEngine.Random.Range(6, 12);

        Vector2   cursorPosition = Vector2.zero;
        Direction directionProd  = 0;

        //generate the ideal path
        for (int winPath = 1; winPath < winPathCount; winPath++)
        {
            //set direction test
            directionProd = (Direction)UnityEngine.Random.Range(0, 4);


            bool acceptable = false;
            while (!acceptable)
            {
                iterateDirection(ref directionProd);

                //edge case: stuck in a corner
                if (f.checkDoorNum(cursorPosition) == 4)
                {
                    f[winPath].isDestination = true;
                    hasFinished = true;
                    winPath     = winPathCount;
                    acceptable  = true;
                    //don't add a room if you're stuck
                    break;
                }

                //if(there's nothing where the directionProd is)
                if (!f.checkDirections(cursorPosition)[(int)directionProd])
                {
                    acceptable = true;
                }

                //if we've passed, but it isn't the end of the line, just add
                if (acceptable)
                {
                    cursorPosition += directionToVector(directionProd);
                    f.Add(new Room(s, cursorPosition));

                    //bool[] debugDirs = f.checkDirections(cursorPosition);
                    //Debug.Log("lcoation:" + cursorPosition + " direction: " + directionProd + " sides: " + debugDirs[0] + " " + debugDirs[1] + " " + debugDirs[2] + " " + debugDirs[3]);
                }
            }

            if (UnityEngine.Random.Range(0f, 1f) > .8f && winPath > 0)
            {
                f[winPath].isDestination = true;
                hasFinished = true;
            }

            if (winPath == winPathCount - 1 && !hasFinished)
            {
                f[winPath].isDestination = true;
            }
        }


        //Add sister rooms

        /*
         * for (int i = 0; i < winPathCount * 2 / 3; i++)
         * {
         *  Direction prod = (Direction)UnityEngine.Random.Range(0, 4);
         *  int potentialSister = 0;
         *  while (f.checkDirections(potentialSister)[prod])
         *  {
         *      potentialSister = UnityEngine.Random.Range(0, f.Count);
         *  }
         * }*/


        //set door count and directions
        for (int i = 0; i < f.Count; i++)
        {
            f[i].doorCount = f.checkDoorNum(f[i].location);
            f.updateSiblings(i);
            switch (f[i].doorCount)
            {
            case 1:
                if (f[i].siblings[1])
                {
                    f[i].direction = Direction.SOUTH;
                }
                if (f[i].siblings[2])
                {
                    f[i].direction = Direction.EAST;
                }
                if (f[i].siblings[3])
                {
                    f[i].direction = Direction.WEST;
                }
                break;

            case 2:
                if (f[i].siblings[0] && f[i].siblings[1])
                {
                    f[i].direction = Direction.CROSS;
                }
                else if (f[i].siblings[2] && f[i].siblings[3])
                {
                    f[i].direction = Direction.HCROSS;
                }
                else if (f[i].siblings[0] && f[i].siblings[3])
                {
                    f[i].direction = Direction.NORTH;
                }
                else if (f[i].siblings[0] && f[i].siblings[2])
                {
                    f[i].direction = Direction.SOUTH;
                }
                else if (f[i].siblings[1] && f[i].siblings[2])
                {
                    f[i].direction = Direction.EAST;
                }
                else if (f[i].siblings[1] && f[i].siblings[3])
                {
                    f[i].direction = Direction.WEST;
                }

                else
                {
                    Debug.Log("error");
                }

                break;

            case 3:
                if (!f[i].siblings[1])
                {
                    f[i].direction = Direction.SOUTH;
                }
                if (!f[i].siblings[2])
                {
                    f[i].direction = Direction.EAST;
                }
                if (!f[i].siblings[3])
                {
                    f[i].direction = Direction.WEST;
                }
                break;
            }
        }

        //instantiate path
        foreach (Room r in f)
        {
            GameObject m;
            //TODO: randomize loads
            string stylename = Enum.GetName(typeof(Style), r.style);
            if (r.direction != Direction.CROSS && r.direction != Direction.HCROSS)
            {
                m = Instantiate(Resources.Load <GameObject>(stylename + "/room" + r.doorCount + "-" + (int)UnityEngine.Random.Range(1, 3)));
            }
            else
            {
                m = Instantiate(Resources.Load <GameObject>(stylename + "/room5-" + (int)UnityEngine.Random.Range(1, 3)));
            }
            m.transform.position = new Vector3(r.location.x * -6.4f * 2, -10, r.location.y * -6.4f * 2);
            m.name = r.location.x + " " + r.location.y;

            //Add grabbable components
            for (int i = 0; i < m.transform.childCount; i++)
            {
                GameObject g = m.transform.GetChild(i).gameObject;
                g.AddComponent <VRTK.VRTK_InteractableObject>().isGrabbable = true;
                VRTK.GrabAttachMechanics.VRTK_FixedJointGrabAttach c = g.AddComponent <VRTK.GrabAttachMechanics.VRTK_FixedJointGrabAttach>();
                c.precisionGrab   = true;
                c.throwMultiplier = 5;
                g.AddComponent <BoxCollider>();
                g.layer = LayerMask.NameToLayer("Throwables");
            }

            //set room directions
            switch (r.direction)
            {
            case Direction.NORTH:
                break;

            case Direction.SOUTH:
                switch (r.doorCount)
                {
                case 1:
                    m.transform.rotation = Quaternion.Euler(-90, 180, 0);
                    break;

                case 2:
                    m.transform.rotation = Quaternion.Euler(-90, 90, 0);
                    break;

                case 3:
                    m.transform.rotation = Quaternion.Euler(-90, 180, 0);
                    break;
                }
                break;

            case Direction.EAST:
                switch (r.doorCount)
                {
                case 1:
                    m.transform.rotation = Quaternion.Euler(-90, 90, 0);
                    break;

                case 2:
                    m.transform.rotation = Quaternion.Euler(-90, 180, 0);
                    break;

                case 3:
                    m.transform.rotation = Quaternion.Euler(-90, 90, 0);
                    break;
                }
                break;

            case Direction.WEST:
                switch (r.doorCount)
                {
                case 1:
                    m.transform.rotation = Quaternion.Euler(-90, -90, 0);
                    break;

                case 2:
                    m.transform.rotation = Quaternion.Euler(-90, -90, 0);
                    break;

                case 3:
                    m.transform.rotation = Quaternion.Euler(-90, -90, 0);
                    break;
                }
                break;

            case Direction.CROSS:
                break;

            case Direction.HCROSS:
                m.transform.rotation = Quaternion.Euler(-90, 90, 0);
                break;
            }

            m.transform.parent = levelHolder.transform;

            if (!r.isDestination)
            {
                try
                {
                    if (r.location != Vector2.zero)
                    {
                        m.transform.Find("TV").gameObject.SetActive(false);
                        m.transform.Find("SecretBook").gameObject.SetActive(false);
                    }
                }
                catch (Exception e) { }
            }
            else
            {
                try {
                    m.transform.Find("TV").gameObject.AddComponent <TV>();
                    m.transform.Find("TV").gameObject.AddComponent <BoxCollider>();
                }
                catch (Exception e) { }
            }
        }

        //next floor style
        //s = (Style)((int)s + 1);
        return(f);
    }