コード例 #1
0
    //收到玩家退出协议
    public static void OnMsgLeaveBattle(MsgBase msgBase)
    {
        MsgLeaveBattle msg = (MsgLeaveBattle)msgBase;
        //查找坦克
        BaseTank tank = GetTank(msg.id);

        if (tank == null)
        {
            return;
        }
        //删除坦克
        RemoveTank(msg.id);
        MonoBehaviour.Destroy(tank.gameObject);
    }
コード例 #2
0
ファイル: BattleManager.cs プロジェクト: Severn17/UnityLearn
    private static void OnMsgLeaveBattle(MsgBase msgBase)
    {
        MsgLeaveBattle msg = (MsgLeaveBattle)msgBase;
        // 查找坦克
        BaseTank tank = GetTank(msg.id);

        if (tank == null)
        {
            return;
        }

        RemoveTank(msg.id);
        Destroy(tank.gameObject);
    }
コード例 #3
0
ファイル: Room.cs プロジェクト: cocos56/TanksWar
    //删除玩家
    public bool RemovePlayer(string id)
    {
        //获取玩家
        Player player = PlayerManager.GetPlayer(id);

        if (player == null)
        {
            Console.WriteLine("room.RemovePlayer fail, player is null");
            return(false);
        }
        //没有在房间里
        if (!playerIds.ContainsKey(id))
        {
            Console.WriteLine("room.RemovePlayer fail, not in this room");
            return(false);
        }
        //删除列表
        playerIds.Remove(id);
        //设置玩家数据
        player.camp   = 0;
        player.roomId = -1;
        //设置房主
        if (ownerId == player.id)
        {
            ownerId = SwitchOwner();
        }
        //战斗状态退出
        if (status == Status.FIGHT)
        {
            player.data.lost++;
            MsgLeaveBattle msg = new MsgLeaveBattle();
            msg.id = player.id;
            Broadcast(msg);
        }
        //房间为空
        if (playerIds.Count == 0)
        {
            RoomManager.RemoveRoom(this.id);
        }
        //广播
        Broadcast(ToMsg());
        return(true);
    }
コード例 #4
0
ファイル: Room.cs プロジェクト: innocence-ze/Server
    public bool RemovePlayer(string id)
    {
        Player player = PlayerManager.GetPlayer(id);

        if (player == null)
        {
            Console.WriteLine("room.RemovePlayer fail, player is null");
            return(false);
        }
        if (!playerDic.ContainsKey(id))
        {
            Console.WriteLine("room.RemovePlayer fail, not in this room");
            return(false);
        }

        playerDic.Remove(id);
        player.camp   = 0;
        player.roomId = -1;
        if (ownerId == player.id)
        {
            ownerId = SwitchOwner();
        }
        if (status == Status.FIGHT)
        {
            MsgLeaveBattle msg = new MsgLeaveBattle()
            {
                id = player.id,
            };
            Broadcast(msg);
        }
        if (playerDic.Count == 0)
        {
            RoomManager.RemoveRoom(this.id);
        }

        Broadcast(ToMsg());
        return(true);
    }