Exemplo n.º 1
0
        public void addNeighbour(Node newNeighbour)
        {
            nS newN=new nS();
            newN.neighbor = newNeighbour;
            newN.timer = 1;
            neighboursNodes.Add(newN);

            PrimitiveLine tempLine = new PrimitiveLine(gd);
            /*
            if (getPosition().X == newNeighbour.getPosition().X)
            {
                tempLine.AddVector(getPosition() + new Vector2(5, 0));
                tempLine.AddVector(newNeighbour.getPosition());

                tempLine.AddVector(getPosition() + new Vector2(-5, 0));
                tempLine.AddVector(newNeighbour.getPosition());
            }
            else
            {

                tempLine.AddVector(getPosition()+new Vector2(0,5));
                tempLine.AddVector(newNeighbour.getPosition());

                tempLine.AddVector(getPosition() + new Vector2(0, -5));
                tempLine.AddVector(newNeighbour.getPosition());
            }*/

            //Simple line
            tempLine.AddVector(getPosition());
            tempLine.AddVector(newNeighbour.getPosition());

            neighbours.Add(tempLine);
        }
Exemplo n.º 2
0
 public packet(SpriteBatch initSB, Texture2D initTexture, Node nodeA, Node nodeB)
 {
     source = nodeA;
     destination = nodeB;
     position = nodeA.getPosition();
     sb = initSB;
     pTexture = initTexture;
     Label = "";
 }
Exemplo n.º 3
0
 public packet(SpriteBatch initSB, Texture2D initTexture, Node nodeA, Node nodeB,string newLabel, SpriteFont fnt)
 {
     source = nodeA;
     destination = nodeB;
     position = nodeA.getPosition();
     sb = initSB;
     pTexture = initTexture;
     Label = newLabel;
     myFnt = fnt;
 }
Exemplo n.º 4
0
        private void processCommand(string command)
        {
            if (command == "")
            {
                return;
            }

             lastMessage = command;

            string[] args = command.Split(' ');
            switch (args[0])
            {
                case "setBadge":
                    if (args.Count() > 2)
                    {
                        int existsID = findNodeByhexID(args[1]);
                        if (existsID > 0)
                        {
                            int c = args.Count() - 1;

                            string badgeNumber = args[2];
                            string finalInfo = "";
                            for (int i = 3; i <= c; i++)
                            {
                                finalInfo += args[i] + " ";
                            }

                            if (badgeNumber == "1")
                            {
                                nodes[existsID - 1].setBadge1(finalInfo);
                            }
                            else
                                if (badgeNumber == "2")
                                {
                                    nodes[existsID - 1].setBadge2(finalInfo);
                                }

                        }
                    }
                    break;

                case "setText":
                    if (args.Count() > 2)
                    {
                        int existsID = findNodeByhexID(args[1]);
                        if (existsID > 0)
                        {
                            int c=args.Count()-1;

                            string finalInfo="";
                            for (int i=2;i<=c;i++)
                            {
                                finalInfo+=args[i]+" ";
                            }
                            nodes[existsID - 1].setInfo(finalInfo);
                        }
                    }
                    break;
                case "clear":

                    nodes.Clear();
                    packets.Clear();

                    break;
                case "heartBeat":
                    if (args.Count() > 1)
                    if (args[1]!="0")
                    {
                        int existsID = findNodeByhexID(args[1]);

                        if (existsID > 0)
                        {

                            if (args.Count() >= 3)
                            {
                                try
                                {
                                    nodes[existsID - 1].setPosition(new Vector2((float)Convert.ToDouble(args[2], CultureInfo.InvariantCulture.NumberFormat) * screenWidth - nodeTexture.Width / 2.0f, (float)Convert.ToDouble(args[3], CultureInfo.InvariantCulture.NumberFormat) * screenHeight - nodeTexture.Height / 2.0f));
                                    foreach (Node n in nodes)
                                    {
                                        n.clearNeighboursLines();
                                        n.updateNeighbours();
                                    }

                                }
                                catch
                                {
                                    //setStatus("Error in command arguments");
                                }
                            }

                            nodes[existsID - 1].heartBeat();
                        }
                        else
                        {
                            if (args.Count() >= 3)
                            {
                                Node new_node = new Node(spriteBatch,nodeTexture,Vector2.Zero);

                                try
                                {
                                    new_node.setPosition(new Vector2((float)Convert.ToDouble(args[2], CultureInfo.InvariantCulture.NumberFormat) * screenWidth - nodeTexture.Width / 2.0f, (float)Convert.ToDouble(args[3], CultureInfo.InvariantCulture.NumberFormat) * screenHeight - nodeTexture.Height / 2.0f));
                                    //new_node.setPosition((float)Convert.ToDouble(args[2]), (float)Convert.ToDouble(args[3]));
                                    new_node.setID(lastID);
                                    new_node.setHexID(args[1]);
                                    new_node.setInfoFont(sf);
                                    new_node.setInfo(args[1]);
                                    new_node.setGraphicsDevice(GraphicsDevice);
                                    new_node.setColor(Color.Black);
                                    lastID++;
                                    nodes.Add(new_node);
                                }
                                catch
                                {
                                    //setStatus("Error in command arguments");
                                }
                            }
                        }
                    }

                    break;
                case "changeColor":
                    if (args.Count() > 4)
                    {
                        int existsID = findNodeByhexID(args[1]);

                        if (existsID > 0)
                        {
                            nodes[existsID - 1].setColor(new Color((float)Convert.ToDouble(args[2], CultureInfo.InvariantCulture.NumberFormat) / 255f, (float)Convert.ToDouble(args[3], CultureInfo.InvariantCulture.NumberFormat) / 255f, (float)Convert.ToDouble(args[4], CultureInfo.InvariantCulture.NumberFormat) / 255f));
                            //mustUpdateDisplays = true;
                        }

                    }

                    break;
                case "activateNode":
                    if (args.Count() > 1)
                    {
                        int existsID = findNodeByhexID(args[1]);

                        if (existsID > 0)
                        {
                            nodes[existsID - 1].enable();

                        }
                    }
                    break;
                case "disactivateNode":
                    if (args.Count() > 1)
                    {
                        int existsID = findNodeByhexID(args[1]);

                        if (existsID > 0)
                        {
                            nodes[existsID - 1].disable();

                        }
                    }
                    break;
                case "sendPacket":
                    if (args.Count() > 2)
                    {
                        int source = findNodeByhexID(args[1]);
                        int destination = findNodeByhexID(args[2]);

                        if (source > 0 && destination > 0 && source!=destination && source<=nodes.Count && destination<=nodes.Count)
                        if (nodes[destination-1].isEnabled())
                        {
                            packet pckt;
                            if (args.Count() >3)
                            {
                                pckt = new packet(spriteBatch, packetTexture, nodes[source - 1], nodes[destination - 1],args[3],sf);
                            }
                            else
                            {
                                pckt = new packet(spriteBatch, packetTexture, nodes[source - 1], nodes[destination - 1]);
                            }
                            packets.Add(pckt);
                            //commandsBuffer.Add("addNeighbor " + args[1] + " " + args[2]);

                        }
                    }
                    break;
                case "resetNeighbors":
                    if (args.Count() > 1)
                    {
                        int existsID = findNodeByhexID(args[1]);

                        if (existsID > 0)
                        {
                            nodes[existsID - 1].clearNeighbours();
                        }
                    }
                    break;
                case "addNeighbor":
                    if (args.Count() > 2)
                    {
                        int source = findNodeByhexID(args[1]);
                        int destination = findNodeByhexID(args[2]);
                        if (source > 0 && destination > 0)
                        {
                            nodes[source - 1].addNeighbour(nodes[destination - 1]);
                        }
                    }
                    break;
            }
        }