Exemplo n.º 1
0
        /// <summary>
        /// Pomocnicza funckcja kopiujaca graf
        /// </summary>
        /// <returns>skopiowany graf</returns>
        public GardenGraph Copy()
        {
            List<Flower> copyFlowers = new List<Flower>();
            List<Fence> copyFences = new List<Fence>();

            foreach(Flower flower in flowers)
                copyFlowers.Add(flower.Copy());

            foreach(Fence fence in fences)
            {
                Fence copyFence = new Fence(copyFlowers[fence.f1.index],
                    copyFlowers[fence.f2.index], "Plotek");

                copyFences.Add(copyFence);
            }

            return new GardenGraph(copyFlowers, copyFences);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Funkcja sprawdzajaca nacisk myszy na element okna Kreatora grafu
        /// </summary>
        /// <param name="mousePos"></param>
        /// <param name="pi"></param>
        /// <param name="content"></param>
        public void CheckGraphCreator(Point mousePos, PlayerInterface pi, ContentManager content)
        {
            int index = GetIndex(GCButtons, mousePos);
            List<Fence> outFences;
            if (index > -1)
            {
                switch (GCButtons[index].name)
                {
                    case "anuluj":
                        pi.state = InterfaceState.MainMenu;
                        break;
                    case "zapisz-graf":
                        DateTime now = DateTime.Now;
                        SerializationManager.SerializeObject(graph, String.Format("{0}-{1}-{2}-{3}-{4}-{5}.xml", now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second));
                        pi.state = InterfaceState.MainMenu;
                        break;
                }
            }

            for(int i =0;i<VerticesNr;i++)
            {
                if(graph.flowers[i].ContainsPoint(mousePos))
                {
                    if(lastClicked==null)
                    {
                        lastClicked = graph.flowers[i];
                        lastClicked.color = Color.LightBlue;
                    }
                    else
                    {
                        if (graph.flowers[i] != lastClicked)
                        {
                            Fence f = new Fence(lastClicked, graph.flowers[i], "Plotek");

                            outFences = graph.GetOutFences(lastClicked);
                            if (!outFences.Exists(x => (x.f1.Equals(lastClicked) && x.f2.Equals(graph.flowers[i])) || (x.f1.Equals(graph.flowers[i]) && x.f2.Equals(lastClicked))))
                            {
                                outFences.Add(f);
                                graph.fences.Add(f);
                                graph.fencesNumber += 1;
                            }
                        }
                        lastClicked.color = Color.White;
                        lastClicked = null;

                    }
                }

            }
        }
Exemplo n.º 3
0
        private bool AreFencesConnected(Fence f1, Fence f2)
        {
            if (f1.f1.Equals(f2.f1) || f1.f1.Equals(f2.f2) || f1.f2.Equals(f2.f1) || f1.f2.Equals(f2.f2))
                return true;

            return false;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Funkcja sprawdzajaca nacisk myszy na element okna Kreatora grafu
        /// </summary>
        /// <param name="mousePos"></param>
        /// <param name="pi"></param>
        /// <param name="content"></param>
        public void CheckGraphCreator(Point mousePos, PlayerInterface pi, ContentManager content)
        {
            int index = GetIndex(GCButtons, mousePos);
            List<Fence> outFences;
            if (index > -1)
            {
                switch (GCButtons[index].name)
                {
                    case "anuluj":
                        pi.state = InterfaceState.MainMenu;
                        break;
                    case "zapisz-graf":
                        DateTime now = DateTime.Now;
                        PrepareGraphForSerialization();
                        SerializationManager.SerializeObject(graph, SerializationManager.CreateFileName(now));
                        pi.state = InterfaceState.MainMenu;
                        break;
                    case "usun":
                        if(GCButtons[index].color == Color.White)
                        {
                            if (lastClicked is Fence)
                            {
                                graph.fences.Remove((Fence)lastClicked);
                                graph.fencesNumber--;
                            }
                            else if(lastClicked is Flower)
                            {
                                outFences = graph.GetOutFences((Flower)lastClicked);
                                if (outFences.Count > 0)
                                    Game1.MessageBox(new IntPtr(), "Najpierw usuń wychodzące krawędzie", "", 0);
                                else
                                {
                                    graph.flowers.Remove((Flower)lastClicked);
                                    graph.flowersNumber--;
                                }
                            }

                            GCButtons[index].color = Color.Gray;
                            lastClicked.color = Color.White;
                            lastClicked = null;
                            GCButtons[3].color = Color.White;
                            return;
                        }
                        break;
                    case "dodaj-kwiatek":
                        if (GCButtons[index].color == Color.White)
                        {
                            List<int> indices = new List<int>();
                            foreach(Flower f in graph.flowers)
                            {
                                indices.Add(f.index);
                            }
                            indices.Sort();

                            int previous_index = -1;
                            int flower_index = graph.flowersNumber;
                            foreach(int ind in indices)
                            {
                                if(ind - previous_index > 1)
                                {
                                    flower_index = previous_index + 1;
                                    break;
                                }
                                previous_index = ind;
                            }

                            Flower flower = new Flower(Game1.GetRatioDimensions(new Vector2(0, 390)), "Kwiatek", flower_index);
                            graph.flowers.Add(flower);
                            graph.flowersNumber++;
                            return;
                        }
                        break;
                }
            }

            if (!(lastClicked is Fence))
            {
                for (int i = 0; i < graph.flowersNumber; i++)
                {
                    if (graph.flowers[i].ContainsPoint(mousePos))
                    {
                        if (lastClicked == null)
                        {
                            lastClicked = graph.flowers[i];
                            lastClicked.color = Color.LightBlue;
                            movingFlower = true;
                            GCButtons[2].color = Color.White;
                            GCButtons[3].color = Color.Gray;
                            break;
                        }
                        else if (!movingFlower)
                        {
                            if (graph.flowers[i] != lastClicked)
                            {
                                Fence f = new Fence((Flower)lastClicked, graph.flowers[i], "Plotek");

                                outFences = graph.GetOutFences((Flower)lastClicked);
                                if (!outFences.Exists(x => (x.f1.Equals(lastClicked) && x.f2.Equals(graph.flowers[i])) || (x.f1.Equals(graph.flowers[i]) && x.f2.Equals(lastClicked))))
                                {
                                    graph.fences.Add(f);
                                    graph.fencesNumber += 1;
                                }
                            }
                            lastClicked.color = Color.White;
                            lastClicked = null;
                            GCButtons[2].color = Color.Gray;
                            GCButtons[3].color = Color.White;
                            return;
                        }
                    }
                }
            }

            if (movingFlower)
            {
                if (previousMousePosition != Vector2.Zero)
                {
                    ((Flower)lastClicked).position.X -= previousMousePosition.X - mousePos.X;
                    ((Flower)lastClicked).position.Y -= previousMousePosition.Y - mousePos.Y;

                    ((Flower)lastClicked).center.X -= previousMousePosition.X - mousePos.X;
                    ((Flower)lastClicked).center.Y -= previousMousePosition.Y - mousePos.Y;
                }

                previousMousePosition = new Vector2(mousePos.X, mousePos.Y);
            }
            else
            {
                if (lastClicked == null || lastClicked is Fence)
                {
                    for (int i = 0; i < graph.fencesNumber; i++)
                    {
                        if (graph.fences[i].ContainsPoint(mousePos))
                        {
                            if (lastClicked == null)
                            {
                                lastClicked = graph.fences[i];
                                lastClicked.color = Color.LightBlue;
                                GCButtons[2].color = Color.White;
                                GCButtons[3].color = Color.Gray;
                            }
                            else
                            {
                                if (graph.fences[i] == lastClicked)
                                {
                                    lastClicked.color = Color.White;
                                    lastClicked = null;
                                    GCButtons[2].color = Color.Gray;
                                    GCButtons[3].color = Color.White;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
 public void FenceContainsTest2()
 {
     Flower f1 = new Flower(new Vector2(746, 97), 2);
     Flower f2 = new Flower(new Vector2(453, 97), 3);
     Fence f = new Fence(f1, f2);
     Point mp = new Point(880, 160);
     bool result = f.ContainsPoint(mp);
     Assert.AreEqual(false, result);
 }
Exemplo n.º 6
0
 public void FenceAngleTest()
 {
     Flower f1 = new Flower(new Vector2(0, 0), 0);
     Flower f2 = new Flower(new Vector2(600, 600), 1);
     Fence f = new Fence(f1, f2);
     double angle = f.GetAngleOfLineBetweenTwoPoints(f1.position, f2.position);
     double expected = Math.PI / 4;
     Assert.AreEqual(expected, angle);
 }
Exemplo n.º 7
0
        private bool AreFencesConnected(Fence f1, Fence f2, GardenGraph graph)
        {
            foreach (Fence fence in graph.fences)
                if (f1.f1.Equals(f2.f1) || f1.f1.Equals(f2.f2) || f1.f2.Equals(f2.f1) || f1.f2.Equals(f2.f2))
                    return true;

            return false;
        }