예제 #1
0
        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();
        }
 public void ProcessGroupMessage(GroupMessageReceivedContext context)
 {
     if (context.Message.StartsWith("/image") && context.FromQq == Configuration.Me)
     {
         var image = context.Message.Substring(7);
         _mahuaApi.SendGroupMessage(context.FromGroup, CqCode.Image(image));
     }
 }
예제 #3
0
        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)}走子!")}");
                }
            }
        }