public SensorNetwork(string str1, string str2, string str3)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            this.numNodes=int.Parse(str1);
            this.xmissionRange=float.Parse(str2);
            this.simulationSpeed=int.Parse(str3);
            rnd   = new Random();
            myPen = new Pen(Color.Blue);
            myLine=new Pen(Color.Gray);
            this.totMsgs=0;
            this.headNode=new SensorNode(true,this.xmissionRange,0, this.simulationSpeed);
            this.headRMsg=new ReceivedMessageList();
            this.temp=this.headNode;
            this.tmpRMsg=this.headRMsg;
            this.headMsg=new MessageList();//dummy node got to be present at all times.
            this.tailMsg=new MessageList();//-do-
            this.headMsg.NEXT=this.tailMsg;
            this.numbers=new bool[this.numNodes];
            this.timerFlag=false;
            this.stopperFlag2=false;
            for(int i=0;i<this.numNodes;i++)
            {
                this.tailNode=new SensorNode(false,this.xmissionRange,i+1,this.simulationSpeed);
                this.temp.Next=this.tailNode;
                this.temp=this.temp.Next;
                this.tailRMsg=new ReceivedMessageList();
                this.tmpRMsg.Next=this.tailRMsg;
                this.tmpRMsg=this.tmpRMsg.Next;
            }
        }
        private void timer1_Tick(object sender, System.EventArgs e)
        {
            this.oGraphics = Graphics.FromImage(this.DrawingArea);
            this.temp=this.headNode;
            this.oGraphics.Clear(Color.AliceBlue);
            bool stopperFlag=false;
            for(int i=0;i<this.numNodes;i++)
            {
                this.temp.bitmapUPDater();
                oGraphics.DrawImage(this.temp.IMG,this.temp.PIXEL_NUMBER_X,this.temp.PIXEL_NUMBER_Y,7,7);
                if(this.temp.JOINSTATUS==true)
                {
                    oGraphics.DrawLine(myLine,this.temp.PIXEL_NUMBER_X,this.temp.PIXEL_NUMBER_Y,this.temp.PARENT_PIXEL_NUMBER_X,this.temp.PARENT_PIXEL_NUMBER_Y);//ammend here
                }
                if(this.temp.BATTERY.BATTERYPOWER<=0)
                {
                    this.NetworkStats();
                    stopperFlag=true;
                }
                this.temp=this.temp.Next;
            }
            if(stopperFlag==true && this.stopperFlag2==false)
            {
                this.timer1.Stop();
                this.stopperFlag2=true;
            }
            Random rnd=new Random();
            for(int j=0;j<this.numNodes;j++)
                this.numbers[j]=false;
            for(int j=0;j<this.numNodes;j++)
            {
                int num=0;
                for(int k=0;k<this.numNodes;k++)
                {

                    num=rnd.Next(0,this.numNodes);
                    if(this.numbers[num]==false)
                    {
                        this.numbers[num]=true;
                        break;
                    }
                    else
                        k--;
                }
                this.temp=this.headNode;
                for(int k=0;k<num;k++)
                    this.temp=this.temp.Next;
                float Xsq, Ysq, distSq;
                int msgCount=1;
                this.flag=false;//false for no message received
                this.hiddenNodeFlag=false;//true for no hidden node problem
                int delMsgs=0;
                this.tmpMsg=this.headMsg.NEXT;
                String msg=null;
                for(int k=0;k<this.totMsgs;k++)
                {
                    String [] msgListToks=this.tmpMsg.MESSAGE.Split(';');
                    Xsq=this.temp.MAC_X-float.Parse(msgListToks[0]);
                    Xsq=Xsq*Xsq;
                    Ysq=this.temp.MAC_Y-float.Parse(msgListToks[1]);
            //			msgListToks=null;
                    Ysq=Ysq*Ysq;
                    distSq=Xsq+Ysq;
                    if(this.tmpMsg.ITERATION>=this.numNodes)
                    {
                        MessageList MsgToBeRemoved=this.move_to_Message(msgCount);
                        this.move_to_Message(msgCount-1).NEXT=this.move_to_Message(msgCount+1);
                        this.temp1=this.headNode;
                        for(int m=0;m<this.numNodes;m++)
                        {
                //			if(this.temp.MAC_X!=this.temp1.MAC_X || this.temp.MAC_Y!=this.temp1.MAC_Y)
                //			{
                                Xsq=this.temp1.MAC_X-float.Parse(msgListToks[0]);
                                Xsq=Xsq*Xsq;
                                Ysq=this.temp1.MAC_Y-float.Parse(msgListToks[1]);
                            //	msgListToks=null;
                                Ysq=Ysq*Ysq;
                                distSq=Xsq+Ysq;
                                if((distSq<=this.xmissionRange*this.xmissionRange) )
                                {
                                    SensorNode tmp=this.headNode;
                                    for(int n=0;n<this.numNodes;n++)
                                    {
                                        float x, y, hyp;
                                        x=this.temp1.MAC_X-tmp.MAC_X;
                                        x=x*x;
                                        y=this.temp1.MAC_Y-tmp.MAC_Y;
                                        y=y*y;
                                        hyp=x+y;
                                        if(hyp<=this.xmissionRange*this.xmissionRange)
                                        {
                                            if(tmp.ITERATION>=this.numNodes)
                                            {
                                                this.richTextBox1.Text+="I come here\n";
                                                tmp.NEIGHBOURRECEIVEDXMITTED=false;
                                                tmp.ITERATION=0;
                                            }
                                        }
                                        tmp=tmp.Next;
                                    }
                                    if(this.temp1.ITERATION>=this.numNodes)
                                    {
                                        this.temp1.NEIGHBOURRECEIVEDXMITTED=false;
                                        this.temp1.ITERATION=0;
                                    }
                                }
                            this.temp1=this.temp1.Next;
                        }
                        MsgToBeRemoved=null;
                        delMsgs++;
                        msgCount--;
                    }
                    //the value used for msg deletion
                    else if(distSq<=this.xmissionRange*this.xmissionRange)
                    {
                        this.temp.MessageReceiver(this.tmpMsg.MESSAGE);
                        this.temp1=this.headNode;
                        for(int m=0;m<this.numNodes;m++)
                        {
                //			if((this.temp.MAC_X!=this.temp1.MAC_X || this.temp.MAC_Y!=this.temp1.MAC_Y) && (this.temp1.NEIGHBOURRECEIVEDXMITTED==true))
                //			{
                                Xsq=this.temp.MAC_X-this.temp1.MAC_X;
                                Xsq=Xsq*Xsq;
                                Ysq=this.temp.MAC_Y-this.temp1.MAC_Y;
                                Ysq=Ysq*Ysq;
                                distSq=Xsq+Ysq;
                                if((distSq<=this.xmissionRange*this.xmissionRange) )
                                {
                                    this.temp1.NEIGHBOURRECEIVEDXMITTED=true;//a neighbour has received a message
                                    this.temp1.ITERATION=0;
                                    //								this.richTextBox1.Text+="haan jee\n";
                                }
                //			}
                            this.temp1=this.temp1.Next;
                        }
                        flag=true;//the node received a message
                    }
                    msgCount++;
                    this.tmpMsg=this.tmpMsg.NEXT;
                }
                this.tmpMsg=this.headMsg.NEXT;
                this.tailMsg.ITERATION=0;
                while(this.tmpMsg.NEXT!=null)
                {
                    this.tmpMsg.ITERATION++;
                    this.tmpMsg=this.tmpMsg.NEXT;
                }
                this.tailMsg.ITERATION=0;
                this.temp1=this.headNode;
                for(int i=0;i<this.numNodes;i++)
                {
                    if(this.temp1.NEIGHBOURRECEIVEDXMITTED==true)
                        this.temp1.ITERATION++;
                    if(this.temp1.ITERATION>=this.numNodes)
                    {
                        this.temp1.ITERATION=0;
                        this.temp1.NEIGHBOURRECEIVEDXMITTED=false;
                    }
                    this.temp1=this.temp1.Next;
                }
                //if else with a flag
                if(flag==false)
                {
                    bool xmitterFlag=false;
                    this.temp1=this.headNode;
                    for(int m=0;m<this.numNodes;m++)
                    {
                        if((this.temp1.NEIGHBOURRECEIVEDXMITTED==true))
                        {
                            Xsq=this.temp.MAC_X-this.temp1.MAC_X;
                            Xsq=Xsq*Xsq;
                            Ysq=this.temp.MAC_Y-this.temp1.MAC_Y;
                            Ysq=Ysq*Ysq;
                            distSq=Xsq+Ysq;

                            if((distSq<=this.xmissionRange*this.xmissionRange) )
                            {
                                xmitterFlag=true;//a neighbour has received a message
            //								this.richTextBox1.Text+="haan jee\n";
                            }
                        }
                        this.temp1=this.temp1.Next;
                    }
                    if(xmitterFlag==false)
                    {
                        String str;
                        if((str=this.temp.MessageTransmitter())!=null)
                        {
                            String [] toks=str.Split(';');
                            if(int.Parse(toks[4])==1)
                                myPen.Color=Color.Red;
                            else if(int.Parse(toks[4])==2)
                                myPen.Color=Color.Green;
                            else if(int.Parse(toks[4])==3)
                                myPen.Color=Color.Blue;
                            else
                                myPen.Color=Color.Purple;
                            MessageList NewMsg=new MessageList();
                            NewMsg.MESSAGE=str;
                            NewMsg.NEXT=this.headMsg.NEXT;
                            this.headMsg.NEXT=NewMsg;
                            this.totMsgs++;
                            oGraphics.DrawEllipse(myPen, this.temp.PIXEL_NUMBER_X-this.interNodeDistance, this.temp.PIXEL_NUMBER_Y-this.interNodeDistance, this.interNodeDistance*2, this.interNodeDistance*2);
                            this.temp1=this.headNode;
                            for(int m=0;m<this.numNodes;m++)
                            {
                                if((this.temp.MAC_X!=this.temp1.MAC_X || this.temp.MAC_Y!=this.temp1.MAC_Y) )
                                {
                                    Xsq=this.temp.MAC_X-this.temp1.MAC_X;
                                    Xsq=Xsq*Xsq;
                                    Ysq=this.temp.MAC_Y-this.temp1.MAC_Y;
                                    Ysq=Ysq*Ysq;
                                    distSq=Xsq+Ysq;
                                    if((distSq<=this.xmissionRange*this.xmissionRange) )
                                    {
                                        this.temp1.NEIGHBOURRECEIVEDXMITTED=true;
                                        this.temp1.ITERATION=0;
                                    }
                                }
                                this.temp1=this.temp1.Next;
                            }
                        }
                    }
                }
                this.totMsgs=this.totMsgs-delMsgs;
            }
            rnd=null;
            oGraphics.Dispose();
            this.panel1.Invalidate();
        }