Пример #1
0
        void StateHandler(byte[] data)
        {
            proto.StateProto proto = codecs.Decode <proto.StateProto>(data);

            // 是自己的状态 直接忽略
            List <GameObject> game_objects = GameEngine.GetInstance().QueryGameObjectsByTag("Player");
            Player            p            = (Player)game_objects[0];

            if (proto.id == p.GetUnique())
            {
                return;
            }

            // 不存在其他玩家,添加敌人
            if (!enemy_dict.ContainsKey(proto.id))
            {
                Player enemy = new Enemy("Enemy", proto.id);
                enemy_dict[proto.id] = enemy;
                GameEngine.GetInstance().AddGameObject(enemy);
            }

            // 更新其他玩家的状态
            enemy_dict[proto.id].MoveTo(proto.row, proto.col);
            enemy_dict[proto.id].SetSymbol(proto.symbol);
        }
Пример #2
0
        public override void Update(int delta)
        {
            List <GameObject> game_objects = GameEngine.GetInstance().QueryGameObjectsByTag("Root");

            if (game_objects != null || game_objects.Count == 1)
            {
                Root             r     = (Root)game_objects[0];
                proto.StateProto state = new proto.StateProto();
                state.id     = unique_;
                state.col    = col_;
                state.row    = row_;
                state.symbol = symbol_;
                r.SendStateProto(state);
            }

            if (!Console.KeyAvailable)
            {
                return;
            }

            char           key = ' ';
            ConsoleKeyInfo cki = Console.ReadKey(true);

            if (cki.Key == ConsoleKey.W)
            {
                key = 'W';
            }
            else if (cki.Key == ConsoleKey.S)
            {
                key = 'S';
            }
            else if (cki.Key == ConsoleKey.A)
            {
                key = 'A';
            }
            else if (cki.Key == ConsoleKey.D)
            {
                key = 'D';
            }

            game_objects = GameEngine.GetInstance().QueryGameObjectsByTag("Root");
            if (game_objects != null || game_objects.Count == 1)
            {
                Root r = (Root)game_objects[0];
                proto.ActionProto action = new proto.ActionProto();
                action.id  = unique_;
                action.key = key;
                r.SendActionProto(action);
            }
        }
Пример #3
0
 public void SendStateProto(proto.StateProto state)
 {
     _net.Send((int)NetworkProtocolType.STATE, codecs.Encode <proto.StateProto>(state));
 }