예제 #1
0
        public List <Room> GetNeighbors(Level level, Room vertex)
        {
            Room NorthNeighbor;
            Room EastNeighbor;
            Room SouthNeighbor;
            Room WestNeighbor;
            //Iterate through array of hallway and get neighbors
            //check if the neighbors are visited
            Hallway NorthNeighborHallway = level.GetRoom(vertex).GetHallway(Enum.Direction.North);
            Hallway EastNeighborHallway  = level.GetRoom(vertex).GetHallway(Enum.Direction.East);
            Hallway SouthNeighborHallway = level.GetRoom(vertex).GetHallway(Enum.Direction.South);
            Hallway WestNeighborHallway  = level.GetRoom(vertex).GetHallway(Enum.Direction.West);

            NorthNeighbor = NorthNeighborHallway == null || NorthNeighborHallway.IsCollapsed ? null : NorthNeighborHallway.GetConnectedRoom(vertex);
            EastNeighbor  = EastNeighborHallway == null || EastNeighborHallway.IsCollapsed ? null : EastNeighborHallway.GetConnectedRoom(vertex);
            SouthNeighbor = SouthNeighborHallway == null || SouthNeighborHallway.IsCollapsed ? null : SouthNeighborHallway.GetConnectedRoom(vertex);
            WestNeighbor  = WestNeighborHallway == null || WestNeighborHallway.IsCollapsed ? null : WestNeighborHallway.GetConnectedRoom(vertex);

            List <Room> neighbors = new List <Room>();

            neighbors.Add(NorthNeighbor);
            neighbors.Add(EastNeighbor);
            neighbors.Add(SouthNeighbor);
            neighbors.Add(WestNeighbor);
            return(neighbors);
        }
예제 #2
0
        public Hallway GetLowestLevelHallway(List <Room> visited)
        {
            Hallway lowest = new Hallway(999, new Room());

            for (int i = 0; i < 4; i++)
            {
                if ((this.Hallways[i] != null &&
                     this.Hallways[i].IsCollapsed == false &&
                     visited.Contains(this.Hallways[i].GetConnectedRoom(this)) == false) &&
                    this.Hallways[i].Enemy < lowest.Enemy)
                {
                    lowest = this.Hallways[i];
                }
            }
            return(lowest);
        }
예제 #3
0
 public void SetHallway(Direction direction, Hallway hallway)
 {
     this.Hallways[(int)direction] = hallway;
 }
예제 #4
0
        public void PrimsSafetyProtocol(Level level, Room startRoom)
        {
            List <Room>    visited        = new List <Room>();
            List <Room>    unvisited      = new List <Room>();
            List <Hallway> notCollapsable = new List <Hallway>();

            //Add all nodes to the unvisited
            foreach (Room room in level.GetMap())
            {
                unvisited.Add(room);
            }

            //Haal de startkamer uit unvisited en doe deze bij visited (eerste kamer om vanuit te werken)
            unvisited.Remove(startRoom);
            visited.Add(startRoom);

            //While unvisited is not empty
            while (unvisited.Count > 0)
            {
                Room    lowestRoom    = new Room();
                Hallway lowestHallway = new Hallway(999, null);

                //Check foreach room which hallway has the lowest cost
                foreach (Room n in visited)
                {
                    //To show what rooms are visited with the algorithm
                    //n.IsVisited = true;
                    //level.DrawMap();
                    //Thread.Sleep(25);

                    Hallway h = n.GetLowestLevelHallway(visited);
                    if (h != null && h.Enemy < lowestHallway.Enemy)
                    {
                        //Set lowestHallway and lowestRoom to the lowestcost hallway and the connected room
                        lowestHallway = h;
                        lowestRoom    = h.GetConnectedRoom(n);
                    }
                }
                if (lowestRoom == null)
                {
                    break;
                }
                notCollapsable.Add(lowestHallway);
                visited.Add(lowestRoom);
                unvisited.Remove(lowestRoom);
            }

            //To remove the discovery animation
            level.CleanPathAndCollapsable();

            //This can be done in the above while loop, not using a list of notCollapsable but immediately setting the notCollapsable property
            //Also better this way to make the discovery animation
            foreach (Hallway h in notCollapsable)
            {
                h.IsCollapsable = false;
            }

            //Explode random
            Random random = new Random();

            while (true)
            {
                Hallway hallway = startRoom.GetHallway((Direction)random.Next(1, 4));
                if (hallway != null)
                {
                    hallway.Enemy = 0;
                    break;
                }
            }
        }