public Node AddNewNode()
        {
            Node node = new Node (this);
            lock (_Nodes) {
                int index = _Random.Next (0, _Nodes.Count + 1);
                _Nodes.Insert (index, node);
            }

            SetNodePositions ();

            return node;
        }
Esempio n. 2
0
        public Packet(Node sender, Node receiver, int pieceId)
        {
            _Sender = sender;
            _Receiver = receiver;
            _PieceId = pieceId;

            var x = _Sender.PositionX;
            var y = _Sender.PositionY;

            for (int i = 0; i < PartsPerPiece; i++) {
                _Tail = new PacketTail (
                    this,
                    0.3 + 0.3 * _R.NextDouble (),
                    _Tail);
            }
        }
Esempio n. 3
0
        public bool RequestPiece(int index, Node target)
        {
            if (!HasPiece (index)) {
                return false;
            }

            if (_StepsUntilReadyToSend > 0) {
                return false;
            }

            _StepsUntilReadyToSend = _SendInterval;

            Packet p = new Packet (this, target, index);
            _NodeManager.AddPacket (p);

            return true;
        }
 public void RemoveNode(Node n = null)
 {
     lock (_Nodes) {
         if (n != null) {
             _Nodes.Remove (n);
         }
         else {
             _Nodes.RemoveAt (0);
         }
     }
 }