public void MergeWith2(Room2 roomToMerge, string border)
        {
            border2.Remove(border);

            conections.Add(roomToMerge.GetID());


            foreach (var n in roomToMerge.GetBorderMap())
            {
                if (!neighbours.ContainsKey(n.Key))
                {
                    neighbours.Add(n.Key, n.Value);
                }
                else
                {
                    var l = neighbours[n.Key];
                    foreach (var i in n.Value)
                    {
                        if (i != border)
                        {
                            l.Add(i);
                        }
                    }
                    neighbours[n.Key] = l;
                }
            }
            foreach (var c in conections)
            {
                if (neighbours.ContainsKey(c))
                {
                    neighbours.Remove(c);
                }
            }
        }
示例#2
0
        private void ConectRooms2()
        {
            /**Room Connect algorith destciption
             * 1, Select room - separate it from array
             * 2, Find all of the neghbourt of the room and randomly choose one
             * 3, selectst random border of the room - merge with current room and delete from list
             * 4, add current room to the list
             */
            rooms = rooms2.Values.ToList();
            //randomly choosing room
            Random random = new Random();
            int    count  = rooms2.Count();

            ;
            int   rand     = random.Next(2, count + 1);
            Room2 megaRoom = rooms2[rand];


            while (rooms2.Count() != 1)
            {
                rooms2.Remove(megaRoom.GetID());
                //Choose one random neighbour and conect
                Room2 neighboutr   = new Room2(); //empty constructor (ID is zero and all tiles are empty);
                int   roomToChange = 0;

                if (megaRoom.GetSurrounding().Count != 0)
                {
                    roomToChange = megaRoom.GetSurrounding().First();
                }
                else
                {
                    Console.WriteLine("Error ocured during room maping");
                    break;
                }
                string border = megaRoom.GetBorderMap()[roomToChange].First();



                int coordinateX = ParseMap(border)[0];
                int coordinateY = ParseMap(border)[1];
                dMap[coordinateY][coordinateX]        = door;
                roomMap[coordinateY][coordinateX]     = int.MaxValue;
                roomTypeMap[coordinateY][coordinateX] = int.MaxValue;

                //merging
                megaRoom.MergeWith2(rooms2[roomToChange], border);
                rooms2.Remove(roomToChange);
                rooms2.Add(megaRoom.GetID(), megaRoom);
            }
        }