Пример #1
0
 void Remove_Gold(GOLD a)
 {
     lock (lockthis)
     {
         lstGold.Remove(a);
     }
 }
Пример #2
0
        void Addgold(String strgold)
        {
            string[] arrListStr = strgold.Split(',');
            GOLD     gold       = new GOLD(Int32.Parse(arrListStr[0]), Int32.Parse(arrListStr[1]), Int32.Parse(arrListStr[2]));

            lstGold.Add(gold);
        }
Пример #3
0
        void drawstraight()
        {
            Point    start, run, end;
            int      t;
            Pen      pen = new Pen(Color.Red, 2);
            Pen      pen1 = new Pen(Color.White, 2);
            Graphics g = panel1.CreateGraphics();
            GOLD     tem = new GOLD(1, 1, 1);
            int      t1, t2;

            while (true)
            {
                Label :  while (!flagdraw)
                {
                    ;
                }
                t     = 1;
                start = new Point(cancau.Location.X + cancau.Width / 2, 0);
                run   = new Point(start.X, start.Y + 2);
                end   = new Point(start.X, start.Y + panel1.Height);
                tem   = Collision(run);
                t1    = 0;
                t2    = 0;
                while (run.Y >= start.Y + 2)
                {
                    if (flagdraw == false)
                    {
                        goto Label;
                    }
                    if (t == 1)
                    {
                        g.DrawLine(pen, start, run);
                    }
                    else
                    {
                        g.DrawLine(pen1, end, run);
                    }
                    Thread.Sleep(Cons.SpeedThaCau);
                    if (tem == null)
                    {
                        if (t2 == 0)
                        {
                            tem = Collision(run);
                        }
                    }
                    else
                    {
                        if (t1 == 0)
                        {
                            tcp.SendData(Cons.Send_CanCau + Convert.ToString(tem.lb.Location.X) + "," + tem.lb.Location.Y);
                            t1 = 1;
                            t2 = 1;
                        }
                        t = -1;
                        tem.setlb(tem.lb.Location.Y + t);
                    }
                    run.Y = run.Y + t;
                    if (run.Y == end.Y)
                    {
                        t = -1;
                    }
                }
                try
                {
                    if (tem.pos != tem.lb.Location && flagdraw == true)
                    {
                        AddMark(tem);
                        tem.lb.Visible = false;
                        Remove_Gold(tem);
                    }
                }
                catch
                {
                    Console.Write("ko co vang");
                }
                flagRuncancau = true;
                btdao.Enabled = true;
                flagdraw      = false;
                refresh();
            }
        }
Пример #4
0
 void AddMark(GOLD g)
 {
     BoxMyMark.Text = Convert.ToString(Int32.Parse(BoxMyMark.Text) + g.value);
 }
Пример #5
0
        void HandleReceive(String str)
        {
            if (str[0] == Cons.Receive_Result)
            {
                result = str[1];
                return;
            }

            if (str[0] == Cons.Receive_End)
            {
                flagEnd = true;
                return;
            }
            if (str[0] == Cons.Receive_OpDisconnect)
            {
                flagReady = false;
                panel3.Invoke((MethodInvoker) delegate
                {
                    //perform on the UI thread
                    label7.Visible = true;
                });
                //
                btdao.Enabled = false;
                flagRuncancau = false;
                flagdraw      = false;
                Clear_Panel1();
                Clear_LstGold();
                refresh();
                Thread.Sleep(1000);
                return;
            }
            if (str[0] == Cons.Receive_Ready)
            {
                btbatdau.Enabled = true;

                panel3.Invoke((MethodInvoker) delegate
                {
                    //perform on the UI thread
                    label7.Visible = false;
                });
                return;
            }
            if (str[0] == Cons.Receive_Room)
            {
                str       = str.Substring(1);
                Room.Text = "Phong: " + str;
                tcp.SendData(Cons.Send_OK + "");
                return;
            }
            if (str[0] == Cons.Receive_Master)
            {
                master           = true;
                btbatdau.Text    = "Bắt đầu";
                btbatdau.Enabled = false;
                return;
            }
            if (str[0] == Cons.Receive_Start)
            {
                btbatdau.Enabled = false;
                flagRuncancau    = true;
                flagReady        = true;
                //timer1.Enabled = true;
                //timer1.Start();
                drawmap(lstGold);
                btdao.Enabled  = true;
                BoxMyMark.Text = "0";
                BoxOpMark.Text = "0";
                return;
            }
            if (str[0] == Cons.Receive_Golg)
            {
                str = str.Substring(1);
                string[] arrListStr = str.Split(',');
                Point    pt         = new Point(Int32.Parse(arrListStr[0]), Int32.Parse(arrListStr[1]));
                GOLD     remove     = new GOLD(0, 0, 0);
                remove = lstGold.Find(x => x.pos == pt);
                if (remove != null)
                {
                    Remove_Gold(remove);
                    remove.lb.Visible = false;
                }
                return;
            }
            if (str[0] == Cons.Receive_map)
            {
                int i = 0;
                Clear_LstGold();
                Clear_Panel1();
                str = str.Substring(1);
                string[] arrListStr = str.Split('.');
                lock (lockthis)
                {
                    while (arrListStr.Length - 1 > i)
                    {
                        Addgold(arrListStr[i]);
                        i++;
                    }
                }
                //  tcp.SendData(Cons.Send_OK+"");
                return;
            }
            if (str[0] == Cons.Receive_OpMark)
            {
                str            = str.Substring(1);
                BoxOpMark.Text = str;

                return;
            }
        }