static void Main(string[] args)
        {
            Player player = new Player();
            Console.ForegroundColor = ConsoleColor.White;

            // Title Screen
            Console.WriteLine("===================================\nDUNGEON CRAWLER (by Chris Simmons)\n===================================\n");

            // Set Player Name
            Console.WriteLine("Please type your name and hit enter:");
            player.name = Console.ReadLine();

            // Set Class
            Console.WriteLine("What class are you? (1 = Warrior, 2 = Archer, 3 = Mage)");
            player.role = Convert.ToInt32(Console.ReadLine());

            // Display Player Details
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Now playing as " + player.details());

            // Init Dungeons
            Dungeon dungeonOne = new Dungeon(player, 1);
            // Dungeon dungeonTwo = new Dungeon(player, 2);

            // Display
            Console.ReadLine();

        }
Пример #2
0
        public static Dungeon MakeDungeon(Hero hero, string filename)
        {
            Dungeon dungeon = new Dungeon();

            string[] lines = System.IO.File.ReadAllLines(filename);

            dungeon.PointScaleFactor = Int32.Parse(lines[0]);
            foreach (string line in lines.Skip(1))
            {
                string[] lineInfo = line.Split(' ');

                if (lineInfo[0] == "room:" || lineInfo[0] == "door:")
                {
                    Point topLeft = new Point(
                        Int32.Parse(lineInfo[1]), Int32.Parse(lineInfo[2]));
                    Point bottomRight = new Point(
                        Int32.Parse(lineInfo[3]), Int32.Parse(lineInfo[4]));

                    if (lineInfo[0] == "room:")
                    {
                        dungeon.Size = Math.Max(Math.Max(bottomRight.X, bottomRight.Y), dungeon.Size);

                        Room r = new Room(topLeft, bottomRight);
                        dungeon.Rooms.Add(r);
                    }
                    else
                    {
                        Room room1 = null;
                        Room room2 = null;

                        // each door has two rooms
                        foreach (Room room in dungeon.Rooms)
                        {
                            if (room.isInside(topLeft))
                            {
                                room1 = room;
                            }
                            else if (room.isInside(bottomRight))
                            {
                                room2 = room;
                            }
                        }

                        Point doorPoint;
                        if (room1.isInside(topLeft) && room2.isInside(bottomRight))
                        {
                            room1.AddDoor(topLeft, room2);
                            room2.AddDoor(bottomRight, room1);
                        }
                    }
                }
                else
                {
                    Point loc = new Point(Int32.Parse(lineInfo[1]), Int32.Parse(lineInfo[2]));

                    foreach (Room room in dungeon.Rooms)
                    {
                        if (room.isInside(loc))
                        {
                            if (lineInfo[0] == "monster:")
                            {
                                Monster monster;
                                if (lineInfo[3] == "O")
                                {
                                    monster = new Orc();
                                }
                                else
                                {
                                    monster = new Goblin();
                                }

                                monster.SetDungeon(dungeon);
                                monster.Pos = loc;
                                room.AddMonster(monster);
                            }
                            else if ((lineInfo[0] == "item:"))
                            {
                                Item item;
                                if (lineInfo[3] == "A")
                                {
                                    item = new Armor();
                                    ((Armor)item).Resistance = Int32.Parse(lineInfo[4]);
                                }
                                else
                                {
                                    item = new Weapon();
                                    ((Weapon)item).Damage = Int32.Parse(lineInfo[4]);
                                }

                                item.Pos = loc;
                                room.AddItem(item);
                            }
                        }
                    }
                }
            }

            List <Point> posWrap = new List <Point>();
            int          len     = 0;

            foreach (var room in dungeon.Rooms)
            {
                for (int i = room.TopLeft.X; i < room.BottomRight.X; i++)
                {
                    for (int j = room.TopLeft.Y; j < room.BottomRight.Y; j++)
                    {
                        var point = new Point(i, j);

                        bool bad = false;
                        foreach (Monster monster in room.Monsters)
                        {
                            if (monster.Pos.X == point.X && monster.Pos.Y == point.Y)
                            {
                                bad = true;
                            }
                        }

                        if (!bad)
                        {
                            posWrap.Add(point);
                            len++;
                        }
                    }
                }
            }

            Random ran = new Random();
            Point  pos = posWrap[ran.Next(0, len - 1)];

            hero.SetDungeon(dungeon);
            hero.Pos = pos;

            foreach (Room room in dungeon.Rooms)
            {
                if (room.isInside(hero.Pos))
                {
                    hero.Room = room;
                    break;
                }
            }

            dungeon.Hero = hero;

            return(dungeon);
        }
Пример #3
0
        public static Dungeon GenerateDungeon(Hero hero)
        {
            Random ran = new Random();

            Dungeon dungeon = new Dungeon();

            Room room = new Room(new Point(0, 0), new Point(ran.Next(3, 10), ran.Next(3, 20)));

            dungeon.Rooms.Add(room);

            Room newRoom = room;

            for (int j = 0; j < 2; j++)
            {
                for (int i = 0; i < 2000; i++)
                {
                    newRoom = makeRoom(room);
                    bool overlap = false;
                    foreach (Room r in dungeon.Rooms)
                    {
                        if (r.isInside(newRoom.TopLeft) || r.isInside(newRoom.BottomRight) || r.isInside(new Point(newRoom.TopLeft.X, newRoom.BottomRight.Y)) || r.isInside(new Point(newRoom.TopLeft.Y, newRoom.BottomRight.X)))
                        {
                            overlap = true;
                            break;
                        }
                    }
                    if (overlap)
                    {
                        continue;
                    }
                    if (newRoom.TopLeft.X < 0 || newRoom.TopLeft.X > 29 || newRoom.TopLeft.Y < 0 || newRoom.TopLeft.Y > 29 || newRoom.BottomRight.X > 29 || newRoom.BottomRight.Y > 29)
                    {
                        //Console.WriteLine(",,");
                    }
                    else
                    {
                        dungeon.Rooms.Add(newRoom);
                        room = newRoom;
                        break;
                    }
                }
                //Console.WriteLine(newRoom.TopLeft);
                //Console.WriteLine(newRoom.BottomRight);
                //dungeon.Rooms.Add(newRoom);
                //room = newRoom;
            }

            for (int j = 0; j < dungeon.Rooms.Count; j++)
            {
                room = dungeon.Rooms[j];
                for (int i = 0; i < 2000; i++)
                {
                    newRoom = makeRoom(room);
                    bool overlap = false;
                    foreach (Room r in dungeon.Rooms)
                    {
                        if (r.isInside(newRoom.TopLeft) || r.isInside(newRoom.BottomRight) || r.isInside(new Point(newRoom.TopLeft.X, newRoom.BottomRight.Y)) || r.isInside(new Point(newRoom.TopLeft.Y, newRoom.BottomRight.X)))
                        {
                            overlap = true;
                            break;
                        }
                    }
                    if (overlap)
                    {
                        continue;
                    }
                    if (newRoom.TopLeft.X < 0 || newRoom.TopLeft.X > 29 || newRoom.TopLeft.Y < 0 || newRoom.TopLeft.Y > 29 || newRoom.BottomRight.X > 29 || newRoom.BottomRight.Y > 29)
                    {
                        //Console.WriteLine(",,");
                    }
                    else
                    {
                        dungeon.Rooms.Add(newRoom);
                        room = newRoom;
                        break;
                    }
                }
            }


            for (int i = 0; i < 5; i++)
            {
                foreach (Room r in dungeon.Rooms)
                {
                }
            }



            return(dungeon);
        }
Пример #4
0
        static void Main(string[] args)
        {
            Dungeon dngcrwlr = new Dungeon(10, 10, 14, 85);

            System.Console.ReadKey();
        }