Ejemplo n.º 1
0
    private void GenerateAnnexRoom(Vector2Int annexRoomPosition)
    {
        CastleRoom actualMainPathRoom = rooms[actualMainRoomPosition.x, actualMainRoomPosition.y];
        CastleRoom annexRoom          = rooms[annexRoomPosition.x, annexRoomPosition.y];
        Vector2Int exitLocation       = actualMainRoomPosition - annexRoomPosition;

        //mets une clef dans la pièce annexe qui ouvre la porte qui empeche de continuer le chemin principale
        if (Constants.RANDOM.Next(blockMainPath + 2) == 0)//plus on l'a bloqué moins il y a de chance de le bloquer
        {
            //relie la piece annex au chemin principale
            annexRoom.CreateHoleExit(exitLocation);
            actualMainPathRoom.CreateHoleExit(exitLocation * -1);
            annexRoom.keys.Add(-1);//le clef qui ouvrent le chemin principale ont toutes l'ID -1
            blockMainPath++;
        }
        //ferme à clef la pièce annexe et met la clef dans une liste de clef à poser pendant la génération et pose un coffre
        else if (keyRemaining >= 0)
        {
            Vector2Int lockedDoorLocation = actualMainRoomPosition - annexRoomPosition;
            annexRoom.CreateLockedDoor(keyRemaining, lockedDoorLocation);
            keysToInstall.Add(keyRemaining);
            keyRemaining--;
            annexRoom.chest = true;
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// A 1/3 chance de générer une pièce annexe au chemin principale dans une direction aléatoire.
    /// Si la pièce est déjà générée, on crée une porte à sens unique pour la rejoindre.
    /// </summary>
    /// <returns>
    /// true si une piece annexe ou une porte a sens unique a été crée, sinon false.
    /// </returns>

    private bool GenerateAnnexPath(int castleWidth, int castleHeight)
    {
        if (Constants.RANDOM.Next(3) == 0)
        {
            Vector2Int[] possibleDirections = new Vector2Int[] { Vector2Int.left, Vector2Int.up, Vector2Int.right, Vector2Int.down };
            Vector2Int   choosenDirection   = HomeMadeFunctions.GetRandom(possibleDirections);
            Vector2Int   annexPathPosition  = choosenDirection + actualMainRoomPosition;
            Debug.Log("position de la piece annexe: " + annexPathPosition + " " + actualMainRoomPosition);
            if (!IsInBounds(annexPathPosition, castleWidth, castleHeight) || annexPathPosition == oldRoomPosition)
            //si la piece annexe est en dehors des limites du chateau ou qu'elle retourne sur les pas de la génération du chemin principale
            {
                return(false);
            }
            CastleRoom AnnexRoom = rooms[annexPathPosition.x, annexPathPosition.y];

            if (AnnexRoom.isGenerated)
            {
                Debug.Log("porte sens unique créé en position:" + actualMainRoomPosition);
                rooms[actualMainRoomPosition.x, actualMainRoomPosition.y].CreateOneWayDoor(true, choosenDirection);
                //Castle[annexPathPosition.x, annexPathPosition.y].CreateOneWayDoor(false, choosenDirection);
            }
            else
            {
                GenerateAnnexRoom(annexPathPosition);
                AnnexRoom.Generate(keysToInstall);
                Debug.Log("piece annexe crée: " + annexPathPosition);
            }
            return(true);
        }
        return(false);
    }
Ejemplo n.º 3
0
    private int blockMainPath = 0;//la valeur de cette variable est inversement proportionnelle aux chances de bloquer le chemin principale

    public Castle(int castleWidth, int castleHeight, int annexLockedDoorNbr)
    {
        keyRemaining = annexLockedDoorNbr;
        //initialisation des directions de generations possibles
        allowedGenerationDirection.Add(Vector2Int.left);
        allowedGenerationDirection.Add(Vector2Int.up);
        allowedGenerationDirection.Add(Vector2Int.right);
        allowedGenerationDirection.Add(Vector2Int.down);

        rooms = new CastleRoom[castleWidth, castleHeight];
        //remplis le chateau de pieces
        for (int x = 0; x < castleWidth; x++)
        {
            for (int y = 0; y < castleHeight; y++)
            {
                rooms[x, y] = new CastleRoom();
            }
        }

        actualMainRoomPosition = new Vector2Int(castleWidth / 2, 0);//commencer la generation au "milieu" du chateau
        rooms[actualMainRoomPosition.x, actualMainRoomPosition.y].Generate(keysToInstall);
        while (GenerateMainPath(castleWidth, castleHeight))
        {
            GenerateAnnexPath(castleWidth, castleHeight);
        }
    }
Ejemplo n.º 4
0
        public void DecoratedRoomTest()
        {
            IRoom room = new CastleRoom();

            room = new OrnateRoom(room);
            room = new FloodedRoom(room);
            room.CreateRoom();
        }
Ejemplo n.º 5
0
    // Start is called before the first frame update
    void Start()
    {
        Castle castle = new Castle(CASTLE_WIDTH, CASTLE_HEIGHT, 5);

        Debug.Log("---CastleTileGeneration---");
        for (int y = 0; y < CASTLE_HEIGHT; y++)
        {
            for (int x = 0; x < CASTLE_WIDTH; x++)
            {
                #region exitCreation
                Vector3    exitPosition;
                GameObject roomGameObject  = Instantiate(roomPrefab, new Vector3(x * 6, y * 6), Quaternion.identity);
                string[]   directionsNames = new string[4] {
                    "Up", "Right", "Down", "Left"
                };
                Debug.Log("création de la salle" + "(" + x + ";" + y + ")");
                CastleRoom room = castle.GetRoom(x, y);
                Debug.Log("ouvertures de la salle:" + room.ToString());


                for (int i = 0; i <= 3; i++)
                {
                    if (room.exits[i] != Constants.NO_EXIT)
                    {
                        exitPosition = roomGameObject.transform.Find(directionsNames[i]).transform.position;
                        Destroy(roomGameObject.transform.Find(directionsNames[i]).gameObject);
                        GameObject door = Instantiate(GetPrefab(room.exits[i]), exitPosition, Quaternion.identity, roomGameObject.transform);
                        if (room.exits[i] == Constants.LOCKED_DOOR)
                        {
                            LockedDoorScript doorScript = door.GetComponent <LockedDoorScript>();
                            doorScript.SetId(room.lockedDoorsIDs[i]);
                        }
                    }

                    if (room.isGenerated)//////debuuuuug
                    {
                        exitPosition = roomGameObject.transform.Find("middlePoint").transform.position;
                        Destroy(roomGameObject.transform.Find("middlePoint").gameObject);
                        Instantiate(debugPrefab, exitPosition, Quaternion.identity, roomGameObject.transform);
                    }
                    #endregion
                    #region keysCreation
                    if (room.keys.Count > 0)
                    {
                        Vector3 keyPosition = roomGameObject.transform.Find("keyLocation").transform.position;
                        Destroy(roomGameObject.transform.Find("keyLocation").gameObject);
                        Instantiate(keyPrefab, keyPosition, Quaternion.identity, roomGameObject.transform);
                        Debug.Log("clef posée en " + x + " " + y);
                    }
                    #endregion
                }
            }
        }
    }