Exemplo n.º 1
0
 public void addEdge(GraphNode Neighbor1, GraphNode Neighbor2, int Distance, int Magnitude)
 {
     Line newLink = new Line(findNode(Neighbor1), findNode(Neighbor2), xnaStuff);
        findNode(Neighbor1).Edges.Add(newLink);
        findNode(Neighbor2).Edges.Add(newLink);
 }
Exemplo n.º 2
0
        public void addNode(GraphNode Neighbor, GraphNode node, int Distance, int Magnitude)
        {
            if (Neighbor != null)
            {
                GraphList.Add(node);
             Line newLink = new Line(findNode(Neighbor), node, xnaStuff);
             newLink.setDistance(Distance);
             newLink.setMagnitude(Magnitude);
               findNode(Neighbor).Edges.Add(newLink);
               findNode(node).Edges.Add(newLink);

            }
               else if (Count == 0)
               {
               GraphList.Add(node);
               }
        }
Exemplo n.º 3
0
 public GraphNode findNode(GraphNode Neighbor)
 {
     return GraphList.Find(x => x.IP == Neighbor.IP);
 }
Exemplo n.º 4
0
        public void Update(GameTime gameTime)
        {
            bool update = false;

               foreach (GraphNode a in GraphList)
               {
               if (node.Equals(a))
                   {
                       label.Text = a.ToString();

                   }
               if (Mouse.GetState().LeftButton == ButtonState.Pressed)
               {

                   if (new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1).Intersects(a.picturePosition))
                   {
                       label.Text = a.ToString();
                       update = true;
                       node = a;

                   }
               }
            a.Update(gameTime);

               }
        }
Exemplo n.º 5
0
 public void createLabel(SpriteFont font, SpriteBatch batch)
 {
     label = new Label(font, "", new Vector2(10, 200),Color.White, 1);
        spriteBatch = batch;
        node = GraphList[0];
 }
Exemplo n.º 6
0
 public void addLine(GraphNode endPoint)
 {
     Line line = new Line(this, endPoint, fields);
     edges.Add(line);
     endPoint.edges.Add(line);
 }
Exemplo n.º 7
0
        public Line(GraphNode Neighbor1, GraphNode Neighbor2, Fields f)
        {
            NeighborOne = Neighbor1;
            NeighborTwo = Neighbor2;

            spriteBatch = f.spriteBatch;

            fields = f;
            double distance = Math.Sqrt(Math.Pow((Neighbor2.picturePosition.Center.X -
                                                Neighbor1.picturePosition.Center.X), 2) +
                                                Math.Pow((Neighbor2.picturePosition.Center.Y -
                                                Neighbor1.picturePosition.Center.Y), 2));

            outgoing = new Link(f, 0, (int)distance);
            outgoing.endNode = Neighbor2;
            ingoing = new Link(f, 0, (int)distance);
            ingoing.endNode = Neighbor1;

            if (Neighbor2.picturePosition.X > Neighbor1.picturePosition.X && Neighbor2.picturePosition.Y < Neighbor1.picturePosition.Y)
            {
                outgoing.endPosition = new Vector2(Neighbor2.picturePosition.Center.X - (Neighbor2.picturePosition.Width / 2), Neighbor2.picturePosition.Center.Y);
                outgoing.startPosition = new Vector2(Neighbor1.picturePosition.Center.X, Neighbor1.picturePosition.Center.Y - (Neighbor1.picturePosition.Width / 2));

                ingoing.endPosition = new Vector2(Neighbor2.picturePosition.Center.X, Neighbor2.picturePosition.Center.Y + (Neighbor2.picturePosition.Width / 2));
                ingoing.startPosition = new Vector2(Neighbor1.picturePosition.Center.X + (Neighbor1.picturePosition.Width / 2), Neighbor1.picturePosition.Center.Y);
            }
            else if (Neighbor2.picturePosition.X < Neighbor1.picturePosition.X && Neighbor2.picturePosition.Y < Neighbor1.picturePosition.Y)
            {
                outgoing.endPosition = new Vector2(Neighbor2.picturePosition.Center.X, Neighbor2.picturePosition.Center.Y + (Neighbor2.picturePosition.Width / 2));
                outgoing.startPosition = new Vector2(Neighbor1.picturePosition.Center.X - (Neighbor1.picturePosition.Width / 2), Neighbor1.picturePosition.Center.Y);

                ingoing.endPosition = new Vector2(Neighbor2.picturePosition.Center.X, Neighbor2.picturePosition.Center.Y - (Neighbor2.picturePosition.Width / 2));
                ingoing.startPosition = new Vector2(Neighbor1.picturePosition.Center.X + (Neighbor1.picturePosition.Width / 2), Neighbor1.picturePosition.Center.Y);
            }

            if (Neighbor2.picturePosition.X > Neighbor1.picturePosition.X && Neighbor2.picturePosition.Y > Neighbor1.picturePosition.Y)
            {
                outgoing.endPosition = new Vector2(Neighbor2.picturePosition.Center.X, Neighbor2.picturePosition.Center.Y - (Neighbor2.picturePosition.Width / 2));
                outgoing.startPosition = new Vector2(Neighbor1.picturePosition.Center.X + (Neighbor1.picturePosition.Width / 2), Neighbor1.picturePosition.Center.Y);

                ingoing.endPosition = new Vector2(Neighbor2.picturePosition.Center.X - (Neighbor2.picturePosition.Width / 2), Neighbor2.picturePosition.Center.Y);
                ingoing.startPosition = new Vector2(Neighbor1.picturePosition.Center.X, Neighbor1.picturePosition.Center.Y + (Neighbor1.picturePosition.Width / 2));
            }

            if (Neighbor2.picturePosition.X < Neighbor1.picturePosition.X && Neighbor2.picturePosition.Y > Neighbor1.picturePosition.Y)
            {
                outgoing.endPosition = new Vector2(Neighbor2.picturePosition.Center.X, Neighbor2.picturePosition.Center.Y - (Neighbor2.picturePosition.Width / 2));
                outgoing.startPosition = new Vector2(Neighbor1.picturePosition.Center.X - (Neighbor1.picturePosition.Width / 2), Neighbor1.picturePosition.Center.Y);

                ingoing.endPosition = new Vector2(Neighbor2.picturePosition.Center.X + (Neighbor2.picturePosition.Width / 2), Neighbor2.picturePosition.Center.Y);
                ingoing.startPosition = new Vector2(Neighbor1.picturePosition.Center.X, Neighbor1.picturePosition.Center.Y + (Neighbor1.picturePosition.Width / 2));
            }
            if (Neighbor2.picturePosition.X < Neighbor1.picturePosition.X && Neighbor2.picturePosition.Y < Neighbor1.picturePosition.Y)
            {
                outgoing.endPosition = new Vector2(Neighbor2.picturePosition.Center.X, Neighbor2.picturePosition.Center.Y + (Neighbor2.picturePosition.Width / 2));
                outgoing.startPosition = new Vector2(Neighbor1.picturePosition.Center.X - (Neighbor1.picturePosition.Width / 2), Neighbor1.picturePosition.Center.Y);

                ingoing.endPosition = new Vector2(Neighbor2.picturePosition.Center.X + (Neighbor2.picturePosition.Width / 2), Neighbor2.picturePosition.Center.Y);
                ingoing.startPosition = new Vector2(Neighbor1.picturePosition.Center.X, Neighbor1.picturePosition.Center.Y - (Neighbor1.picturePosition.Width / 2));
            }
            //outgoing.endPosition = new Vector2(endNode.picturePosition.Center.X, endNode.picturePosition.Center.Y);
            //outgoing.startPosition = new Vector2(startNode.picturePosition.Center.Y, startNode.picturePosition.Center.X);
        }
Exemplo n.º 8
0
        public void send(Packet p, GraphNode startNode)
        {
            if (startNode.Equals(NeighborOne))
            {
                p.OnLine = true;
                outgoing.transmit(p);
                outgoing.finished = false;

            }
            else
            {
                p.OnLine = true;
                ingoing.transmit(p);
                ingoing.finished = false;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            font = this.Content.Load<SpriteFont>("Arial");
            fields = new Fields(spriteBatch, graphics);
            int[] a = new int[] { 1, 2, 3 };
            int[] b = new int[] { 4, 5, 6 };
            int[] c = new int[] { 7, 8, 9 };
            int[] d = new int[] { 10, 11, 12 };
            int[] e = new int[] { 13, 14, 15 };
            int[] f = new int[] { 16, 17, 18 };
            node = new GraphNode(fields, a);
            node2 = new GraphNode(fields, b);
            node3 = new GraphNode(fields, c);
            node4 = new GraphNode(fields, d);
            node5 = new GraphNode(fields, f);
            nodeImage = this.Content.Load<Texture2D>("Node");
            node.addText(font, "1");
            node.loadImage(nodeImage, new Rectangle(100, 100, 50, 50));

            node2.loadImage(nodeImage, new Rectangle(640, 200, 50, 50));
            node2.addText(font, "2");
            node3.loadImage(nodeImage, new Rectangle(500, 101, 50, 50));
            node3.addText(font, "3");
            node4.loadImage(nodeImage, new Rectangle(60, 300, 50, 50));
            node4.addText(font, "4");
            node5.loadImage(nodeImage, new Rectangle(501, 301, 50, 50));
            node5.addText(font, "5");

            // TODO: use this.Content to load your game content here

            graphNetwork = new Network(fields);
            graphNetwork.addNode(null, node, 200, 150);
            graphNetwork.addNode(node, node3, 200, 150);
            graphNetwork.addNode(node3, node5, 200, 150);
            graphNetwork.addNode(node, node4, 200, 150);

            graphNetwork.addNode(node3, node2, 200, 150);

            graphNetwork.addEdge(node5, node2, 200, 150);
            graphNetwork.addEdge(node5, node4, 200, 150);
            graphNetwork.addEdge(node5, node, 200, 150);
            for (int i = 0; i < 19; i++)
            {
                graphNetwork.findNode(node5).outgoing.Enqueue(new Packet(123, node.IP, node4.IP, this.Content.Load<Texture2D>("Packet"))

                {
                });

            }
            ap = new Packet(123, node.IP, node4.IP, this.Content.Load<Texture2D>("Packet"));
             ap.packetParticle = this.Content.Load<Texture2D>("Packet");
             graphNetwork.findNode(node).outgoing.Enqueue(ap);
             graphNetwork.createLabel(font, spriteBatch);
             IsMouseVisible = true;
        }