Пример #1
0
 public Fence(Flower _f1, Flower _f2)
 {
     f1 = _f1;
     f2 = _f2;
     int length = (int)Math.Sqrt((f1.position.X - f2.position.X) * (f1.position.X - f2.position.X) +
         (f1.position.Y - f2.position.Y) * (f1.position.Y - f2.position.Y));
     position = f1.center;
     color = Color.White;
     angle = (float)GetAngleOfLineBetweenTwoPoints(f1.center, f2.center);
 }
Пример #2
0
        public Fence(Flower _f1, Flower _f2, string _textureAsset)
        {
            f1 = _f1;
            f2 = _f2;

            textureAsset = _textureAsset;
            color = Color.White;

            CalculateCoordinates();
        }
Пример #3
0
 /// <summary>
 /// Funkcja pomocnicza do tworzenia listy wierzcholkow
 /// </summary>
 /// <param name="n">liczba wierzcholkow</param>
 /// <param name="center">vector centrum polozenia grafu</param>
 /// <param name="R">promien kola na ktorym polozony jest graf</param>
 /// <param name="content">menadzer zawartosci</param>
 /// <returns></returns>
 public static List<Flower> CreateflowerList(int n, Vector2 center, int R, ContentManager content)
 {
     List<Flower> flowers = new List<Flower>();
     Texture2D flowerTexture = content.Load<Texture2D>("Kwiatek");
     float angle =(float)(2 * Math.PI / n);
     for (int i = 0; i < n;i++ )
     {
         Flower f = new Flower(GetCoordinates(center, R, i * angle), "Kwiatek", i);
         flowers.Add(f);
     }
     return flowers;
 }
Пример #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;
                        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;

                    }
                }

            }
        }
Пример #5
0
 public Fence(Flower _f1, Flower _f2, string _textureAsset)
 {
     f1 = _f1;
     f2 = _f2;
     int length = (int)Math.Sqrt((f1.position.X - f2.position.X) * (f1.position.X - f2.position.X) +
         (f1.position.Y - f2.position.Y) * (f1.position.Y - f2.position.Y));
     textureAsset = _textureAsset;
     Texture2D originalTexture = Globals.content.Load<Texture2D>(textureAsset);
     Rectangle sourceRectangle = new Rectangle(0, 0, length, originalTexture.Height);
     texture = new Texture2D(originalTexture.GraphicsDevice, sourceRectangle.Width, sourceRectangle.Height);
     Color[] data = new Color[sourceRectangle.Width * sourceRectangle.Height];
     originalTexture.GetData(0, sourceRectangle, data, 0, data.Length);
     texture.SetData(data);
     position = f1.center;
     color = Color.White;
     angle = (float)GetAngleOfLineBetweenTwoPoints(f1.center, f2.center);
 }
Пример #6
0
        private bool AreFlowersConnected(Flower f1, Flower f2, GardenGraph graph)
        {
            foreach (Fence fence in graph.fences)
                if ((fence.f1.Equals(f1) && fence.f2.Equals(f2)) || (fence.f1.Equals(f2) && fence.f2.Equals(f1)))
                    return true;

            return false;
        }
Пример #7
0
        /// <summary>
        /// Funckja zwracajaca plotki wychodzace z kwiatka
        /// </summary>
        /// <param name="flower">kwiatek</param>
        /// <returns>lista z plotkami</returns>
        public List<Fence> GetOutFences(Flower flower)
        {
            List<Fence> outFences = new List<Fence>();

            foreach(Fence fence in fences)
            {
                if (fence.f1.Equals(flower) || fence.f2.Equals(flower))
                    outFences.Add(fence);
            }

            return outFences;
        }
Пример #8
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;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #9
0
 public void FlowerContainsTest2()
 {
     Flower f = new Flower(new Vector2(0, 0), 0);
     Point mp = new Point(250, 250);
     bool result = f.ContainsPoint(mp);
     Assert.AreEqual(false, result);
 }
Пример #10
0
 public void FlowerContainsTest1()
 {
     Flower f = new Flower(new Vector2(0, 0), 0);
     Point mp = new Point(5, 5);
     bool result = f.ContainsPoint(mp);
     Assert.AreEqual(true, result);
 }
Пример #11
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);
 }
Пример #12
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);
 }