コード例 #1
0
        /// <summary>
        /// update the displayed image in the picturebox of the form so there can be animations displayed.
        /// </summary>
        /// <param name="sender">interval</param>
        /// <param name="e"></param>
        private void UpdateImage(object sender, EventArgs e)
        {
            timerForMaids.Tick += (UpdateEvents);                           //call updateevents
            elevator            = roomFactory.elevator;                     //get the elevator and store it for later use
            personLayout.Dispose();                                         //empty the Bitmap
            personLayout = new Bitmap(background.Width, background.Height); //create new one

            //if there are changes in the simulation
            //update personlayout
            if (peopleToDraw != manager.people)
            {
                peopleToDraw.Clear();//empty the list
                //foreach person in manager.people add it to peopleToDraw
                foreach (KeyValuePair <IPerson, IRoom> person in manager.people)
                {
                    IPerson last = manager.people.Keys.Last();
                    peopleToDraw.Add(person.Key, person.Value);

                    //if person has a path to walk. go walk
                    if (person.Key.route != null && person.Key.route.Count > 0)
                    {
                        bool wait = false;

                        if (roomFactory.elevator.position == person.Key.position) //check if person is in a elevator
                        {
                            wait = true;
                            if (roomFactory.elevator.running == true)//if elevator is running person can go up
                            {
                                person.Key.WalkTo();

                                if (person.Key.Equals(last))//if last person moved update the elvator
                                {
                                    elevator.prevPosition = elevator.position;
                                    elevator.position     = new Point(0, elevator.people.Last().position.Y);//set the elevator to same pos as person in elevator.
                                    roomFactory.coordinates[elevator.position.X, elevator.position.Y] = elevator;
                                    if (elevator.prevPosition != elevator.position)
                                    {
                                        ElevatorShaft shaft = new ElevatorShaft();
                                        shaft.dimension = new Point(1, 1);
                                        roomFactory.coordinates[elevator.prevPosition.X, elevator.prevPosition.Y] = shaft;
                                        shaft.position = elevator.prevPosition;
                                    }
                                }
                                IRoom check = roomFactory.coordinates[person.Key.position.X, person.Key.position.Y];
                                if (check != null && roomFactory.coordinates[check.position.X, check.position.Y] == check)
                                {
                                    person.Key.currentRoom = check;
                                }
                                manager.dijkstra.CreateGraph(roomFactory.coordinates);
                            }
                        }
                        else if (wait == false)//if wait is false. The person is not in a elevator so it can continue moving.
                        {
                            person.Key.WalkTo();
                            IRoom check = roomFactory.coordinates[person.Key.position.X, person.Key.position.Y];
                            if (check != null && roomFactory.coordinates[check.position.X, check.position.Y] == check)
                            {
                                person.Key.currentRoom = check;
                            }
                        }
                        wait = false;
                    }

                    Customer current = null;

                    //if person is customer and is checking out remove him
                    if (person.Key.id.Contains("Gast"))
                    {
                        current = (Customer)person.Key;
                        ///if a person is in the lobby and is checked out or a evac is going on
                        ///make them dissapear
                        if (current.checkedIn == false && current.currentRoom == roomFactory.coordinates[1, 0] || current.currentRoom.position == new Point(1, 0) && manager.evacuation == true)
                        {
                            peopleToDraw.Remove(current);
                        }
                    }
                }
            }
            //draw the new personLayout and background
            background.Dispose();
            background   = draw.DrawLayout(roomFactory.coordinates);
            personLayout = draw.DrawPersonLayout(personLayout, peopleToDraw);

            //dislay new persenLayout and background
            hotelMap.BackgroundImage = background;
            hotelMap.Image           = personLayout;
        }
コード例 #2
0
        /// <summary>
        /// Overview of the layout
        /// </summary>
        /// <returns>2D array with rooms</returns>
        private IRoom[,] CreateOverview()
        {
            Point maxArray = new Point();

            maxArray.X = 0;
            maxArray.Y = 0;
            Point lobbyDimension    = new Point();
            Point stairsDimension   = new Point();
            Point elevatorDimension = new Point();

            //set the dimensions of the 2dArray
            foreach (IRoom room in rooms)
            {
                if (room.position.X > maxArray.X)
                {
                    maxArray.X = room.position.X;
                }
                if (room.position.Y > maxArray.Y)
                {
                    maxArray.Y = room.position.Y;
                }
            }

            //create 2dArray
            coordinates = new IRoom[maxArray.X + 2, maxArray.Y + 1];

            //add the rooms to the array
            foreach (IRoom room in rooms)
            {
                coordinates[room.position.X, room.position.Y] = room;
            }
            for (int i = 0; i < maxArray.X; i++)
            {
                if (coordinates[i, 0] == null)
                {
                    lobbyDimension.X++;
                }
                else
                {
                    break;
                }
            }



            //create the lobby and add to array
            Lobby lobby = new Lobby();

            lobbyDimension.Y  = 1;
            lobby.dimension   = new Point(lobbyDimension.X, 1);
            coordinates[1, 0] = lobby;

            for (int i = 0; i < maxArray.Y; i++)
            {
                if (coordinates[0, i] == null)
                {
                    elevatorDimension.Y++;
                    stairsDimension.Y++;
                }
                else
                {
                    break;
                }
            }

            elevator              = new Elevator();
            elevator.dimension    = new Point(1, 1);
            elevator.position     = new Point(0, 0);
            elevator.prevPosition = new Point(0, 0);
            coordinates[0, 0]     = elevator;
            //create elevator + shaft and add to array
            for (int i = 1; i < coordinates.GetLength(1); i++)
            {
                ElevatorShaft elevatorShaft = new ElevatorShaft();
                elevatorShaft.dimension = new Point(1, 1);
                elevatorShaft.position  = new Point(0, i);
                coordinates[0, i]       = elevatorShaft;
            }

            //create stairs and add to array
            for (int i = 0; i < coordinates.GetLength(1); i++)
            {
                Stairs stairs = new Stairs();
                stairs.dimension = new Point(1, 1);
                stairs.position  = new Point(coordinates.GetLength(0) - 1, i);
                coordinates[coordinates.GetLength(0) - 1, i] = stairs;
            }

            return(coordinates);
        }