public static GameUserManager GetInstance() { lock (locker) if (instance == null) { lock (locker) instance = new GameUserManager(); } return(instance); }
/// <summary> /// Get join. /// </summary> /// <param name="playerId">playerId</param> /// <returns>Is players full</returns> public string PlayerGetJoin(Guid playerId) { if (playerReadyDic.Any(d => d.Key.Equals(playerId)) || Players.Any(d => d.ID.Equals(playerId)))//若玩家已加入则返回false { throw new ArgumentException("玩家已加入"); } else { var player = GameUserManager.GetInstance().GetPlayerInfo(playerId); string HasJoinPlayers = string.Empty; if (Players.Count > 0) { foreach (var item in Players) { if (item != null) { HasJoinPlayers += item.ID + ","; } } HasJoinPlayers = HasJoinPlayers.Substring(0, HasJoinPlayers.Length - 1); } Players.ForEach(d => playerReadyDic[d.ID] = false); Players.Add(player); playerReadyDic.Add(playerId, false); Players.ForEach(d => { _sendMsgCallback(d.ID, "{'ActionName':'GetJoin','joinplayer':'" + playerId + "'}"); }); if (Players.Count >= 5) { Players.ForEach(d => { _sendMsgCallback(d.ID, "{'ActionName':'Notice','gamestate':'ready'}"); }); } return(HasJoinPlayers); } }