Пример #1
0
        public void ApplayAction(proto.ActionProto action)
        {
            if (action.id != unique_)
            {
                return;
            }

            if (action.key == 'W')
            {
                row_ -= 1;
            }

            if (action.key == 'S')
            {
                row_ += 1;
            }

            if (action.key == 'A')
            {
                col_ -= 1;
            }

            if (action.key == 'D')
            {
                col_ += 1;
            }

            row_ = Math.Min(Math.Max(row_, top_bound_), bottom_bound_);
            col_ = Math.Min(Math.Max(col_, left_bound_), right_bound_);
        }
Пример #2
0
        void ActionHandler(byte[] data)
        {
            proto.ActionProto proto = codecs.Decode <proto.ActionProto>(data);

            // 是自己的状态 才进行更新
            List <GameObject> game_objects = GameEngine.GetInstance().QueryGameObjectsByTag("Player");
            Player            p            = (Player)game_objects[0];

            if (proto.id == p.GetUnique())
            {
                p.ApplayAction(proto);
            }
        }
Пример #3
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);
            }
        }
Пример #4
0
 public void SendActionProto(proto.ActionProto action)
 {
     _net.Send((int)NetworkProtocolType.ACTION, codecs.Encode <proto.ActionProto>(action));
 }