예제 #1
0
        /// <summary>
        /// search all rooms in AreaList assigning coords then checking neighbours
        /// and repeating until AreaList is empty
        ///
        /// Completed rooms are added to CompletedRooms and removed from AreaList
        ///
        /// </summary>
        /// <returns>Returns CompletedRooms which contains the list of rooms that have coordinates set</returns>
        public List <Room.Room> AssignCoords()
        {
            var startingLoc = AreaList.FirstOrDefault(x => x.areaId == 0);

            if (startingLoc == null)
            {
                return(null);
            }

            SetCoords(startingLoc, new Coordinates());

            /*
             * Takes the 1st room and search all 4 exits
             * and assigns them coordinates adding them
             * to the completed list
             */
            ProcessRoom(startingLoc);

            /*
             * Now completedList has areas, loop areaList looking for rooms
             * that have exits that lead to one of the rooms in the completed list
             */
            while (AreaList.Count > 0)
            {
                var getRoom = AreaList.Last();

                //Check if getRoom has a neighbour in the completed List
                var getNeighbour = GetNeighbour(getRoom);

                if (getNeighbour != null)
                {
                    var getExitToNeighbour = GetNeighbourExit(getRoom, getNeighbour);

                    if (getExitToNeighbour != null)
                    {
                        SetCoords(getRoom, GetNewCoord(getNeighbour.coords, getExitToNeighbour.name, true));
                    }

                    ProcessRoom(getRoom);
                }
                else
                {
                    /*
                     * if nothing found remove the room from areaList
                     * and add back to the top of the Area:ist
                     */
                    AreaList.Remove(getRoom);
                    AreaList.Insert(0, getRoom);
                }
            }

            //Once all rooms in areaList have been processed return the list of completed rooms
            return(CompletedRooms);
        }
예제 #2
0
        private void ExecuteDelete(Area area)
        {
            MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure to delete", "Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                using (var unitofWork = new UnitOfWork(new MahalluDBContext())) {
                    AreaList.Remove(area);
                    eventAggregator.GetEvent <PubSubEvent <ObservableCollection <Area> > >().Publish(AreaList);
                    var result = unitofWork.Areas.Find((x) => x.Id == area.Id).FirstOrDefault();
                    unitofWork.Areas.Remove(result);
                    unitofWork.Complete();
                }
            }
        }
예제 #3
0
        /// <summary>
        /// loops through the exits of getRoom looking for adjacent rooms in AreaList
        /// then assigns coords to getRoom relating to the adjacent room
        ///
        /// For example:
        /// getRoom is (0,0,0) and has an exit which leads to areaId 1
        ///
        /// nextRoom is a room that has the matching areaId of one of getRoom's exits
        /// in this case 1.
        ///
        /// So the coordinates it will assign to nextRoom is (1,0,0)
        ///
        /// Because GetNewCoord(getRoom.coords, exit.name);
        /// would look like this:
        /// GetNewCoord((0,0,0), "North");
        ///
        /// Once the coord has been given to a room it adds it to the completed
        /// list and removes it from area list
        ///
        /// </summary>
        /// <param name="getRoom">Last room from area list</param>
        public void ProcessRoom(Room.Room getRoom)
        {
            foreach (var exit in getRoom.exits)
            {
                var nextRoom       = AreaList.FirstOrDefault(x => x.areaId == exit.areaId);
                var nextRoomCoords = GetNewCoord(getRoom.coords, exit.name);

                if (nextRoom != null && nextRoom.visited == false)
                {
                    SetCoords(nextRoom, nextRoomCoords);
                    nextRoom.visited = true;
                    CompletedRooms.Add(nextRoom);
                    AreaList.Remove(nextRoom);
                }
            }

            getRoom.visited = true;
            CompletedRooms.Add(getRoom);
            AreaList.Remove(getRoom);
        }