private void PrintStartMessage(string group, PlayGround game) { var message = new StringBuilder("开始游戏!\n"); message.AppendLine("---------------------------------"); message.AppendLine("命令列表: (您随时都可以使用/help查看命令)"); message.AppendLine(" 落子: x坐标y坐标"); message.AppendLine(" 退出: /ge"); message.AppendLine(" 投降: /gf"); message.AppendLine(" 投票结束: /ve"); message.AppendLine(" 查看Gomoku Credit: /gc"); message.AppendLine(" 查看Gomoku Credit排行榜: /gt"); message.AppendLine("---------------------------------"); switch (game.Role) { case Role.Black: message.Append($"黑方:{CqCode.At(game.BlackPlayer)}先手!请{CqCode.At(game.BlackPlayer)}走子!"); break; case Role.White: message.Append($"白方:{CqCode.At(game.WhitePlayer)}先手!请{CqCode.At(game.WhitePlayer)}走子!"); break; default: throw new ArgumentOutOfRangeException(); } _mahuaApi.SendGroupMessage(group) .Text(message.ToString()) .Newline() .Text(CqCode.Image($"{game.GameId}\\ChessBoard_{game.Steps}.jpg")) .Done(); }
private void PlayerJoinGame(PlayGround game, GroupMessageReceivedContext context) { var result = game.PlayerJoinGame(context.FromQq); switch (result) { case PlayerJoinStat.GameFull: _mahuaApi.SendGroupMessage(context.FromGroup, "游戏已满,请等待游戏结束"); return; case PlayerJoinStat.HaveJoined: _mahuaApi.SendGroupMessage(context.FromGroup, "你已经加入过了"); return; case PlayerJoinStat.Success: if (game.GameFull) { _mahuaApi.SendGroupMessage(context.FromGroup, $"白方:{CqCode.At(context.FromQq)}成功加入!"); game.StartGame(); PrintStartMessage(context.FromGroup, game); } else { _mahuaApi.SendGroupMessage(context.FromGroup, $"黑方:{CqCode.At(context.FromQq)}成功加入!"); } return; default: throw new ArgumentOutOfRangeException(); } }
public void Handle(CommandContext context, GomokuPlayerJoinGameCommand command, params object[] handleObjects) { var game = (PlayGround)handleObjects[0]; var mahuaApi = CommandFactory.GetMahuaApi(); var result = game.PlayerJoinGame(context.From); switch (result) { case PlayerJoinStat.GameFull: mahuaApi.SendGroupMessage(context.FromGroup, "游戏已满,请等待游戏结束"); return; case PlayerJoinStat.HaveJoined: mahuaApi.SendGroupMessage(context.FromGroup, "你已经加入过了"); return; case PlayerJoinStat.Success: if (game.GameFull) { mahuaApi.SendGroupMessage(context.FromGroup, $"白方:{CqCode.At(context.From)}成功加入!"); game.StartGame(); PrintStartMessage(context.FromGroup, game, mahuaApi); } else { mahuaApi.SendGroupMessage(context.FromGroup, $"黑方:{CqCode.At(context.From)}成功加入!"); } return; default: throw new ArgumentOutOfRangeException(); } }
public void Handle(CommandContext context, GomokuPlayerSurrenderCommand command, params object[] handleObjects) { var game = (PlayGround)handleObjects[0]; var mahuaApi = CommandFactory.GetMahuaApi(); if (game.IsActivatedAndValid(context.From)) { var isBlackWin = game.BlackPlayer != context.From; mahuaApi.SendGroupMessage(context.FromGroup) .Text($"{CqCode.At(context.From)}选择了投降!") .Newline() .Text(game.GetWinMessage(isBlackWin)) .Done(); } }
public void Handle(CommandContext context, GomokuPlayerVoteEndCommand command, params object[] handleObjects) { var game = (PlayGround)handleObjects[0]; var mahuaApi = CommandFactory.GetMahuaApi(); if (game.IsActivatedAndValid(context.From)) { if (game.VoteForEnd.isVoting && game.IsMessageFromPlayer(context.From) && context.From != game.VoteForEnd.qq) { mahuaApi.SendGroupMessage(context.FromGroup, $"投票通过,结束ID为{game.GameId}的游戏"); game.Dispose(); } else if (!game.VoteForEnd.isVoting && game.IsMessageFromPlayer(context.From)) { mahuaApi.SendGroupMessage(context.FromGroup, $"{CqCode.At(context.From)}发起结束游戏投票!同意请输入/ve"); game.VoteForEnd = (context.From, true); } } }
public void Handle(CommandContext context, GomokuPlayerExitCommand command, params object[] handleObjects) { var game = (PlayGround)handleObjects[0]; if (game != null && game.IsMessageFromPlayer(context.From)) { var sb = new StringBuilder(); sb.Append($"{CqCode.At(context.From)}离开游戏,游戏结束!"); if (game.GameStarted) { sb.Append($"\n根据退赛惩罚机制,{CqCode.At(context.From)}将会被扣除20000点Gomoku Credit"); GomokuCredit.SetOrIncreaseCredit(context.From, -30000); } CommandFactory.GetMahuaApi().SendGroupMessage(context.FromGroup, sb.ToString()); game.Dispose(); } }
public void Handle(CommandContext context, GomokuPlayerGoCommand command, params object[] handleObjects) { var game = (PlayGround)handleObjects[0]; var mahuaApi = CommandFactory.GetMahuaApi(); if (game.IsActivatedAndValid(context.From) && game.IsBlackOrWhiteTurn(context.From)) { var dropResult = game.ProcessGoCommand(context.Message); switch (dropResult.GameState) { case GameState.Success: mahuaApi.SendGroupMessage(context.FromGroup) .Text($"{(game.Role == Role.White ? "黑方成功落子" : "白方成功落子")}: [{dropResult.DropPoint.X},{Axis.NumberToYAxis(dropResult.DropPoint.Y)}]") .Newline() .Text(CqCode.Image($"{game.GameId}\\ChessBoard_{game.Steps}.jpg")) .Done(); break; case GameState.IllegalDropLocation: mahuaApi.SendGroupMessage(context.FromGroup, "诶呀,您落子的位置好像不太合理,再重新试试吧?"); return; case GameState.AbortCuzChessBoardFull: mahuaApi.SendGroupMessage(context.FromGroup) .Text("棋盘上已经没有地方了,和棋!") .Newline() .Text("游戏结束!") .Done(); game.Dispose(); return; case GameState.IrrelevantMessage: return; default: throw new ArgumentOutOfRangeException(); } var winResult = game.IsWin(dropResult.DropPoint.X, dropResult.DropPoint.Y); if (winResult != Chessman.Empty) { var isBlackWin = winResult == Chessman.Black; mahuaApi.SendGroupMessage(context.FromGroup, game.GetWinMessage(isBlackWin)); } else { mahuaApi.SendGroupMessage(context.FromGroup, $"请{(game.Role == Role.White ? $"白方{CqCode.At(game.WhitePlayer)}走子!" : $"黑方{CqCode.At(game.BlackPlayer)}走子!")}"); } } }