Пример #1
0
        private void StatusChange(short newStatus)
        {
            switch (newStatus)
            {
            case 0x112:     //抛竿动作1(常规鱼饵)
            case 0x113:     //抛竿动作2(部分拟饵以小钓大等)
            case 0x114:     //抛竿动作3(摇蚊等特殊鱼饵等)
            case 0xC49:     //抛竿动作1(坐下时)
            case 0xC4A:     //抛竿动作2(坐下时)
            case 0xC4B:     //抛竿动作3(坐下时)
                Fish.Cast();
                break;

            case 0x124:     //咬钩(轻杆)
                Fish.Bite(TugType.Light);
                break;

            case 0x125:     //咬钩(中杆)
                Fish.Bite(TugType.Medium);
                break;

            case 0x126:     //咬钩(鱼王杆)
                Fish.Bite(TugType.Heavy);
                break;

            case 0x11B:     //脱钩
            case 0xC52:     //脱钩(坐下时)
                Fish.Bite(TugType.None);
                break;

            case 0x111:     //停止垂钓
            case 0xC48:     //停止垂钓(坐下时)
                Fish.Reset();
                break;
            }

            // 原代码 虽然行数整齐一些但是太不直观了

            /*
             * switch (newStatus)
             * {
             *  case short n when new short[] { 0x112, 0x113, 0x114, 0xC49, 0xC4A, 0xC4B }.Any(x => n == x):
             *      Fish.Cast();
             *      break;
             *  case short n when new short[] { 0x124, 0x125, 0x126 }.Any(x => n == x):
             *      var tug = (TugType) (n - 0x123);
             *      //0x124:TugType.Light 0x125:TugType.Medium 0x126:TugType.Heavy
             *      Fish.Bite(tug);
             *      break;
             *  case short n when new short[] { 0x11B, 0xC52 }.Any(x => n == x):
             *      Fish.Bite(TugType.None);
             *      break;
             *  case short n when new short[] { 0x111, 0xC48 }.Any(x => n == x):
             *      Fish.Reset();
             *      break;
             *  default:
             *      break;
             * }*/
        }