Exemplo n.º 1
0
 public void DrawMap()
 {
     foreach (ModelRoom ModelRoom in MapModelRoomList)
     {
         ModelRoom.draw();
     }
 }
Exemplo n.º 2
0
 public void addTopNeighbours(ModelRoom ModelRoom)
 {
     if (!topNeighbours.Contains(ModelRoom))
     {
         topNeighbours.Add(ModelRoom);
     }
 }
Exemplo n.º 3
0
 public void addLeftNeighbours(ModelRoom ModelRoom)
 {
     if (!leftNeighbours.Contains(ModelRoom))
     {
         leftNeighbours.Add(ModelRoom);
     }
 }
Exemplo n.º 4
0
 public void addBottomNeighbours(ModelRoom ModelRoom)
 {
     if (!bottomNeighbours.Contains(ModelRoom))
     {
         bottomNeighbours.Add(ModelRoom);
     }
 }
Exemplo n.º 5
0
 public void ClearAll()
 {
     foreach (ModelRoom ModelRoom in ModelRoomList)
     {
         ModelRoom.clear();
     }
 }
Exemplo n.º 6
0
    public bool Colision(ModelRoom ModelRoom)
    {
        bool collisionX = false;
        bool collisionY = false;

        if (ModelRoom.leftX < leftX)
        {
            if (ModelRoom.rightX >= leftX)
            {
                collisionX = true;
            }
        }
        else if (ModelRoom.leftX <= rightX)
        {
            collisionX = true;
        }


        if (ModelRoom.bottomY < bottomY)
        {
            if (ModelRoom.topY >= bottomY)
            {
                collisionY = true;
            }
        }
        else if (ModelRoom.bottomY <= topY)
        {
            collisionY = true;
        }
        if (collisionX && collisionY)
        {
            return(true);
        }
        return(false);
    }
Exemplo n.º 7
0
 public void addRightNeighbours(ModelRoom ModelRoom)
 {
     if (!rightNeighbours.Contains(ModelRoom))
     {
         rightNeighbours.Add(ModelRoom);
     }
 }
Exemplo n.º 8
0
    void clearPointsForNeighbors(List <ModelRoom> ModelModelRoomList)
    {
        List <Vector2> pointsForNeighborsLT = new List <Vector2>();
        List <Vector2> pointsForNeighborsLB = new List <Vector2>();
        List <Vector2> pointsForNeighborsRT = new List <Vector2>();
        List <Vector2> pointsForNeighborsRB = new List <Vector2>();

        for (int i = 0; i < pointsForNeighborsLT.Count; i++)
        {
            foreach (ModelRoom ModelRoom in ModelModelRoomList)
            {
                if (ModelRoom.Colision(pointsForNeighborsLT[i].x, pointsForNeighborsLT[i].y - sizeMinY, pointsForNeighborsLT[i].x + sizeMinX, pointsForNeighborsLT[i].y))
                {
                    pointsForNeighborsLT.RemoveAt(i);
                    i--;
                    break;
                }
            }
        }

        for (int i = 0; i < pointsForNeighborsLB.Count; i++)
        {
            foreach (ModelRoom ModelRoom in ModelModelRoomList)
            {
                if (ModelRoom.Colision(pointsForNeighborsLB[i].x, pointsForNeighborsLB[i].y, pointsForNeighborsLB[i].x + sizeMinX, pointsForNeighborsLB[i].y + sizeMinY))
                {
                    pointsForNeighborsLT.RemoveAt(i);
                    i--;
                    break;
                }
            }
        }

        for (int i = 0; i < pointsForNeighborsRT.Count; i++)
        {
            foreach (ModelRoom ModelRoom in ModelModelRoomList)
            {
                if (ModelRoom.Colision(pointsForNeighborsRT[i].x - sizeMinX, pointsForNeighborsRT[i].y - sizeMinY, pointsForNeighborsRT[i].x, pointsForNeighborsRT[i].y))
                {
                    pointsForNeighborsLT.RemoveAt(i);
                    i--;
                    break;
                }
            }
        }

        for (int i = 0; i < pointsForNeighborsRB.Count; i++)
        {
            foreach (ModelRoom ModelRoom in ModelModelRoomList)
            {
                if (ModelRoom.Colision(pointsForNeighborsRB[i].x - sizeMinX, pointsForNeighborsRB[i].y, pointsForNeighborsRB[i].x, pointsForNeighborsRB[i].y + sizeMinY))
                {
                    pointsForNeighborsLT.RemoveAt(i);
                    i--;
                    break;
                }
            }
        }
    }
Exemplo n.º 9
0
    void addPath(ModelRoom ModelRoom, ModelRoom ModelRoomBetween = null, List <ModelRoom> listModelRoomsBetween = null)
    {
        if (ModelRoomBetween == this)
        {
            ModelRoomBetween = null;
        }
        List <ModelRoom> list;

        for (int i = 0; i < pathList.Count; i++)
        {
            if (pathList[i].target == ModelRoom)
            {
                int length = 0;
                if (ModelRoomBetween != null)
                {
                    length++;
                }
                if (listModelRoomsBetween != null)
                {
                    length += listModelRoomsBetween.Count;
                }
                if (pathList[i].length() > length)
                {
                    list = new List <ModelRoom>();
                    if (listModelRoomsBetween != null)
                    {
                        foreach (ModelRoom item in listModelRoomsBetween)
                        {
                            list.Add(item);
                        }
                    }
                    if (ModelRoomBetween != null)
                    {
                        list.Add(ModelRoomBetween);
                    }

                    pathList[i].ModelRoomsBetween = list;
                }
                return;
            }
        }

        list = new List <ModelRoom>();
        if (listModelRoomsBetween != null)
        {
            foreach (ModelRoom item in listModelRoomsBetween)
            {
                list.Add(item);
            }
        }
        if (ModelRoomBetween != null)
        {
            list.Add(ModelRoomBetween);
        }

        pathList.Add(new ModelPath(ModelRoom, list));
    }
Exemplo n.º 10
0
 bool doorExist(ModelRoom room)
 {
     foreach (ModelDoor door in doors)
     {
         if (door.getDestinationRoom() == room)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 11
0
 public ModelPath(ModelRoom ModelRoom, List <ModelRoom> list = null)
 {
     this.target = ModelRoom;
     if (list != null)
     {
         ModelRoomsBetween = list;
     }
     else
     {
         ModelRoomsBetween = new List <ModelRoom>();
     }
 }
Exemplo n.º 12
0
    public static ModelRoom CreateModelModelRoom(float leftX, float bottomY, float rightX, float topY, List <ModelRoom> ModelModelRoomList)
    {
        foreach (ModelRoom ModelRoom in ModelModelRoomList)
        {
            if (ModelRoom.Colision(leftX, bottomY, rightX, topY))
            {
                return(null);
            }
        }
        ModelRoom newModelModelRoom = new ModelRoom(leftX, bottomY, rightX, topY, ModelModelRoomList.Count);

        ModelModelRoomList.Add(newModelModelRoom);
        return(newModelModelRoom);
    }
Exemplo n.º 13
0
 public void removeNeighbour(ModelRoom room)
 {
     if (rightNeighbours.Contains(room))
     {
         rightNeighbours.Remove(room);
     }
     if (topNeighbours.Contains(room))
     {
         topNeighbours.Remove(room);
     }
     if (bottomNeighbours.Contains(room))
     {
         bottomNeighbours.Remove(room);
     }
     if (leftNeighbours.Contains(room))
     {
         leftNeighbours.Remove(room);
     }
 }
Exemplo n.º 14
0
 public bool isNeighbour(ModelRoom room)
 {
     if (rightNeighbours.Contains(room))
     {
         return(true);
     }
     if (topNeighbours.Contains(room))
     {
         return(true);
     }
     if (bottomNeighbours.Contains(room))
     {
         return(true);
     }
     if (leftNeighbours.Contains(room))
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 15
0
    public void findNeighbours(List <ModelRoom> ModelModelRoomList)
    {
        foreach (ModelRoom ModelRoom in ModelModelRoomList)
        {
            if (ModelRoom.Colision(leftX + doorSize + 1, bottomY - 1, rightX - doorSize - 1, bottomY - 1))
            {
                addBottomNeighbours(ModelRoom);
            }
            if (ModelRoom.Colision(leftX + doorSize + 1, topY + 1, rightX - doorSize - 1, topY + 1))
            {
                addTopNeighbours(ModelRoom);
            }


            if (ModelRoom.Colision(leftX - 1, bottomY + doorSize + 1, leftX - 1, topY - doorSize - 1))
            {
                addLeftNeighbours(ModelRoom);
            }
            if (ModelRoom.Colision(rightX + 1, bottomY + doorSize + 1, rightX + 1, topY - doorSize - 1))
            {
                addRightNeighbours(ModelRoom);
            }
        }
    }
Exemplo n.º 16
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string name1 = sender.ToString();

            string[] words = name1.Split(':');

            ModelRoom id = new ModelRoom(words[1].TrimEnd().TrimStart());


            eq.room.Remove(id);

            Room           s         = new Room();
            RoomController RoomContr = new RoomController();
            List <Room>    lista     = new List <Room>();

            lista = RoomContr.GetAll();

            foreach (Room ee in lista)
            {
                if (ee.typeOfRoom.Equals(id))
                {
                    s = ee;
                    s.medicine.Remove(new ModelMedicine(eq.name));
                }
            }



            MedContr.Update(eq);



            RoomContr.Update(s);



            lista = RoomContr.GetAll();
            List <Room> sobe          = new List <Room>();
            List <Room> sobeSaOpremom = new List <Room>();

            //dataGridEquipment.DataContext = lista;


            foreach (Room item in lista)
            {
                if (item.forUse == true)
                {
                    for (int i = 0; i < eq.room.Count; i++)
                    {
                        ModelRoom soba = eq.room[i];

                        if (soba.Equals(item.typeOfRoom))
                        {
                            sobeSaOpremom.Add(item);
                        }
                    }
                }
            }

            foreach (Room item in lista)
            {
                if (item.forUse == true)
                {
                    bool postoji = false;
                    foreach (Room saOpremom in sobeSaOpremom)
                    {
                        if (item.id == saOpremom.id)
                        {
                            postoji = true;
                        }
                    }

                    if (!postoji)
                    {
                        sobe.Add(item);
                    }
                }
            }



            Combo.ItemsSource       = sobe;
            Combo_Copy.ItemsSource  = sobeSaOpremom;
            Combo_Copy1.ItemsSource = sobeSaOpremom;
        }
Exemplo n.º 17
0
        public MedicineClass(Medicine medicine)
        {
            InitializeComponent();
            eq = medicine;

            name.Text        = medicine.name;
            quantity.Text    = medicine.quantity.ToString();
            description.Text = medicine.description;

            RoomController RoomContr = new RoomController();
            List <Room>    lista     = new List <Room>();

            lista = RoomContr.GetAll();
            List <Room> sobe          = new List <Room>();
            List <Room> sobeSaOpremom = new List <Room>();


            foreach (Room item in lista)
            {
                if (item.forUse == true)
                {
                    if (eq.room != null)
                    {
                        for (int i = 0; i < eq.room.Count; i++)
                        {
                            ModelRoom soba = eq.room[i];

                            if (soba.Equals(item.typeOfRoom))
                            {
                                sobeSaOpremom.Add(item);
                            }
                        }
                    }
                }
            }

            foreach (Room item in lista)
            {
                if (item.forUse == true)
                {
                    bool postoji = false;
                    foreach (Room saOpremom in sobeSaOpremom)
                    {
                        if (item.id == saOpremom.id)
                        {
                            postoji = true;
                        }
                    }

                    if (!postoji)
                    {
                        sobe.Add(item);
                    }
                }
            }



            Combo.ItemsSource       = sobe;
            Combo_Copy.ItemsSource  = sobeSaOpremom;
            Combo_Copy1.ItemsSource = sobeSaOpremom;
        }
    List <ModelRoom> generateMapModelRoomList()
    {
        List <ModelRoom> MapModelRoomList = new List <ModelRoom>();
        List <ModelRoom> ModelRoomList    = new List <ModelRoom>();

        for (int i = 0; i < modelRoomCount; i++)
        {
            if (ModelRoom.createModelRoom(ModelRoomList) == null)
            {
                Debug.Log("jakis blad 212");
            }
        }
        findAllNeighbours(ModelRoomList);
        Debug.Log("1");
        do
        {
            startRoom = ModelRoomList[(int)(UnityEngine.Random.value * (ModelRoomList.Count - 1))];
            startRoom.findAllPath();
        } while (startRoom.pathList.Count < ModelRoomList.Count);


        List <ModelRoom> newModelRoomList = new List <ModelRoom>();
        List <ModelPath> pathList         = startRoom.pathList;

        pathList.RemoveAt(0);
        MapModelRoomList.Add(startRoom);
        for (int i = 0; i < pathCount; i++)
        {
            if (pathList.Count == 0)
            {
                break;
            }


            ModelPath longestPath = pathList[0];
            foreach (ModelPath path in pathList)
            {
                if (longestPath.length() < path.length())
                {
                    longestPath = path;
                }
            }


            MapModelRoomList.Add(longestPath.target);

            endRoom = longestPath.target;

            foreach (ModelRoom ModelRoom in longestPath.ModelRoomsBetween)
            {
                if (!MapModelRoomList.Contains(ModelRoom))
                {
                    MapModelRoomList.Add(ModelRoom);
                }
            }

            for (int j = 0; j < pathList.Count; j++)
            {
                bool delete = false;
                if (pathList[j].target == longestPath.target)   //usuniecie istniejacych pokoi z list celow nowych scierzek
                {
                    pathList.RemoveAt(j);
                    j--;
                    continue;
                }
                foreach (ModelRoom ModelRoom in longestPath.ModelRoomsBetween)
                {
                    if (pathList[j].target == ModelRoom)
                    {
                        delete = true;
                        break;
                    }
                }
                if (delete)
                {
                    pathList.RemoveAt(j);
                    j--;
                    continue;
                }
                if (longestPath.target.isNeighbour(pathList[j].target))   //usuniecie sasiadow konca ciezki
                {
                    pathList.RemoveAt(j);
                    j--;
                    continue;
                }
                for (int k = longestPath.ModelRoomsBetween.Count - 1; k > longestPath.ModelRoomsBetween.Count - 4; k--)
                {
                    if (k < 0)
                    {
                        break;
                    }
                    if (longestPath.ModelRoomsBetween[k].isNeighbour(pathList[j].target))
                    {
                        delete = true;
                        break;
                    }
                }
                if (delete)
                {
                    pathList.RemoveAt(j);
                    j--;
                    continue;
                }
            }
        }
        ClearNeighbours(ModelRoomList, MapModelRoomList);
        createDoors(MapModelRoomList);
        return(MapModelRoomList);
    }
Exemplo n.º 19
0
 public ModelDoor(ModelRoom room)
 {
     this.room = room;
 }
Exemplo n.º 20
0
    public void createDoors(ModelRoom destination)
    {
        ModelDoor door  = new ModelDoor(this);
        ModelDoor door1 = new ModelDoor(destination, door);

        door.setDestination(door1);

        if (topNeighbours.Contains(destination))
        {
            int startRangePosition = Mathf.Max(this.leftX, destination.leftX) + 1;
            int endRangePosition   = Mathf.Min(this.rightX, destination.rightX) - doorSize;
            if (startRangePosition > endRangePosition)
            {
                Debug.Log("1Error: Drzwi sie nie zmiescioly " + index + " dop " + destination.index);
                return;
            }
            int startPosition = startRangePosition + Random.Range(0, endRangePosition - startRangePosition);
            door.setPosition(new Vector2(startPosition, topY), new Vector2(startPosition + doorSize - 1, topY));
            door1.setPosition(new Vector2(startPosition, topY + 1), new Vector2(startPosition + doorSize - 1, topY + 1));
            this.doors.Add(door);
            destination.doors.Add(door1);
            return;
        }


        if (bottomNeighbours.Contains(destination))
        {
            int startRangePosition = Mathf.Max(this.leftX, destination.leftX) + 1;
            int endRangePosition   = Mathf.Min(this.rightX, destination.rightX) - doorSize;
            if (startRangePosition > endRangePosition)
            {
                Debug.Log("2Error: Drzwi sie nie zmiescioly " + index + " dop " + destination.index);
                return;
            }
            int startPosition = startRangePosition + Random.Range(0, endRangePosition - startRangePosition);
            door.setPosition(new Vector2(startPosition, bottomY), new Vector2(startPosition + doorSize - 1, bottomY));
            door1.setPosition(new Vector2(startPosition, bottomY - 1), new Vector2(startPosition + doorSize - 1, bottomY - 1));
            this.doors.Add(door);
            destination.doors.Add(door1);
            return;
        }

        if (rightNeighbours.Contains(destination))
        {
            int startRangePosition = Mathf.Max(this.bottomY, destination.bottomY) + 1;
            int endRangePosition   = Mathf.Min(this.topY, destination.topY) - doorSize;
            if (startRangePosition > endRangePosition)
            {
                Debug.Log("3Error: Drzwi sie nie zmiescioly " + index + " dop " + destination.index);
                return;
            }
            int startPosition = startRangePosition + Random.Range(0, endRangePosition - startRangePosition);
            door.setPosition(new Vector2(rightX, startPosition), new Vector2(rightX, startPosition + doorSize - 1));
            door1.setPosition(new Vector2(rightX + 1, startPosition), new Vector2(rightX + 1, startPosition + doorSize - 1));
            this.doors.Add(door);
            destination.doors.Add(door1);
            return;
        }


        if (leftNeighbours.Contains(destination))
        {
            int startRangePosition = Mathf.Max(this.bottomY, destination.bottomY) + 1;
            int endRangePosition   = Mathf.Min(this.topY, destination.topY) - doorSize;
            if (startRangePosition > endRangePosition)
            {
                Debug.Log("4Error: Drzwi sie nie zmiescioly " + index + " dop " + destination.index);
                return;
            }
            int startPosition = startRangePosition + Random.Range(0, endRangePosition - startRangePosition);
            door.setPosition(new Vector2(leftX, startPosition), new Vector2(leftX, startPosition + doorSize - 1));
            door1.setPosition(new Vector2(leftX - 1, startPosition), new Vector2(leftX - 1, startPosition + doorSize - 1));
            this.doors.Add(door);
            destination.doors.Add(door1);
            return;
        }
        Debug.Log("cos jest nie tak");
    }
Exemplo n.º 21
0
 public ModelDoor(ModelRoom room, ModelDoor destination)
 {
     this.room        = room;
     this.destination = destination;
 }
Exemplo n.º 22
0
    public override void Test()
    {
        RoomSourceSelection selection = new RoomSourceSelection();

        selection.EEventSelectionChanged += EventSelectionChanged;

        // test that no subscription occurs for room/source after 200ms
        selection.SetPendingRoom(-1, null);
        Thread.Sleep(100);
        TEST(iNumEventsReceived == 0);    // after 100ms no event should have occured
        Thread.Sleep(150);
        TEST(iNumEventsReceived == 0);    // after 250ms no event should have occured

        selection.SetPendingSource(-1, null, true);
        Thread.Sleep(100);
        TEST(iNumEventsReceived == 0);    // after 100ms no event should have occured
        Thread.Sleep(150);
        TEST(iNumEventsReceived == 0);    // after 250ms no event should have occured

        ModelRoom room = new ModelRoom("TestRoom");

        // test that a subscription occurs for room/source after 200ms
        selection.SetPendingRoom(0, room);
        Thread.Sleep(100);
        TEST(iNumEventsReceived == 0);    // after 100ms no event should have occured
        Thread.Sleep(200);
        TEST(iNumEventsReceived == 1);    // after 250ms 1 event should have occured
        iNumEventsReceived = 0;
        int             roomIndex       = -1;
        ModelRoom       modelRoom       = null;
        int             sourceIndex     = -1;
        ModelRoomSource modelRoomSource = null;

        selection.GetRoomAndSource(ref roomIndex, ref modelRoom, ref sourceIndex, ref modelRoomSource);
        TEST(roomIndex == 0);
        TEST(modelRoom == room);
        TEST(sourceIndex == -1);
        TEST(modelRoomSource == null);
        ModelRoomSource source      = new ModelRoomSource();
        ModelDevice     modelDevice = new ModelDevice("TestRoom", "TestSource", "Auxiliary");

        source.ModelAuxiliarySource           = new ModelDeviceSourceAuxiliary(modelDevice);
        source.ModelAuxiliarySource.ModelRoom = room;
        selection.SetPendingSource(1, source, true);
        Thread.Sleep(100);
        TEST(iNumEventsReceived == 0);    // after 100ms no event should have occured
        Thread.Sleep(200);
        TEST(iNumEventsReceived == 1);    // after 250ms 1 event should have occured
        iNumEventsReceived = 0;
        selection.GetRoomAndSource(ref roomIndex, ref modelRoom, ref sourceIndex, ref modelRoomSource);
        TEST(roomIndex == 0);
        TEST(modelRoom == room);
        TEST(sourceIndex == 1);
        TEST(modelRoomSource == source);

        // unsubscribe from source
        selection.SetPendingSource(-1, null, true);
        Thread.Sleep(250);
        TEST(iNumEventsReceived == 1);    // after 250ms 1 event should have occured
        iNumEventsReceived = 0;
        selection.GetRoomAndSource(ref roomIndex, ref modelRoom, ref sourceIndex, ref modelRoomSource);
        TEST(roomIndex == 0);
        TEST(modelRoom == room);
        TEST(sourceIndex == -1);
        TEST(modelRoomSource == null);

        // unsubscribe from room when subscribed to room and source
        selection.SetPendingSource(1, source, true);
        Thread.Sleep(250);
        selection.SetPendingRoom(-1, null);
        Thread.Sleep(250);
        TEST(iNumEventsReceived == 2);    // after 500ms 2 events should have occured
        iNumEventsReceived = 0;
        selection.GetRoomAndSource(ref roomIndex, ref modelRoom, ref sourceIndex, ref modelRoomSource);
        TEST(roomIndex == -1);
        TEST(modelRoom == null);
        TEST(sourceIndex == -1);
        TEST(modelRoomSource == null);
    }