public ActionResult Post([FromBody] mTree Tree)
 {
     try
     {
         if (!(Tree.Order < 1))
         {
             Storage.MoviesTree.Order        = Tree.Order;
             Storage.MoviesTree.MultiwayPeli = new Laboratorio1_ED2.MultiwayTree <mMovies>();
             Storage.MoviesTree.MultiwayPeli.SetM(Tree.Order);
             return(Ok("El orden del árbol es:" + Tree.Order));
         }
         else
         {
             return(Ok("El orden debe ser mayor a 1"));
         }
     }
     catch
     {
         return(BadRequest());
     }
 }
示例#2
0
    private int currentLevel;                               //The curent level the player is on

    //Destroys old dungeons and creates new dungeons with all gameobjects
    void createLevel(int _level)
    {
        //Get the current level the player is on
        currentLevel = _level;
        //Delete all game objects of the old dungeon
        destroyLevel();

        //Create a new dungeon layout tree
        levelTree = new mTree(_level);
        //Ensure the dungeon tree has at least 4 end rooms
        while (levelTree.getEndRoomCount() < 4)
        {
            levelTree = new mTree(_level);
        }
        //Create a boss room at one the end rooms
        levelTree.makeBossRoom();

        //Retrieve all the nodes from the dungeon layout tree
        List <Node> levelNodes = levelTree.getNodes();

        //Set the length of the roomHolder to the number of nodes in the tree
        roomHolder          = new Transform[levelNodes.Count];
        currentRoom         = 0;                 //The current room is the spawn room
        currentGridPosition = new Vector2(0, 0); //The current grid position is at the spawn room


        //For each node in the dungeon tree
        for (int i = 0; i < levelNodes.Count; i++)
        {
            Node currentNode = levelNodes[i];
            //Check position of doors for room
            bool[] doors = new bool[4] {
                false, false, false, false
            };                                                                //[0] Up [1] Down [2] Left [3] Right

            //Check for child node doors
            if (currentNode.getChildren() != null)
            {
                foreach (int _childIndex in currentNode.getChildren())
                {
                    if (checkDoor(0, 1, currentNode, levelNodes[_childIndex]))
                    {
                        doors[0] = true;
                    }
                    else if (checkDoor(0, -1, currentNode, levelNodes[_childIndex]))
                    {
                        doors[1] = true;
                    }
                    else if (checkDoor(-1, 0, currentNode, levelNodes[_childIndex]))
                    {
                        doors[2] = true;
                    }
                    else if (checkDoor(1, 0, currentNode, levelNodes[_childIndex]))
                    {
                        doors[3] = true;
                    }
                }
            }

            //Check for parent node door
            if (currentNode.getParent() != -1)
            {
                if (checkDoor(0, 1, currentNode, levelNodes[currentNode.getParent()]))
                {
                    doors[0] = true;
                }
                else if (checkDoor(0, -1, currentNode, levelNodes[currentNode.getParent()]))
                {
                    doors[1] = true;
                }
                else if (checkDoor(-1, 0, currentNode, levelNodes[currentNode.getParent()]))
                {
                    doors[2] = true;
                }
                else if (checkDoor(1, 0, currentNode, levelNodes[currentNode.getParent()]))
                {
                    doors[3] = true;
                }
            }

            int[,] roomLayout, roomEntities;

            roomLayout   = new int[0, 0];
            roomEntities = new int[0, 0];

            //Debug.Log (i+" TYPE: "+ currentNode.getRoomType()+" ID: "+currentNode.getRoomID());

            //Checks the room type of the node to select the appropriate room layout with entity placements
            if (currentNode.getRoomType() == 1)                //Boss Rooms
            {
                roomLayout   = GameManager.instance.roomData.getBossRoomLayout(currentNode.getRoomID() - GameManager.instance.numberOfRooms);
                roomEntities = GameManager.instance.roomData.getBossRoomEntities(currentNode.getRoomID() - GameManager.instance.numberOfRooms);
            }
            else if (currentNode.getRoomType() == 2)                  //Special Rooms
            {
                roomLayout   = GameManager.instance.roomData.getSpecialRoomLayout(currentNode.getRoomID());
                roomEntities = GameManager.instance.roomData.getSpecialRoomEntities(currentNode.getRoomID());
            }
            else                 //Normal Rooms
            {
                roomLayout   = GameManager.instance.roomData.getRoomLayout(currentNode.getRoomID());
                roomEntities = GameManager.instance.roomData.getRoomEntities(currentNode.getRoomID());
            }


            //Calculates a score for the player based on their average performance of the room ID selected
            float performanceScore = GameManager.instance.roomData.CurrentPlayer().getRoomAvergePerformance(currentNode.getRoomID());
            //Gets the current modifier of the selcted room ID
            int currentMod = GameManager.instance.roomData.CurrentPlayer().getRoomModifer(currentNode.getRoomID());

            //Code to modify the rooms based on player performance
            //------
            //If the room is not the spawn room
            if (currentNode.getRoomID() != 0)
            {
                //Check if the performance score is greater than 0 - Error detection from performance score calculation (see ln 129)
                if (performanceScore >= 0)
                {
                    //Add to the current modifier based on the players performance with the current modifier
                    currentMod += GameManager.instance.roomData.checkRoomModifier(currentNode.getRoomID(), performanceScore, currentMod);
                    //Set the current room ID's modifier to the changed modifier
                    GameManager.instance.roomData.CurrentPlayer().setRoomModifier(currentNode.getRoomID(), currentMod);
                }
            }
            //-----

            //Create a new transform object to hold all the gameobjects of that room
            roomHolder[i] = new GameObject("Room" + i).transform;
            //Create all gameobjects in the room
            createRoom(i, doors, roomLayout);
            //If the room is not the spawn room -- Spawn room is safe
            if (i != 0)
            {
                //Add enemy gameobjects to the current room with the current modifier to the room
                addEnemies(i, roomEntities, currentMod);
                //Deactivate the room in the unity hierarchy -- Spawn room is active at the start of the dungeon
                roomHolder [i].gameObject.SetActive(false);
            }
        }
    }