コード例 #1
0
ファイル: NetHelper.cs プロジェクト: muupu/GoMoku
 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();
         }
     }
 }
コード例 #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);
        }
コード例 #3
0
ファイル: NetHelper.cs プロジェクト: muupu/GoMoku
        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);
        }
コード例 #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;
                 }
             }
         }
     }
 }
コード例 #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);
        }
コード例 #6
0
ファイル: Board.cs プロジェクト: muupu/GoMoku
        //局域网游戏
        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;
        }
コード例 #7
0
ファイル: Board.cs プロジェクト: muupu/GoMoku
        //悔棋
        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;
        }
コード例 #8
0
ファイル: NetHelper.cs プロジェクト: muupu/GoMoku
        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;
        }
コード例 #9
0
ファイル: NetHelper.cs プロジェクト: muupu/GoMoku
 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();
         }
     }
 }