示例#1
0
    public void PrintMap(dungeon d)
    {
        string map = string.Empty;

        for (int r = 0; r <= d.n_rows; r++)
        {
            if (map.Length > 0)
            {
                map += "\n";
            }
            for (int c = 0; c <= d.n_cols; c++)
            {
                //if ((d.cell[r][c] & dungeon.PERIMETER) != dungeon.NOTHING)
                //    map += "0";
                if ((d.cell[r][c] & dungeon.DOORSPACE) != dungeon.NOTHING)
                {
                    map += "-";
                }
                else if ((d.cell[r][c] & dungeon.ROOM) != dungeon.NOTHING)
                {
                    map += "#";
                }
                else if ((d.cell[r][c] & dungeon.CORRIDOR) != dungeon.NOTHING)
                {
                    map += "#";
                }
                else
                {
                    map += " ";
                }
            }
        }
        Debug.Log(map);
    }
示例#2
0
    public void BuildMesh(dungeon d)
    {
        int NumTiles = (d.n_rows + 1) * (d.n_cols + 1);
        int NumTris  = NumTiles * 2;

        int SizeX    = d.n_cols + 1;
        int SizeY    = d.n_rows + 1;
        int VSizeX   = SizeX + 1;
        int VSizeY   = SizeY + 1;
        int NumVerts = VSizeX * VSizeY;

        Vector3[] Vertices = new Vector3[NumVerts];
        Vector3[] Normals  = new Vector3[NumVerts];
        Vector2[] UV       = new Vector2[NumVerts];

        int[] Triangles = new int[NumTris * 3];

        for (int y = 0; y < VSizeY; y++)
        {
            for (int x = 0; x < VSizeX; x++)
            {
                int SquareIndex = y * VSizeX + x;
                Vertices[SquareIndex] = new Vector3(x, y, 0);
                Normals[SquareIndex]  = Vector3.up;
                UV[SquareIndex]       = new Vector2(x * 1.0f / SizeX, y * 1.0f / SizeY);
            }
        }

        for (int y = 0; y < SizeY; y++)
        {
            for (int x = 0; x < SizeX; x++)
            {
                int SquareIndex = y * SizeX + x;
                int TriOffset   = SquareIndex * 6;

                Triangles[TriOffset + 0] = y * VSizeX + x + 0;
                Triangles[TriOffset + 1] = y * VSizeX + x + VSizeX + 0;
                Triangles[TriOffset + 2] = y * VSizeX + x + VSizeX + 1;

                Triangles[TriOffset + 3] = y * VSizeX + x + 0;
                Triangles[TriOffset + 4] = y * VSizeX + x + VSizeX + 1;
                Triangles[TriOffset + 5] = y * VSizeX + x + 1;
            }
        }

        Mesh Mesh = new Mesh();

        Mesh.vertices  = Vertices;
        Mesh.triangles = Triangles;
        Mesh.normals   = Normals;
        Mesh.uv        = UV;

        if (_MeshFilter == null)
        {
            InitializeComponents();
        }
        _MeshFilter.mesh = Mesh;

        BuildTexture(d);
    }
示例#3
0
    protected void BuildTexture(dungeon d)
    {
        int TexWidth  = (d.n_cols + 1) * TileResolution;
        int TexHeight = (d.n_rows + 1) * TileResolution;

        Texture2D Texture = new Texture2D(TexWidth, TexHeight);

        for (int r = 0; r <= d.n_rows; r++)
        {
            for (int c = 0; c <= d.n_cols; c++)
            {
                Sprite s;
                if ((d.cell[r][c] & dungeon.DOORSPACE) != dungeon.NOTHING)
                {
                    s = DoorSprite;
                }
                else if ((d.cell[r][c] & dungeon.ROOM) != dungeon.NOTHING)
                {
                    s = RoomSprite;
                }
                else if ((d.cell[r][c] & dungeon.CORRIDOR) != dungeon.NOTHING)
                {
                    s = RoomSprite;
                }
                else
                {
                    s = EmptySprite;
                }

                DrawCell(Texture, c * TileResolution, r * TileResolution, s);
            }
        }

        Texture.filterMode = FilterMode.Point;
        Texture.wrapMode   = TextureWrapMode.Clamp;
        Texture.Apply();

        if (_MeshRenderer == null)
        {
            InitializeComponents();
        }
        _MeshRenderer.sharedMaterials[0].mainTexture = Texture;
    }
    public override void OnInspectorGUI()
    {
        Sample2DRenderer r = (Sample2DRenderer)target;

        DrawDefaultInspector();
        if (GUILayout.Button("Renegerate"))
        {
            dungeon d = r.GenerateDungeon();
            r.BuildMesh(d);
        }
        if (GUILayout.Button("New seed"))
        {
            r.Seed = System.Environment.TickCount;
        }
        if (GUILayout.Button("Export To PNG"))
        {
            string path = EditorUtility.SaveFilePanel(
                "Save texture as PNG",
                "",
                "Dungeon.png",
                "png");

            if (path.Length != 0)
            {
                Texture2D tex = r.MeshRenderer.sharedMaterials[0].mainTexture as Texture2D;

                // Convert the texture to a format compatible with EncodeToPNG
                if (tex.format != TextureFormat.ARGB32 && tex.format != TextureFormat.RGB24)
                {
                    Texture2D newTexture = new Texture2D(tex.width, tex.height);
                    newTexture.SetPixels(tex.GetPixels(0), 0);
                    tex = newTexture;
                }
                byte[] pngData = tex.EncodeToPNG();
                if (pngData != null)
                {
                    System.IO.File.WriteAllBytes(path, pngData);
                }
            }
        }
    }
示例#5
0
    // Use this for initialization
    void Start()
    {
        dungeon d = GenerateDungeon();

        BuildMesh(d);
    }
示例#6
0
        // TODO: Implement in all rooms tips, go back and things to find and put them in the inventar
        // TODO: Solve problem with go back, how do we know from where the person comes
        public int RunProgram()
        {
            Character.Inventory = new List <Item>();
            distributeNotes();
            TypeWriter typewriter = new TypeWriter();

            Console.SetOut(typewriter);
            Console.WriteLine(
                "Du gehst gerade nach Hause, als du plötztlich von hinten einen Schlag auf den Kopf bekommst!" +
                "\nAls du wieder zu dir kommst, spürst du einen stechenden Schmerz an deinem Hinterkopf. Warte, wer warst Du noch einmal?");
            Character.Name = Console.ReadLine();
            Console.WriteLine($"Ach genau! Du bist {Character.Name}, richtig?");
            String[] validInput   = { "nein", "ja" };
            string   confirmation = CheckInput(validInput);

            if (confirmation.ToLower().Equals("nein"))
            {
                Console.WriteLine("Wie ist denn dann dein Name?");
                Character.Name = Console.ReadLine();
            }

            Console.WriteLine("Nach allem Anschein wurdest du entführt. Du solltest versuchen dich zu befreien!" +
                              "\nDu ertastest deine Umgebung und merkst, dass du auf einem Bett sitzt. Was willst Du tun?\nAufstehen?\nUmsehen?");


            validInput   = new[] { "aufstehen", "umsehen" };
            confirmation = CheckInput(validInput);

            if (confirmation.Equals("umsehen"))
            {
                Console.WriteLine(
                    "Du kannst nicht viel sehen. Das Einzige, das Du erkennen kannst, sind die Umrisse des Betts. Du versuchst aufzustehen.");
                Console.WriteLine("Du tastest Dich weiter und erfühlst eine Kerze und Streichhölzer!");
                // if (_character.Inventory.Exists(x => x.ItemName == "Kerze"))
                // {
                // Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                // }
            }

            if (confirmation.ToLower().Equals("aufstehen"))
            {
                Console.WriteLine("Du tastest Dich weiter und erfühlst eine Kerze und Streichhölzer!");
            }

            Character.Inventory.Add(new Item()
            {
                ItemName = "Kerze"
            });
            Console.WriteLine("\nDu zündest die Kerze an und kannst nun Deine Umgebung besser erkennen.");

            bool doorOpened = false;
            bool keyFound   = false;

            while (doorOpened == false)
            {
                Console.WriteLine(
                    "Du siehst: Einen Schrank, ein Bett und eine Tür. Was willst Du Dir genauer ansehen?");
                validInput   = new[] { "tür", "schrank", "bett" };
                confirmation = CheckInput(validInput);

                switch (confirmation)
                {
                case "tür":
                    if (keyFound)
                    {
                        Console.WriteLine(
                            "Du gehst auf die Tür zu und versuchst die Tür mit dem Schlüssel zu öffnen. Der Schlüssel lässt sich im Schloss umdrehen und die Tür öffnet sich. \nDu gehst hindurch.");
                        doorOpened = true;
                        Room       = "corridorOne";
                        break;
                    }

                    Console.WriteLine(
                        "Du gehst auf die Tür zu. Sie wirkt ziemlich alt.\nDu versuchst sie zu öffnen, aber sie bewegt sich keinen Zentimeter.");
                    break;

                case "schrank":
                    Console.WriteLine(
                        "Der Schrank steht in der Ecke des Raums. So wie es aussieht, scheint nur unbrauchbares Zeug darin zu liegen.");
                    break;

                case "bett":
                    Console.WriteLine("Du schaust unters Bett und findest eine Schatulle. Willst Du sie öffnen? ");
                    validInput   = new[] { "ja", "nein" };
                    confirmation = CheckInput(validInput);

                    if (confirmation.Equals("nein"))
                    {
                        Console.WriteLine("Bist Du Dir sicher?");
                        confirmation = CheckInput(validInput);
                        if (confirmation.Equals("ja"))
                        {
                            break;
                        }
                    }

                    Console.WriteLine(
                        "Du öffnest die Schatulle, in der sich ein Schlüssel befindet. Wofür könnte dieser sein? ");
                    keyFound = true;
                    break;
                }
            }

            while (!GameFinished)
            {
                switch (Room)
                {
                case "bedroom":
                    while (Room == "bedroom")
                    {
                        string retval = new bedroom(this).run();
                        if (retval.Equals("corridorOne"))
                        {
                            Room = "corridorOne";
                        }
                    }

                    break;

                case "corridorOne":
                    while (Room == "corridorOne")
                    {
                        string retval = new corridor1(this).run();
                        if (retval.Equals("attic"))
                        {
                            Room = "attic";
                        }
                        else if (retval.Equals("entranceArea"))
                        {
                            _isDownstairs = false;
                            Room          = "entranceArea";
                        }
                    }

                    break;

                case "attic":
                    while (Room == "attic")
                    {
                        string retval = new attic(this).run();
                        if (retval.Equals("corridorOne"))
                        {
                            Room = "corridorOne";
                        }
                    }

                    break;

                case "entranceArea":
                    string val = new entranceArea(this).run(_isDownstairs);
                    if (val.Equals("corridorOne"))
                    {
                        Room = "corridorOne";
                    }
                    else if (val.Equals("corridorTwo"))
                    {
                        Room = "corridorTwo";
                    }
                    else if (val.Equals("kitchen"))
                    {
                        Room = "kitchen";
                    }

                    break;

                case "kitchen":
                    while (Room == "kitchen")
                    {
                        string retval = new kitchen(this).run();
                        if (retval.Equals("entranceArea"))
                        {
                            _isDownstairs = true;
                            Room          = "entranceArea";
                        }
                        else if (retval.Equals("garden"))
                        {
                            Room = "garden";
                        }
                    }

                    break;

                case "garden":
                    while (Room == "garden")
                    {
                        string retval = new garden(this).run();
                        if (retval.Equals("kitchen"))
                        {
                            Room = "kitchen";
                        }
                        else if (retval.Equals("ballroom"))
                        {
                            Room = "ballroom";
                        }
                    }

                    break;

                case "ballroom":
                    while (Room == "ballroom")
                    {
                        string retval = new ballroom(this).run();
                        if (retval.Equals("corridorTwo"))
                        {
                            Room = "corridorTwo";
                        }
                        else if (retval.Equals("balcony"))
                        {
                            Room = "balcony";
                        }
                    }

                    break;

                case "balcony":
                    while (Room == "balcony")
                    {
                        string retval = new balcony(this).run();
                        if (retval.Equals("ballroom"))
                        {
                            Room = "ballroom";
                        }
                    }

                    break;

                case "corridorTwo":
                    while (Room == "corridorTwo")
                    {
                        string retval = new corrdidor2(this).run();
                        if (retval.Equals("entranceArea"))
                        {
                            _isDownstairs = true;
                            Room          = "entranceArea";
                        }
                        else if (retval.Equals("library"))
                        {
                            Room = "library";
                        }
                        else if (retval.Equals("dungeon"))
                        {
                            Room = "dungeon";
                        }
                        else if (retval.Equals("corridorTwo"))
                        {
                            Room = "corridorTwo";
                        }
                    }

                    break;

                case "library":
                    while (Room == "library")
                    {
                        string retval = new library(this).run();
                        if (retval.Equals("corridorTwo"))
                        {
                            Room = "corridorTwo";
                        }
                    }

                    break;

                case "dungeon":
                    Console.WriteLine("Du gehst langsam die Treppe hinunter, die immer weiter nach unten führt.");
                    if (Character.Inventory.Exists(x => x.ItemName == "Taschenlampe"))
                    {
                        Console.WriteLine("Mit Deiner Taschanlampe in der Hand, kommst Du unten an.");
                    }
                    else
                    {
                        Console.WriteLine("Unten an der Treppe angekommen, kannst Du kaum noch etwas erkennen");
                    }
                    while (Room == "dungeon")
                    {
                        string retval = new dungeon(this).run();
                        if (retval.Equals("corridorTwo"))
                        {
                            Room = "corridorTwo";
                        }
                    }

                    break;

                default:
                    return(1);
                }
            }

            return(1);
        }