/// <summary> /// 处理用户的放置单位请求并返回消息 /// </summary> /// <param name="UserName"></param> /// <param name="PatternName"></param> /// <param name="x"></param> /// <param name="y"></param> void PlaceUnit(string UserName, string PatternName, int x, int y, GameBoard.PatternGameBoard.RoationMode roation = GameBoard.PatternGameBoard.RoationMode.None, GameBoard.PatternGameBoard.FlipMode flip = GameBoard.PatternGameBoard.FlipMode.None) { if (TeamOf.Keys.Contains(UserName) && !TeamsOKToAttack.Contains(TeamOf[UserName])) { if (Info.AllowRoation) { Info.Patterns[PatternName].Roation = roation; } if (Info.AllowFlip) { Info.Patterns[PatternName].Flip = flip; } if (RemainUnits[TeamOf[UserName]][PatternName] > 0) { if (GameBoards[TeamOf[UserName]].PutPatern(Info.Patterns[PatternName], x, y, Info.cornorMode)) { RemainUnits[TeamOf[UserName]][PatternName]--; foreach (string name in Teams[TeamOf[UserName]]) { Server.SendTo(name, "SBAR|已放置单位"); Server.SendTo(name, "GBRD|" + GameBoards[TeamOf[UserName]].ToString()); Server.SendTo(name, "UCNT|" + PatternName + '|' + RemainUnits[TeamOf[UserName]][PatternName]); } } else { Server.SendTo(UserName, "SBAR|放置失败,空间不足"); } } else { Server.SendTo(UserName, "SBAR|放置失败,剩余单位不足"); } } }
void ResetBoard(string UserName) { if (TeamOf.Keys.Contains(UserName) && !TeamsOKToAttack.Contains(TeamOf[UserName])) { RemainUnits[TeamOf[UserName]] = GetNewUnitCount(); GameBoards[TeamOf[UserName]] = Info.Mask.GetFullPlayerGameBoard(); foreach (string name in Teams[TeamOf[UserName]]) { Server.SendTo(name, "SBAR|已清空棋盘"); Server.SendTo(name, "GBRD|" + GameBoards[TeamOf[UserName]].ToString()); foreach (var Unit in RemainUnits[TeamOf[UserName]]) { Server.SendTo(name, "UCNT|" + Unit.Key + '|' + Unit.Value); } } } }
void StartPUState() { //初始化 TeamOf.Clear(); GameBoards.Clear(); Teams.Clear(); RemainUnits.Clear(); TeamsOKToAttack.Clear(); for (int i = 0; i < Info.TeamCount; i++) { Teams.Add(new List <string>()); GameBoards.Add(Info.Mask.GetFullPlayerGameBoard()); RemainUnits.Add(GetNewUnitCount()); } foreach (string Name in OnlinePlayers) { GetTeam(Name); } }