Esempio n. 1
0
        public void Login(long playerId)
        {
            var player = new Player();

            player.id    = playerId;
            player.name  = "hello";
            player.pos   = new Vector3();
            player.dir   = new Vector3();
            player.state = 0;
            player.hp    = 0;

            scene.MasterAddObj(player);

            this.Info("Login playerId:{0}", playerId);
        }
Esempio n. 2
0
        public void Server(object obj)
        {
            var scene = new SyncScene();

            scene.Init();

            scene.MasterAddObj(new GameState
            {
                canRecvMsg = false,
                id         = 3,
                safePoint  = new Vector3(),
                safeRadius = 1000
            });

            scene.onSendMsg = (id, msg) =>
            {
                if (id != 1)
                {
                    return;
                }
                lock (queue)
                {
                    queue.Enqueue(msg);
                }
            };

            scene.onObjAdded = added =>
            {
                switch (added)
                {
                case Player player:
                    player.csFire = (dst, count, hit) => { };
                    player.csMove = (pos, dir, state) => { };
                    break;
                }
            };
            scene.onObjRefreshed = refreshed => { };
            scene.onObjRemoved   = removed => { };


            var p1 = new Player {
                id = 1
            };
            var p2 = new Player {
                id = 2
            };

            p1.csMove = (pos, dir, state) =>
            {
                p1.pos   = pos;
                p1.dir   = dir;
                p1.state = state;
            };
            p1.csFire = (targetId, bulletCount, isHit) =>
            {
                p2.hp = 0;
                p2.scExplode();
            };
            p2.scExplode = () => { };


            scene.MasterAddObj(p1);
            scene.MasterAddObj(p2);


            while (true)
            {
                scene.MasterUpdateObjs();
                Thread.Sleep(100);
            }

            scene.MasterRemoveObj(p2.id);


            scene.Destroy();
        }
Esempio n. 3
0
        public static void Test()
        {
            var cli   = new Client();
            var scene = new SyncScene();

            scene.Init();
            scene.onSendMsg = (id, msg) =>
            {
                if (id != 1)
                {
                    return;
                }

                cli.RecvMsg(msg);
            };
            scene.MasterAddObj(new GameState
            {
                canRecvMsg = false,
                id         = 3,
                safePoint  = new Vector3(),
                safeRadius = 1000
            });
            scene.onObjAdded = added =>
            {
                switch (added)
                {
                case Player player:
                    player.csMove = (pos, dir, state) =>
                    {
                        player.pos   = pos;
                        player.dir   = dir;
                        player.state = state;
                    };
                    player.csFire = (targetId, bulletCount, isHit) =>
                    {
                        var target = scene.FindObj(targetId) as Player;
                        target.hp = 0;
                        target.scExplode();
                    };
                    player.scExplode = () =>
                    {
                        // pack rpc
                    };
                    break;
                }
            };
            scene.onObjRefreshed = refreshed => { };
            scene.onObjRemoved   = removed => { };
            var p1 = new Player {
                id = 1
            };
            var p2 = new Player {
                id = 2
            };

            scene.MasterAddObj(p1);
            cli.Dispatch();
            scene.MasterAddObj(p2);
            cli.Dispatch();
            scene.MasterRemoveObj(p2.id);
            scene.Destroy();
        }