Exemplo n.º 1
0
 public GraphNode(Fields f, int[] Ip)
 {
     this.graphics = f.graphics;
     this.spriteBatch = f.spriteBatch;
     this.ip = Ip;
     fields = f;
 }
Exemplo n.º 2
0
        public Link(Fields f, int Mag, int Dist)
        {
            Magnitude = Mag;
            Distance = Dist;

            LinkTexture = new Texture2D(f.graphics, 1, 1, false, SurfaceFormat.Color);
            LinkTexture.SetData(new[] { particleColor });
            direction = startPosition - endPosition;
            direction.Normalize();
            pixelsPerMove.X = MathHelper.Distance(startPosition.X, endPosition.X);
            pixelsPerMove.Y = MathHelper.Distance(startPosition.Y, endPosition.Y);
        }
Exemplo n.º 3
0
 public Network(Fields x)
 {
     xnaStuff = x;
 }
Exemplo n.º 4
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.º 5
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;
        }