Ejemplo n.º 1
0
 public void Send(QiZi qz)
 {
     if (isConn)
     {
         byte[] bq = new byte[20];
         string x  = qz.Rect.X.ToString();
         string y  = qz.Rect.Y.ToString();
         for (int i = 0; i < x.Length; i++)
         {
             bq[i] = Convert.ToByte(x[i]);
         }
         for (int i = 0; i < y.Length; i++)
         {
             bq[10 + i] = Convert.ToByte(y[i]);
         }
         try
         {
             client.Send(bq);
         }
         catch (System.Exception e)
         {
             MessageBox.Show(e.Message);
             this.Close();
         }
     }
 }
Ejemplo n.º 2
0
        public bool HuiQi()//悔棋
        {
            if (q1 != null && q2 != null)
            {
                q1.Qs = QiSe.Null;
                q2.Qs = QiSe.Null;

                q1.Paint();
                q2.Paint();
                q1 = null; q2 = null;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        public QiZi Recv()
        {
            if (isConn)
            {
                byte[] bq = new byte[20];
                try
                {
                    client.Receive(bq);
                }
                catch (System.Exception e)
                {
                    MessageBox.Show(e.Message);
                    this.Close();
                }
                StringBuilder sbx = new StringBuilder();
                StringBuilder sby = new StringBuilder();
                for (int i = 0; i < 10; i++)
                {
                    if (bq[i] != 0)
                    {
                        sbx.Append(Convert.ToChar(bq[i]));
                    }
                    if (bq[10 + i] != 0)
                    {
                        sby.Append(Convert.ToChar(bq[10 + i]));//5-1-a-s-p-x
                    }
                }
                int x = Convert.ToInt32(sbx.ToString());
                int y = Convert.ToInt32(sby.ToString());

                Rectangle rect = new Rectangle(x, y, rectPix, rectPix);
                QiSe      qs;
                if (isServer)
                {
                    qs = QiSe.Hei;
                }
                else
                {
                    qs = QiSe.Bai;
                }

                QiZi qz = new QiZi(qs, rect, gp, rectPix);
                return(qz);
            }
            return(null);
        }
Ejemplo n.º 4
0
 public void ThreadProc()//接收线程函数
 {
     while (bt)
     {
         if (start)
         {
             if (isServer)
             {
                 QiZi qz = localnet.Recv();
                 if (qz != null)
                 {
                     int i = qz.Rect.X / rectPix;
                     int j = qz.Rect.Y / rectPix;
                     QzArr[i, j] = qz;
                     qz.Paint();
                     if (ShuYin())
                     {
                         bt = false;
                         localnet.Close();
                         shu = true;
                     }
                     this.turn = QiSe.Bai;
                 }
             }
             else
             {
                 QiZi qz = localnet.Recv();
                 if (qz != null)
                 {
                     int i = qz.Rect.X / rectPix;
                     int j = qz.Rect.Y / rectPix;
                     QzArr[i, j] = qz;
                     qz.Paint();
                     if (ShuYin())
                     {
                         bt = false;
                         localnet.Close();
                         shu = true;
                     }
                     this.turn = QiSe.Hei;
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
        public bool LocalnetXiaQi(int x, int y)//局域网游戏
        {
            if (isServer && turn == QiSe.Bai)
            {
                if (qzArr[x, y].Qs == QiSe.Null)
                {
                    qzArr[x, y].Qs = turn;
                    qzArr[x, y].Paint();
                    q1 = qzArr[x, y];
                    if (ShuYin())
                    {
                        localnet.Send(QzArr[x, y]);
                        this.turn = QiSe.Hei;
                        localnet.Close();
                        return(true);
                    }

                    localnet.Send(QzArr[x, y]);
                    this.turn = QiSe.Hei;
                }
            }

            if (!isServer && turn == QiSe.Hei)
            {
                if (qzArr[x, y].Qs == QiSe.Null)
                {
                    qzArr[x, y].Qs = turn;
                    qzArr[x, y].Paint();
                    q1 = qzArr[x, y];
                    if (ShuYin())
                    {
                        localnet.Send(QzArr[x, y]);
                        this.turn = QiSe.Hei;
                        localnet.Close();
                        return(true);
                    }
                    localnet.Send(QzArr[x, y]);
                    this.turn = QiSe.Bai;
                }
            }

            return(false);
        }
Ejemplo n.º 6
0
        //局域网游戏
        public bool LocalnetXiaQi(int x, int y)
        {
            if (isServer && turn == QiSe.Bai)
            {
                if (qzArr[x, y].Qs == QiSe.Null)
                {
                    qzArr[x, y].Qs = turn;
                    qzArr[x, y].Paint();
                    q1 = qzArr[x, y];
                    if (ShuYin())
                    {
                        localnet.Send(QzArr[x, y]);
                        this.turn = QiSe.Hei;
                        localnet.Close();
                        return true;
                    }

                    localnet.Send(QzArr[x, y]);
                    this.turn = QiSe.Hei;
                }
            }

            if (!isServer && turn == QiSe.Hei)
            {
                if (qzArr[x, y].Qs == QiSe.Null)
                {
                    qzArr[x, y].Qs = turn;
                    qzArr[x, y].Paint();
                    q1 = qzArr[x, y];
                    if (ShuYin())
                    {
                        localnet.Send(QzArr[x, y]);
                        this.turn = QiSe.Hei;
                        localnet.Close();
                        return true;
                    }
                    localnet.Send(QzArr[x, y]);
                    this.turn = QiSe.Bai;
                }
            }

            return false;
        }
Ejemplo n.º 7
0
        //悔棋
        public bool HuiQi()
        {
            if (q1 != null && q2 != null)
            {
                q1.Qs = QiSe.Null;
                q2.Qs = QiSe.Null;

                q1.Paint();
                q2.Paint();
                q1 = null; q2 = null;
                return true;
            }
            return false;
        }
Ejemplo n.º 8
0
        public QiZi Recv()
        {
            if(isConn)
            {
                byte[] bq = new byte[20];
                try
                {
                    client.Receive(bq);
                }
                catch (System.Exception e)
                {
                    MessageBox.Show(e.Message);
                    this.Close();
                }
                StringBuilder sbx = new StringBuilder();
                StringBuilder sby = new StringBuilder();
                for (int i = 0; i < 10; i++)
                {
                    if (bq[i] != 0)
                        sbx.Append(Convert.ToChar(bq[i]));
                    if (bq[10 + i] != 0)
                        sby.Append(Convert.ToChar(bq[10 + i]));//5-1-a-s-p-x
                }
                int x = Convert.ToInt32(sbx.ToString());
                int y = Convert.ToInt32(sby.ToString());

                Rectangle rect = new Rectangle(x, y, rectPix, rectPix);
                QiSe qs;
                if (isServer)
                    qs = QiSe.Hei;
                else
                    qs = QiSe.Bai;

                QiZi qz = new QiZi(qs, rect, gp, rectPix);
                return qz;
            }
            return null;
        }
Ejemplo n.º 9
0
 public void Send(QiZi qz)
 {
     if(isConn)
     {
         byte[] bq = new byte[20];
         string x = qz.Rect.X.ToString();
         string y = qz.Rect.Y.ToString();
         for (int i = 0; i < x.Length; i++)
         {
             bq[i] = Convert.ToByte(x[i]);
         }
         for (int i = 0; i < y.Length; i++)
         {
             bq[10 + i] = Convert.ToByte(y[i]);
         }
         try
         {
             client.Send(bq);
         }
         catch (System.Exception e)
         {
             MessageBox.Show(e.Message);
             this.Close();
         }
     }
 }