当前位置: 首页>>代码示例>>C#>>正文


C# ByteArray.Close方法代码示例

本文整理汇总了C#中ByteArray.Close方法的典型用法代码示例。如果您正苦于以下问题:C# ByteArray.Close方法的具体用法?C# ByteArray.Close怎么用?C# ByteArray.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ByteArray的用法示例。


在下文中一共展示了ByteArray.Close方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: newTurn

        public override void newTurn(GameState whoseTurn)
        {
            bool meFirst = whoseTurn == GameState.MY_TURN;
            ByteArray msg = new ByteArray();
            msg.write(Const.NEW_TURN);
            msg.write(meFirst);
            sendMsg(client1, msg);
            msg.Close();

            msg = new ByteArray();
            msg.write(Const.NEW_TURN);
            msg.write(!meFirst);
            sendMsg(client2, msg);
            msg.Close();
        }
开发者ID:zhendery,项目名称:FiveVsFive,代码行数:15,代码来源:LanServer.cs

示例2: MessageEncode

        /// <summary>
        /// 消息体序列化
        /// </summary>
        /// <param name="value">消息体</param>
        /// <returns></returns>
        public static byte[] MessageEncode(object value)
        {
            SocketModel model = value as SocketModel;
            ByteArray ba = new ByteArray();
            ba.Write(model.Type);
            ba.Write(model.Area);
            ba.Write(model.Command);

            if (model.Message != null)
            {
                ba.Write(SerializeUtil.Encode(model.Message));
            }

            byte[] result = ba.GetBuff();
            ba.Close();
            return result;
        }
开发者ID:dafei2015,项目名称:LOLClient,代码行数:22,代码来源:MessageEncoding.cs

示例3: MessageDecode

        /// <summary>
        /// 消息体的反序列化
        /// </summary>
        /// <param name="value">序列化的二进制码</param>
        /// <returns></returns>
        public static object MessageDecode(byte[] value)
        {
            ByteArray ba = new ByteArray(value);
            SocketModel model = new SocketModel();
            byte type;
            int area;
            int command;
            ba.Read(out type);
            ba.Read(out area);
            ba.Read(out command);
            model.Type = type;
            model.Area = area;
            model.Command = command;

            if (ba.ReadEnable)
            {
                byte[] message;
                ba.Read(out message, ba.Length - ba.Position);
                model.Message = SerializeUtil.Decode(message);
            }
            ba.Close();
            return model;
        }
开发者ID:dafei2015,项目名称:LOLClient,代码行数:28,代码来源:MessageEncoding.cs

示例4: handleMsg

 void handleMsg(ByteArray msg)
 {
     ByteArray newMsg = new ByteArray();
     byte action = msg.readByte();
     switch (action)
     {
         case Const.CONNECT:
             yourLogo = msg.readInt();
             yourName = msg.readString();
             break;
         case Const.NEW_TURN:
             bool isMyTurn = msg.readBool();
             newTurn(isMyTurn);
             break;
         case Const.UP_CHESS:
             board.chessUp = msg.readInt();
             break;
         case Const.MOVE_CHESS:
             int pos = msg.readInt();
             board.moveChess(pos);
             break;
         case Const.YOUR_TURN://就是轮到我了
             whoseTurn = GameState.MY_TURN;
             break;
         case Const.END_GAME://有人赢了
             isGaming = false;
             whoseTurn = GameState.NO_TURN;
             gameRes = (GameRes)msg.readInt();//将以int形式发送过来的比赛结果存入gameRes以供检测
             break;
         case Const.RETRACT_APPLY://收到悔棋申请~则显示提示,如同意则回发悔棋指令
             MessageBox.show("您同意您的对手悔棋吗?", "同意",
                 delegate()
                 {
                     newMsg.write(Const.RETRACT_CHESS);
                     sendMsg(newMsg);
                 },
                 "拒绝",
                 delegate()
                 {
                     newMsg.write(Const.RETRACT_DISAGREE);
                     sendMsg(newMsg);
                 });
             break;
         case Const.RETRACT_CHESS:
             Global.board.retract();
             break;
         case Const.RETRACT_DISAGREE:
             MessageBox.show("您的对手不同意您悔棋", "了解",
                 delegate() { }, null, null);
             break;
         case Const.DISCONNECT://有人掉线了,或者有人退出了isRunning = false;
             if (client != null)
             {
                 client.Close();
                 client = null;
             }
             Global.setSceneOld(GameScenes.WELCOME);//返回欢迎界面
             isGaming = isRunning = false;
             break;
     }
     msg.Close();
 }
开发者ID:zhendery,项目名称:FiveVsFive,代码行数:62,代码来源:LanClient.cs

示例5: sendMsg

 void sendMsg(ByteArray msg)
 {
     byte[] bits = msg.encode();
     client.Send(bits);
     msg.Close();
 }
开发者ID:zhendery,项目名称:FiveVsFive,代码行数:6,代码来源:LanClient.cs

示例6: sendMsg

 protected void sendMsg(Socket sock, ByteArray msg)
 {
     byte[] bits = msg.encode();
     if (sock.Connected)
         sock.Send(bits);
     msg.Close();
 }
开发者ID:zhendery,项目名称:FiveVsFive,代码行数:7,代码来源:LanServer.cs

示例7: handleMsg

        protected void handleMsg(ByteArray msg, Socket from, Socket to)
        {
            byte action = msg.readByte();
            ByteArray newMsg = new ByteArray();
            switch (action)
            {
                case Const.NEW_TURN:
                    ruleController.reset();//开始新游戏
                    break;
                case Const.UP_CHESS:
                    newMsg.write(Const.UP_CHESS);
                    //因为对手的棋盘和我是正好相反的,所以要取”互补数“  这里是index
                    newMsg.write(9 - msg.readInt());
                    sendMsg(to, newMsg);
                    break;
                case Const.MOVE_CHESS:
                    newMsg.write(Const.MOVE_CHESS);
                    //因为对手的棋盘和我是正好相反的,所以要取”互补数“  这里是pos
                    newMsg.write(24 - msg.readInt());
                    sendMsg(to, newMsg);
                    break;
                case Const.YOUR_TURN:
                    //走完了判断输赢
                    GameRes res = ruleController.yourTurn();
                    if (res == GameRes.NO_WIN)//如果没有人赢则向对手发送你走的指令
                    {
                        newMsg.write(Const.YOUR_TURN);
                        sendMsg(to, newMsg);
                    }
                    else//如果有人赢了,则向两位玩家发送谁赢了
                    {
                        newMsg.write(Const.END_GAME);
                        newMsg.write((int)res);//将比赛结果以int形式发送给两方
                        sendMsg(client1, newMsg);

                        newMsg.Close();
                        newMsg = new ByteArray();
                        newMsg.write(Const.END_GAME);
                        newMsg.write(2/(int)res);//将比赛结果以int形式发送给两方
                        sendMsg(client2, newMsg);
                    }
                    break;
                case Const.RETRACT_APPLY://收到悔棋申请则将申请发送给对方
                    sendMsg(to, msg);
                    break;
                case Const.RETRACT_DISAGREE://不同意悔棋
                    sendMsg(to, msg);
                    break;
                case Const.RETRACT_CHESS://收到悔棋指令(同意),将其传送给两方
                    sendMsg(from, msg);
                    sendMsg(to, msg);
                    break;
                case Const.CONNECT:
                    sendMsg(to,msg);//起到一个传递消息的作用
                    break;
                case Const.DISCONNECT:
                    sendMsg(to, msg);
                    if (client1 != null)
                    {
                        client1.Close();//结束监听进程
                        client1 = null;
                    }
                    if (client2 != null)
                    {
                        client2.Close();//结束监听进程
                        client2 = null;
                    }
                    isRunning = false;//结束所有进程
                    break;
            }

            newMsg.Close();
            msg.Close();
        }
开发者ID:zhendery,项目名称:FiveVsFive,代码行数:74,代码来源:LanServer.cs

示例8: handleMsg

 protected override void handleMsg(ByteArray msg)
 {
     byte action = msg.readByte();
     ByteArray newMsg = new ByteArray();
     switch (action)
     {
         case Const.NEW_TURN:
             ruleController.reset();//开始新游戏
             break;
         case Const.YOUR_TURN:
             GameRes res = ruleController.yourTurn();
             if (res == GameRes.NO_WIN)//如果没有人赢则让ai走
             {
                 Global.client.whoseTurn = ruleController.whoseTurn;
                 if (ruleController.whoseTurn == GameState.YOUR_TURN)
                     ai.move();
                 else
                 {
                     newMsg.write(Const.YOUR_TURN);
                     sendMsg(newMsg);
                 }
             }
             else//如果有人赢了,则告诉玩家发送谁赢了
             {
                 newMsg.write(Const.END_GAME);
                 newMsg.write((int)res);//将比赛结果以int的形式发送给我
                 sendMsg(newMsg);
             }
             break;
         case Const.RETRACT_APPLY://本机收到申请则默认同意~直接回发悔棋指令
             newMsg.write(Const.RETRACT_CHESS);
             sendMsg(newMsg);
             break;
         case Const.END_GAME:
             newMsg.write(Const.END_GAME);
             newMsg.write((int)GameRes.YOU_WIN);//发送对方赢的结果
             sendMsg(newMsg);
             break;
         case Const.DISCONNECT:
             if (client1 != null)
             {
                 client1.Close();
                 client1 = null;
             }
             break;
     }
     msg.Close();
 }
开发者ID:zhendery,项目名称:FiveVsFive,代码行数:48,代码来源:LocalServer.cs

示例9: newTurn

        public override void newTurn(GameState whoseTurn)
        {
            bool meFirst = whoseTurn == GameState.MY_TURN;
            ByteArray msg = new ByteArray();
            msg.write(Const.NEW_TURN);
            msg.write(meFirst);
            sendMsg(msg);
            msg.Close();

            if (!meFirst)
            {
                Thread.Sleep(1600);
                ai.move();
            }
        }
开发者ID:zhendery,项目名称:FiveVsFive,代码行数:15,代码来源:LocalServer.cs


注:本文中的ByteArray.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。