コード例 #1
0
        public async Task CreateWordAsync()
        {
            HangmanService _service = new HangmanService(new UnitOfWork(GetContext()));
            string         val      = "hkjkjkjkjkjkjkjkjkj";

            if (val.Length < 25)
            {
                int count = 0;
                for (int i = 1; i < val.Length; i++)
                {
                    if (val[i - 1] == val[i])
                    {
                        count++;
                    }
                }

                if (count >= val.Length - 1)
                {
                    Debug.WriteLine("Come on that's not a word, that's a keyboard smash!!");
                }
                else
                {
                    var   task = _service.Create(val);
                    await task;
                    Debug.WriteLine("The word has been added successfully!");
                }
            }
        }
コード例 #2
0
        public async Task HangmanAsync()
        {
            if (HangmanService.Started)
            {
                return;
            }
            var message = await ReplyAsync($"Hangman Starting Soon!");

            HangmanService.StartGame(message);
        }
コード例 #3
0
 public void GetRandomWord()
 {
     try
     {
         HangmanService _service = new HangmanService(new UnitOfWork(GetContext()));
         var            task     = _service.GetRandom();
         Assert.NotNull(task);
         Debug.WriteLine(task.Descripcion);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
         Assert.False(false);
     }
 }
コード例 #4
0
        public async Task DeleteWord()
        {
            try
            {
                HangmanService _service = new HangmanService(new UnitOfWork(GetContext()));
                await _service.Remove("Maguwhite");

                Assert.True(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Assert.False(false);
            }
        }
コード例 #5
0
ファイル: Hangman.cs プロジェクト: benharri/dotbot
 public Hangman(HangmanService hangman)
 {
     _games = hangman._activeGames;
 }
コード例 #6
0
        public async Task HangmanCommand()
        {
            if (Cache.HangmanInProgress.ContainsKey(Context.Channel.Id))
            {
                await RespondAsync(":game_die: There is a game in progress in this channel!");

                return;
            }

            var logger = _loggerFactory.CreateLogger("Hangman");

            Cache.HangmanInProgress[Context.Channel.Id] = null;

            try
            {
                var card = await YuGiOhDbService.GetRandomCardAsync();

                logger.Info(card.Name);

                var cts            = new CancellationTokenSource();
                var hangmanService = new HangmanService(card.Name);

                var criteria = BaseCriteria
                               .AddCriterion(new NotCommandCriteria(GuildConfig))
                               .AddCriterion(new NotInlineSearchCriteria());

                if (!GuildConfig.HangmanAllowWords)
                {
                    criteria.AddCriterion(new CharacterOnlyCriteria());
                }

                var time = TimeSpan.FromSeconds(GuildConfig.HangmanTime);

                await RespondAsync("You can now type more than a letter for hangman!\n" +
                                   $"As well as change the hangman time ({GuildConfig.Prefix}hangmantime <seconds>)! Ask an admin about it!\n" +
                                   $"You may also disable the ability to input more than one letter! ({GuildConfig.Prefix}hangmanwords <true/false>)\n" +
                                   $"You have **{time.ToPrettyString()}**!\n" +
                                   hangmanService.GetCurrentDisplay());

                var        _    = new Timer((cancelTokenSrc) => (cancelTokenSrc as CancellationTokenSource) !.Cancel(), cts, TimeSpan.FromSeconds(GuildConfig.HangmanTime), Timeout.InfiniteTimeSpan);
                SocketUser user = null;

                do
                {
                    var input = await NextMessageAsync(criteria, token : cts.Token);

                    if (cts.IsCancellationRequested)
                    {
                        break;
                    }

                    user = input.Author;

                    switch (hangmanService.AddGuess(input.Content))
                    {
                    case GuessStatus.Duplicate:
                        await ReplyAsync($"You already guessed `{input}`!\n" +
                                         hangmanService.GetCurrentDisplay());

                        break;

                    case GuessStatus.Nonexistent:
                        await ReplyAsync($"```fix\n{hangmanService.GetHangman()}```\n" +
                                         hangmanService.GetCurrentDisplay());

                        break;

                    case GuessStatus.Accepted:
                        await ReplyAsync(hangmanService.GetCurrentDisplay());

                        break;
                    }
                } while (!cts.IsCancellationRequested && hangmanService.CompletionStatus == CompletionStatus.Incomplete);

                if (cts.IsCancellationRequested)
                {
                    await ReplyAsync($"Time is up! No one won! The card is `{hangmanService.Word}`");
                }
                else
                {
                    switch (hangmanService.CompletionStatus)
                    {
                    case CompletionStatus.Complete:
                        await ReplyAsync($":trophy: The winner is **{(user as SocketGuildUser)!.Nickname ?? user!.Username}**!");

                        break;

                    case CompletionStatus.Hanged:
                        await ReplyAsync($"You have been hanged! The card was `{hangmanService.Word}`.");

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "There was a problem with hangman");
            }
            finally
            {
                Cache.HangmanInProgress.TryRemove(Context.Channel.Id, out _);
            }
        }
コード例 #7
0
 public GamePageModel(HangmanService hangman)
 {
     this.hg = hangman;
     hg.Load();
 }
コード例 #8
0
 public IndexModel(ILogger <IndexModel> logger, HangmanService hangman)
 {
     _logger = logger;
     this.hg = hangman;
     hg.Load();
 }
コード例 #9
0
        public ActionResult InitializeHangmanGame([FromBody] HangmanParameters param)
        {
            AccessGuardian(Roles.AccessUser, param.UserId);

            return(JsonHelper.Success(HangmanService.InitializeQuestions(param)));
        }
コード例 #10
0
 public HangmanModule(HangmanService hangman)
 {
     _hangman = hangman;
 }