示例#1
0
        public async Task GuessALetter(string letter)
        {
            if (!ActiveGames.ContainsKey(Context.Channel) && ActiveGames[Context.Channel].GetType() != typeof(Hangman))
            {
                await ReplyAsync($"You must first start a game of hangman!");

                return;
            }

            if (letter.Length > 1)
            {
                await ReplyAsync($"You can only guess a single letter at a time! Try [!WordIs] to guess a word.");

                return;
            }

            if (QuestionAsked)
            {
                await Context.Channel.SendMessageAsync($"Please respond to the question before continuing... {ActiveGames[Context.Channel].Question}");

                return;
            }

            //TODO: Is there a better way to do this?
            Hangman currentGame = ActiveGames[Context.Channel] as Hangman;
            await currentGame.GuessALetter(letter.ToLower()[0]);
        }
示例#2
0
        public async Task Start(string Category)
        {
            if (!UserIsGameMater((SocketGuildUser)Context.User))
            {
                await ReplyAndDeleteAsync(":x: You are not the gamemaster. " + Context.User.Mention, timeout : new TimeSpan(0, 0, 15));

                return;
            }

            string folderPath = @$ "{ Directory.GetCurrentDirectory()}/Category/";

            if (!File.Exists(folderPath + Category + ".caty"))
            {
                await ReplyAndDeleteAsync($"Category does not exist", timeout : new TimeSpan(0, 0, 15));

                return;
            }


            var words = File.ReadAllLines(folderPath + Category + ".caty");

            if (words.Length < 1)
            {
                await ReplyAndDeleteAsync($"There are no words in **{Category}**", timeout : new TimeSpan(0, 0, 15));

                return;
            }

            var c = Context.Guild.CategoryChannels.SingleOrDefault(x => x.Name == "Games");

            if (c == null)
            {
                Console.WriteLine("There is no Category named Games");
                return;
            }

            RestTextChannel Room = await Context.Guild.CreateTextChannelAsync($"Hangman-{Category}-{_games.Count + 1}", x => {
                x.CategoryId = c.Id;
            });

            if (Room == null)
            {
                Console.WriteLine("Something went wrong");
                return;
            }

            Hangman game = new Hangman(Room.Id, Context.Client, words);

            _games.Add(game);

            await ReplyAndDeleteAsync($"A Game Has started on <#{Room.Id}>", timeout : new TimeSpan(0, 0, 15));

            game.Start();
        }
示例#3
0
        public async Task GuessTheWord(string guessedWord)
        {
            if (!ActiveGames.ContainsKey(Context.Channel))
            {
                await ReplyAsync($"You must first start a game of hangman!");

                return;
            }

            if (QuestionAsked)
            {
                await Context.Channel.SendMessageAsync($"Please respond to the question before continuing... {ActiveGames[Context.Channel].Question}");

                return;
            }

            //TODO: Is there a better way to do this?
            Hangman currentGame = ActiveGames[Context.Channel] as Hangman;
            await currentGame.GuessAWord(guessedWord);
        }