public override void Open() { base.Open(); #region 创建游戏:跳转到ChooseMapUI CreateGameButton.onClick.AddListener(() => { PUIManager.AddNewUIAction("创建游戏:转到CMUI", () => PUIManager.ChangeUI <PChooseMapUI>()); }); #endregion #region 加入游戏:跳转到JoinUI JoinGameButton.onClick.AddListener(() => { PUIManager.AddNewUIAction("加入游戏:转到JUI", () => PUIManager.ChangeUI <PJoinUI>()); }); #endregion #region 成就按钮:跳转到ArchUI ArchievementButton.onClick.AddListener(() => { PUIManager.AddNewUIAction("成就:转到AUI", () => PUIManager.ChangeUI <PArchUI>()); }); #endregion #region 用户按钮:跳转到UserUI UserButton.onClick.AddListener(() => { PUIManager.AddNewUIAction("成就:转到UUI", () => PUIManager.ChangeUI <PUserUI>()); }); #endregion #region 武将按钮:跳转到GeneralUI GeneralButton.onClick.AddListener(() => { PUIManager.AddNewUIAction("武将:转到GUI", () => PUIManager.ChangeUI <PGeneralUI>()); }); #endregion }
public PStartGameOrder() : base("start_game", (string[] args, string IPAddress) => { if (!PNetworkManager.NetworkServer.Game.StartGameFlag) { if (PNetworkManager.NetworkServer.Game.Room.IsFull()) { PThread.Async(() => { PNetworkManager.NetworkServer.Game.StartGame(); }); } } }, (string[] args) => { string MapName = args[1]; int PlayerIndex = Convert.ToInt32(args[2]); PMap Map = PSystem.MapList.Find((PMap TempMap) => TempMap.Name.Equals(MapName)); if (Map != null) { PSystem.PlayerIndex = PlayerIndex; PNetworkManager.NetworkClient.GameStatus = new PGameStatus(Map, PSystem.CurrentMode); PNetworkManager.NetworkClient.GameStatus.StartGame(); PUIManager.AddNewUIAction("StartGame[Client]-初始化地图切换到MUI", () => { PUIManager.ChangeUI <PMapUI>(); }); } }) { }
public override void Open() { base.Open(); #region 返回按钮:回到InitialUI ReturnButton.onClick.AddListener(() => { PUIManager.AddNewUIAction("返回:转到IUI", () => PUIManager.ChangeUI <PInitialUI>()); }); #endregion #region 加入游戏按钮:向服务器发送请求 JoinGameButton.onClick.AddListener(() => { string ServerIP = ServerIPInputField.text; string Nickname = NicknameInputField.text; if (!Regex.IsMatch(ServerIP, IPAddressPattern)) { ErrorText.text = "IP地址不正确"; } else if (Nickname.Equals(string.Empty) || Nickname.Length > 8 || Nickname.Contains(" ")) { ErrorText.text = "昵称须为1~8个字且不能有空格"; } else { if (PNetworkManager.CreateClient(ServerIP, Nickname)) { ErrorText.text = string.Empty; // 不进行任何操作,等待服务器的回应 } else { ErrorText.text = "网络连接失败"; } } }); #endregion }
public PShutDownOrder() : base("shut_down", null, (string[] args) => { PNetworkManager.AbortClient(); PUIManager.AddNewUIAction("ShutDown-返回InitialUI", () => { PUIManager.ChangeUI <PInitialUI>(); }); }) { }
public override void Open() { base.Open(); UsernameInputField.text = PSystem.UserManager.Nickname; ArchPointText.text = "成就点:" + PSystem.UserManager.ArchPoint + "/" + PSystem.ArchManager.TotalArchPoint(); MoneyText.text = "银两:" + PSystem.UserManager.Money; ChooseGeneralCardText.text = "点将卡数量:" + PSystem.UserManager.ChooseGeneral; LuckCardText.text = "手气卡数量:" + PSystem.UserManager.Lucky; ModifyUsernameButton.onClick.AddListener(() => { string NewUsername = UsernameInputField.text; if (NewUsername.Equals(string.Empty) || NewUsername.Length > 8 || NewUsername.Contains(" ")) { UsernameInputField.text = "改名失败"; } else { PSystem.UserManager.Nickname = NewUsername; PSystem.UserManager.Write(); } }); ChooseGeneralCardButton.onClick.AddListener(() => { if (PSystem.UserManager.Money >= 4) { PSystem.UserManager.Money -= 4; PSystem.UserManager.ChooseGeneral++; PSystem.UserManager.Write(); MoneyText.text = "银两:" + PSystem.UserManager.Money; ChooseGeneralCardText.text = "点将卡数量:" + PSystem.UserManager.ChooseGeneral; } }); LuckCardButton.onClick.AddListener(() => { if (PSystem.UserManager.Money >= 2) { PSystem.UserManager.Money -= 2; PSystem.UserManager.Lucky++; PSystem.UserManager.Write(); MoneyText.text = "银两:" + PSystem.UserManager.Money; LuckCardText.text = "手气卡数量:" + PSystem.UserManager.Lucky; } }); ReturnButton.onClick.AddListener(() => { PUIManager.AddNewUIAction("返回:转到IUI", () => PUIManager.ChangeUI <PInitialUI>()); }); }
public PRoomDataOrder() : base("room", null, (string[] args) => { try { int Capacity = int.Parse(args[1]); PSystem.CurrentRoom = new PRoom(Capacity); #region 分析房间的属性 int Index = 2; for (int i = 0; i < Capacity; ++i) { PPlayerType playerType = FindInstance <PPlayerType>(args[Index++]); if (playerType != null) { PSystem.CurrentRoom.PlayerList[i].PlayerType = playerType; PSystem.CurrentRoom.PlayerList[i].Nickname = args[Index++]; if (PSystem.CurrentRoom.PlayerList[i].Nickname.Equals("&")) { PSystem.CurrentRoom.PlayerList[i].Nickname = string.Empty; } } } #endregion #region 更新RUI的数据(未打开则先打开)及开始游戏按钮可交互性 PUIManager.AddNewUIAction("RoomData-更新RUI数据", () => { if (!PUIManager.IsCurrentUI <PRoomUI>()) { PUIManager.ChangeUI <PRoomUI>(); //如果游戏已经开始,把游戏关闭 } PUIManager.GetUI <PRoomUI>().SeatList.ForEach((PRoomUI.PSeat Seat) => { Seat.Update(); }); PUIManager.GetUI <PRoomUI>().StartGameButton.interactable = PSystem.CurrentRoom.IsFull(); }); #endregion } catch (Exception e) { PLogger.Log("房间数据错误"); PLogger.Log(e.ToString()); } }) { }
public override void Open() { base.Open(); #region 返回按钮:回到InitialUI ReturnButton.onClick.AddListener(() => { PUIManager.AddNewUIAction("返回:转到IUI", () => PUIManager.ChangeUI <PInitialUI>()); }); #endregion GeneralInfoInputField.text = string.Empty; GeneralPanel.Open(); GeneralPanel.GroupUIList.ForEach((PGeneralButtonUI GeneralButton) => { if (PSystem.UserManager.GeneralList.Contains(GeneralButton.General.Name)) { GeneralButton.UIBackgroundImage.GetComponent <Image>().color = Config.GotGeneralColor; } else { GeneralButton.UIBackgroundImage.GetComponent <Image>().color = Config.NotGotGeneralColor; } }); }
public override void Open() { base.Open(); #region 返回按钮:回到InitialUI ReturnButton.onClick.AddListener(() => { PUIManager.AddNewUIAction("返回:转到IUI", () => PUIManager.ChangeUI <PInitialUI>()); }); #endregion ArchInfoInputField.text = string.Empty; ArchPanel.Open(); ArchPanel.GroupUIList.ForEach((PArchButtonUI ArchButton) => { if (PSystem.ArchManager.ArchList.Exists((string x ) => x.Equals(ArchButton.ArchInfo.Name))) { ArchButton.UIBackgroundImage.GetComponent <Image>().color = Config.GotArchievementColor; } else { ArchButton.UIBackgroundImage.GetComponent <Image>().color = Config.NotGotArchievementColor; } }); }
public override void Open() { #region 根据当前模式调整房间内座位数量和颜色 for (int i = 0; i < MaxCapacity; ++i) { if (i < PSystem.CurrentMode.PlayerNumber) { SeatList[i].Open(); } else { SeatList[i].Close(); } } for (int i = 0; i < PSystem.CurrentMode.PlayerNumber; ++i) { SeatList[i].Background.color = PPlayerScene.Config.PlayerColors[PSystem.CurrentMode.Seats[i].Party - 1]; } #endregion #region 显示IP地址 IPAddressText.text = "本机IP:" + PNetworkConfig.IP.ToString(); #endregion #region 返回按钮:转到InitialUI并关闭服务器/客户端 ReturnButton.onClick.AddListener(() => { PNetworkManager.AbortClient(); if (PNetworkManager.CurrentHostType.Equals(PHostType.Server)) { PNetworkManager.AbortServer(); } PUIManager.AddNewUIAction("返回:转到IUI", () => PUIManager.ChangeUI <PInitialUI>()); }); #endregion #region 开始游戏按钮:发送开始游戏请求 StartGameButton.onClick.AddListener(() => { PNetworkManager.NetworkClient.Send(new PStartGameOrder()); }); #endregion base.Open(); }
public override void Open() { base.Open(); #region 返回按钮:回到InitialUI ReturnButton.onClick.AddListener(() => { PNetworkManager.AbortServer(); PUIManager.AddNewUIAction("返回:转到IUI", () => PUIManager.ChangeUI <PInitialUI>()); }); #endregion #region 确定按钮:创建服务器 EnterButton.onClick.AddListener(() => { string[] Parts = CodeInputField.text.Split(';'); if (Parts.Length <= 2) { return; } int Times = Math.Min(100, Math.Max(1, Convert.ToInt32(Parts[Parts.Length - 1]))); PSystem.AllAiConfig = CodeInputField.text; PNetworkManager.CreateSingleServer(PSystem.CurrentMap, PSystem.CurrentMode); PThread.Async(() => { for (int i = 0; i < Times; ++i) { string Time = DateTime.Now.ToLocalTime().ToString(); //PLogger.StartLogging(false); List <PGeneral> GeneralList = GenerateGenerals(PSystem.AllAiConfig); PNetworkManager.Game.Room.PlayerList.ForEach((PRoom.PlayerInRoom Player) => Player.PlayerType = PPlayerType.AI); PNetworkManager.Game.StartGame(GeneralList); PThread.WaitUntil(() => PNetworkManager.Game.ReadyToStartGameFlag); PUIManager.AddNewUIAction("增加结果序列", () => { PUIManager.GetUI <PTestUI>().ResultInputField.text += "Time: " + Time + "; Position: " + string.Join(",", PNetworkManager.Game.PlayerList.ConvertAll((PPlayer Player) => Player.General.Name)) + "; Winners: " + PNetworkManager.Game.Winners(true) + "\n"; }); } }); }); #endregion }
public override void Open() { base.Open(); #region 初始化选择地图下拉框 PSystem.MapList.ForEach((PMap Map) => { ChooseMapDropdown.options.Add(new Dropdown.OptionData { text = Map.Name }); }); #endregion #region 初始化选择模式下拉框 PMode.ListModes().ForEach((PMode Mode) => { ChooseModeDropdown.options.Add(new Dropdown.OptionData { text = Mode.Name }); }); #endregion ResetDropdowns(); QuickModeToggle.isOn = PPlayer.Config.QuickMode; #region 返回按钮:回到InitialUI ReturnButton.onClick.AddListener(() => { PUIManager.AddNewUIAction("返回:转到IUI", () => PUIManager.ChangeUI <PInitialUI>()); }); #endregion #region 确定按钮:创建服务器 EnterButton.onClick.AddListener(() => { int MapValue = ChooseMapDropdown.value; int ModeValue = ChooseModeDropdown.value; PSystem.AllAi = false; try { PNetworkManager.CreateServer(PSystem.MapList[MapValue], PMode.ListModes().Find((PMode Mode) => Mode.Name.Equals(ChooseModeDropdown.options[ModeValue].text))); } catch (Exception e) { PLogger.Log("建立服务器错误"); PLogger.Log(e.ToString()); } // 等待客户端接收到信息 }); #endregion #region 测试按钮:开启AI测试界面 TestButton.onClick.AddListener(() => { int MapValue = ChooseMapDropdown.value; int ModeValue = ChooseModeDropdown.value; PSystem.AllAi = true; try { PNetworkManager.CreateServer(PSystem.MapList[MapValue], PMode.ListModes().Find((PMode Mode) => Mode.Name.Equals(ChooseModeDropdown.options[ModeValue].text))); } catch (Exception e) { PLogger.Log("建立服务器错误"); PLogger.Log(e.ToString()); } //int MapValue = ChooseMapDropdown.value; //int ModeValue = ChooseModeDropdown.value; //PSystem.AllAiConfig = string.Empty; //PSystem.CurrentMode = PMode.ListModes().Find((PMode Mode) => Mode.Name.Equals(ChooseModeDropdown.options[ModeValue].text)); //PSystem.CurrentMap = PSystem.MapList[MapValue]; //PUIManager.AddNewUIAction("测试:转到TUI", () => PUIManager.ChangeUI<PTestUI>()); }); #endregion QuickModeToggle.onValueChanged.AddListener((bool value) => { PPlayer.Config.QuickMode = value; }); }
public PServer() { PacketSeq = 0; #region 启动服务器线程,侦听客户端的连接请求 ServerThread = new Thread(() => { #region 获取IP地址并启动监听器 IPAddress IPv4Address = PNetworkConfig.IP; Listener = new TcpListener(IPv4Address, PNetworkConfig.ServerPort); Listener.Start(); #endregion while (true) { TcpClient client = Listener.AcceptTcpClient(); PLogger.Log("收到连接请求:" + client.Client.RemoteEndPoint.ToString()); #region 判断列表是否已满,发送接受或拒绝命令给请求连接的客户端 if (CommanderList.Count < maxConnectionNumber) { #region 发送接受命令,建立和该客户端通信的命令器 lock (CommanderList) { PClientCommander commander = new PClientCommander(client); commander.Send(new PAcceptOrder()); CommanderList.Add(commander); } #endregion } else { #region 建立一个临时的命令器发送拒绝命令 new Thread(() => { PClientCommander tempCommander = new PClientCommander(client); tempCommander.Send(new PRejectOrder()); Thread.Sleep(20); tempCommander.Stop(); }) { IsBackground = true }.Start(); #endregion } #endregion } }) { IsBackground = true }; ServerThread.Start(); #endregion #region 启动信息处理线程,每10ms处理一次来自其他客户端的消息 MessageProcessor = new Thread(() => { while (true) { Thread.Sleep(10); foreach (PClientCommander commander in CommanderList) { while (commander.ReceiveNumber > 0) { string message = commander.Receive(); if (message != null) { ProcessMessage(message, commander.RemoteIPAddress); } } } } }) { IsBackground = true }; MessageProcessor.Start(); #endregion #region 启动保护线程检测掉线事件 ProtectorThread = new Thread(() => { while (true) { bool Disconnect = false; for (int i = CommanderList.Count - 1; i >= 0; --i) { if (CommanderList[i] != null) { if (!CommanderList[i].Connected) { CommanderList[i].Stop(); string DisconnectIP = CommanderList[i].RemoteIPAddress; PLogger.Log("网络断开:" + DisconnectIP); PNetworkManager.Game.Room.RemovePlayer(CommanderList[i].RemoteIPAddress); CommanderList.RemoveAt(i); Disconnect = true; } } } if (Disconnect) { if (Game.StartGameFlag) { Game.ShutDown(); PNetworkManager.AbortServer(); PUIManager.AddNewUIAction("客户端断开-返回InitialUI", () => { PUIManager.ChangeUI <PInitialUI>(); }); } else { TellClients(new PRoomDataOrder(Game.Room.ToString())); } } Thread.Sleep(20); } }) { IsBackground = true }; ProtectorThread.Start(); #endregion ChooseManager = new PChooseManager(); }