예제 #1
0
 private async Task PreviewBoard(TaflConfiguration taflConfiguration)
 {
     TaflConfiguration = taflConfiguration;
     Board             = new TaflBoard(taflConfiguration, this);
     _background       = DrawBoard();
     _boardIndex       = DrawBoardIndex();
     var board = Draw();
     await _ch.SendFileAsync(board, $"Now previewing {taflConfiguration.Name}.").ConfigureAwait(false);
 }
예제 #2
0
        public void Start()
        {
            Task.Run(async() =>
            {
                var interactivity = _client.GetInteractivity();

                TaflConfiguration = await PickBoard().ConfigureAwait(false);
                Board             = new TaflBoard(TaflConfiguration, this);
                _background       = DrawBoard();
                _boardIndex       = DrawBoardIndex();

                var board = Draw();
                await _ch.SendFileAsync(board, $"Tafl game has started!").ConfigureAwait(false);
                var startMsg = $"{_blackPlayer.DisplayName}(Black) goes first!\n";
                startMsg    += $"Type 'help' for help, or 'quit' to quit game.\n";
                startMsg    += $"For detailed rules, click here: <http://aagenielsen.dk/tafl_rules.php>";
                await _ch.SendMessageAsync(startMsg).ConfigureAwait(false);

                CurrentPlayer = Piece.Black;
                var curPlayer = _blackPlayer;
                while (true)
                {
                    var afk    = false;
                    var isMove = false;
                    while (!isMove)
                    {
                        var response = await interactivity.WaitForMessageAsync(x => x.Author.Id == curPlayer.Id && x.ChannelId == _ch.Id).ConfigureAwait(false);
                        if (response.TimedOut)
                        {
                            await _ch.SendMessageAsync($"This channel will be deleted soon unless there is activity.").ConfigureAwait(false);
                            if (afk)
                            {
                                await Dispose().ConfigureAwait(false);
                            }
                            afk = true;
                            continue;
                        }
                        isMove = await TryMove(response.Result.Content.ToLower()).ConfigureAwait(false);
                        afk    = false;
                    }
                    board = Draw();
                    await _ch.SendFileAsync(board).ConfigureAwait(false);
                    var color = CurrentPlayer == Piece.Black ? "Black" : "White";
                    if (Board.HasWin())
                    {
                        await _ch.SendMessageAsync($"{curPlayer.DisplayName}({color}) has won the game!").ConfigureAwait(false);
                        break;
                    }
                    if (CurrentPlayer == Piece.Black)
                    {
                        CurrentPlayer = Piece.White;
                        curPlayer     = _whitePlayer;
                        color         = "White";
                    }
                    else
                    {
                        CurrentPlayer = Piece.Black;
                        curPlayer     = _blackPlayer;
                        color         = "Black";
                    }
                    await _ch.SendMessageAsync($"{curPlayer.DisplayName}({color})'s turn to move!").ConfigureAwait(false);
                }
                await Dispose().ConfigureAwait(false);
            });
        }