Ejemplo n.º 1
0
        // If Second > 0, print the current second
        // Otherwise, stop the current round and declare a tie
        private async Task PrintSecondOrCheckTie(DiscordMessage msg)
        {
            if (Second <= 0)
            {
                StopRoundTimer();
                // Send an embedded message describing the results of the round
                // and what words each team had
                await msg.ModifyAsync("", embed : new DiscordEmbedBuilder
                {
                    Title       = "Round ended with a TIE.",
                    Description = $"__Current scores:__ **Team1: {Team1Score} | Team2: {Team2Score}**\n" +
                                  $"__The category for this round was:__ {NounClass.TypeOfWord(Cure[CurrentCurePosition].Item2)}\n" +
                                  $"__The word for this round was:__ {Cure[CurrentCurePosition].Item1}",
                    Color = LastColorUsed
                }.Build());

                RoundResult     = -1;
                RoundInProgress = false;
            }
            else
            {
                Second--;
                // Update the message every 15 seconds, or if seconds is 7 or under
                // to avoid rate-limit problem
                if (Second <= 5 || Second % 15 == 0)
                {
                    await msg.ModifyAsync($"{Second} seconds remaining for this round.");
                }
            }
        }
Ejemplo n.º 2
0
        // Progress the round after a win
        public async Task NextRoundWIN(CommandContext ctx, bool Team1Won)
        {
            if (Team1Won)
            {
                Team1Score++;
            }
            else
            {
                Team2Score++;
            }
            // Send message after updating the scores
            await ctx.Channel.SendMessageAsync(embed : new DiscordEmbedBuilder
            {
                Title       = $"Round ended. Team {RoundResult} won!",
                Description = $"__Current scores:__ **Team1: {Team1Score} | Team2: {Team2Score}**\n" +
                              $"__The category for this round was:__ {NounClass.TypeOfWord(Cure[CurrentCurePosition].Item2)}\n" +
                              $"__The word for this round was:__ {Cure[CurrentCurePosition].Item1}",
                Color = LastColorUsed
            }.Build());

            CurrentCurePosition++;
            Round++;
            Team1Lead = null;
            Team2Lead = null;
        }
Ejemplo n.º 3
0
        // Default constructor
        public GameLogic()
        {
            // Add all words from words.json
            string json = File.ReadAllText("nouns.json");

            NounClass = JsonConvert.DeserializeObject <Nouns>(json);
            NounClass.AppendAllNouns();

            // Add all minigames from minigames.json
            json         = File.ReadAllText("minigames.json");
            AllMinigames = JsonConvert.DeserializeObject <List <Minigame> >(json);

            // Initialize ALL colors
            AllColors = new List <DiscordColor> {
                DiscordColor.Aquamarine,
                DiscordColor.Azure,
                DiscordColor.Black,
                DiscordColor.Blue,
                DiscordColor.Blurple,
                DiscordColor.Brown,
                DiscordColor.Chartreuse,
                DiscordColor.CornflowerBlue,
                DiscordColor.Cyan,
                DiscordColor.DarkBlue,
                DiscordColor.DarkButNotBlack,
                DiscordColor.DarkGray,
                DiscordColor.DarkGreen,
                DiscordColor.DarkRed,
                DiscordColor.Gold,
                DiscordColor.Goldenrod,
                DiscordColor.Gray,
                DiscordColor.Grayple,
                DiscordColor.Green,
                DiscordColor.HotPink,
                DiscordColor.IndianRed,
                DiscordColor.LightGray,
                DiscordColor.Lilac,
                DiscordColor.Magenta,
                DiscordColor.MidnightBlue,
                DiscordColor.NotQuiteBlack,
                DiscordColor.Orange,
                DiscordColor.PhthaloBlue,
                DiscordColor.PhthaloGreen,
                DiscordColor.Purple,
                DiscordColor.Red,
                DiscordColor.Rose,
                DiscordColor.SapGreen,
                DiscordColor.Sienna,
                DiscordColor.SpringGreen,
                DiscordColor.Teal,
                DiscordColor.Turquoise,
                DiscordColor.VeryDarkGray,
                DiscordColor.Violet,
                DiscordColor.Wheat,
                DiscordColor.White,
                DiscordColor.Yellow
            };
        }
Ejemplo n.º 4
0
 public IndefiniteNoun(string noun, NounClass nounClass = NounClass.It)
 {
     Noun = new Noun(noun, nounClass);
 }
Ejemplo n.º 5
0
 public Noun(string noun, NounClass nounClass = NounClass.It)
 {
     Value = noun;
     Class = nounClass;
 }
Ejemplo n.º 6
0
        // The main play function, which assumes there are enough players to play (work in progress!!!)
        public async Task PlayGame(CommandContext ctx, DiscordChannel voice)
        {
            CurrentCurePosition++; // CurrentCurePosition is now 0
            Round++;               // round is now 1
            VoiceChannel = voice;

            // Add the users in the current voice channel
            foreach (DiscordMember m in VoiceChannel.Users)
            {
                AllPlayers.Add(m, -1);
            }

            GenerateTeam();
            GenerateCure(true);

            string T1 = "**Team1:** ";
            string T2 = "**Team2:** ";

            foreach (DiscordMember m in Team1)
            {
                T1 += $"{m.DisplayName} ";
            }
            T1.TrimEnd(' ');
            foreach (DiscordMember m in Team2)
            {
                T2 += $"{m.DisplayName} ";
            }
            T2.TrimEnd(' ');

            // Send an embedded message describing the teams
            await ctx.Channel.SendMessageAsync(embed : new DiscordEmbedBuilder
            {
                Title       = $"<Welcome to Pandemic Panic!>",
                Description = $"As a deadly disease ravages the globe, you and your team of scientists must work together to find The Cure.\n" +
                              $"You will be split into two teams, each with an even number of people. During each round, one person from each team " +
                              $"will be chosen as the Head Scientist, who must coordinate their team to find a word that represents the next part of The Cure.\n" +
                              $"Guess the word before the other team and you win the round! The first to guess three words wins!\n" +
                              $"__**Be sure to check your DMs for rules of each round**__ (click the discord icon on the top left and look in your messages).\n" +
                              $"If you have a guess and are on the answering side, submit your answer with\n**!c ANSWER** in the chat. All words are singular.",
                Color = DiscordColor.Aquamarine
            }.Build());

            // Send an embedded message describing the teams
            await ctx.Channel.SendMessageAsync(embed : new DiscordEmbedBuilder
            {
                Title       = $"<TEAM FORMATIONS>",
                Description = $"{T1}\n{T2}",
                Color       = DiscordColor.Aquamarine
            }.Build());

            // Starts pre-game timer (for players to get their bearings ~30 seconds)
            Console.WriteLine("Pre-game timer started.");

            StartGenericTimer(ctx,
                              " before game starts.",
                              "The game is now starting.", 30);
            GenericTimerActive = true;

            while (GenericTimerActive)
            {
            }   // Blocks until Intermission ends

            Console.WriteLine("Pre-game period ended.");

            // Stop when either team has a score of MaxRounds (default: 3-1 = 2)
            while (Team1Score < (MaxRounds - 1) && Team2Score < (MaxRounds - 1))
            {
                PickMinigame();

                // Choose the head scientists
                PickHeadScientists(); // comment this if you're testing with only one person

                PickRoundColor();

                // Move everyone into seperate channels
                DiscordChannel T1Channel = await ctx.Guild.CreateChannelAsync("TEAM 1", DSharpPlus.ChannelType.Voice, VoiceChannel.Parent);

                DiscordChannel T2Channel = await ctx.Guild.CreateChannelAsync("TEAM 2", DSharpPlus.ChannelType.Voice, VoiceChannel.Parent);

                foreach (DiscordMember m in VoiceChannel.Users)
                {
                    int ChannelNum = AllPlayers[m];
                    Console.WriteLine($"Moving member: {m.DisplayName} to Team channel {ChannelNum}");
                    if (AllPlayers[m] == 1)
                    {
                        await T1Channel.PlaceMemberAsync(m);
                    }
                    else if (AllPlayers[m] == 2)
                    {
                        await T2Channel.PlaceMemberAsync(m);
                    }
                }

                Console.WriteLine("Distributing info");

                // Send an embedded message describing the minigame and the round
                await ctx.Channel.SendMessageAsync(embed : new DiscordEmbedBuilder
                {
                    Title       = $"<Round: {Round} | Category: {NounClass.TypeOfWord(Cure[CurrentCurePosition].Item2)}>",
                    Description = $"__Gamemode: {CurrentMinigame.Name}__\n" +
                                  $"**Team 1's head scientist:** {Team1Lead.Mention}\n" + //comment the following if testing with only one person
                                  $"**Team 2's head scientist:** {Team2Lead.Mention}\n" + //comment the following if testing with only one person
                                  CurrentMinigame.Description,
                    Color = LastColorUsed
                }.Build());

                // Distribute infomation and instructions for each player
                foreach (DiscordMember m in AllPlayers.Keys)
                {
                    // Determine who recieves what information with CurrentMinigame.WhoHasInfo and CurrentMinigame.TypeOfInfo
                    if (m == Team1Lead)
                    {
                        // Team1 Head scientist
                        if (CurrentMinigame.WhoHasInfo == InfoShare.HeadScientist)
                        {
                            // Team1 Head scientist have information
                            if (CurrentMinigame.TypeOfInfo == InfoType.Chat)
                            {
                                // Team1 Head scientist have information (chat)
                                await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                                {
                                    Title       = $"You are Team1's head scientist. Your word is '{Cure[CurrentCurePosition].Item1}'",
                                    Description = CurrentMinigame.InformedInstructions,
                                    Color       = LastColorUsed
                                }.Build());
                            }
                            else if (CurrentMinigame.TypeOfInfo == InfoType.Image)
                            {
                                // Team1 Head scientist have information (image)
                                await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                                {
                                    Title = $"You are Team1's head scientist. Your word ({NounClass.TypeOfWord(Cure[CurrentCurePosition].Item2)}) is" +
                                            " associated with the image below",
                                    Description = CurrentMinigame.InformedInstructions,
                                    Color       = LastColorUsed
                                }.Build());

                                await m.SendFileAsync(NounClass.FetchImagePath(Cure[CurrentCurePosition].Item1));
                            }
                        }
                        else if (CurrentMinigame.WhoHasInfo == InfoShare.RegularScientists)
                        {
                            // Team1 Head scientist don't have information
                            await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                            {
                                Title       = $"You are Team1's head scientist.",
                                Description = CurrentMinigame.UninformedInstructions,
                                Color       = LastColorUsed
                            }.Build());
                        }
                    }
                    else if (m == Team2Lead)
                    {
                        // Team2 Head scientist
                        if (CurrentMinigame.WhoHasInfo == InfoShare.HeadScientist)
                        {
                            // Team2 Head scientist have information
                            if (CurrentMinigame.TypeOfInfo == InfoType.Chat)
                            {
                                // Team2 Head scientist have information (chat)
                                await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                                {
                                    Title       = $"You are Team2's head scientist. Your word is '{Cure[CurrentCurePosition].Item1}'",
                                    Description = CurrentMinigame.InformedInstructions,
                                    Color       = LastColorUsed
                                }.Build());
                            }
                            else if (CurrentMinigame.TypeOfInfo == InfoType.Image)
                            {
                                // Team2 Head scientist have information (image)
                                await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                                {
                                    Title = $"You are Team2's head scientist. Your word ({NounClass.TypeOfWord(Cure[CurrentCurePosition].Item2)}) is" +
                                            " associated with the image below",
                                    Description = CurrentMinigame.InformedInstructions,
                                    Color       = LastColorUsed
                                }.Build());

                                await m.SendFileAsync(NounClass.FetchImagePath(Cure[CurrentCurePosition].Item1));
                            }
                        }
                        else if (CurrentMinigame.WhoHasInfo == InfoShare.RegularScientists)
                        {
                            // Team2 Head scientist doesn't have information
                            await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                            {
                                Title       = $"You are Team2's head scientist.",
                                Description = CurrentMinigame.UninformedInstructions,
                                Color       = LastColorUsed
                            }.Build());
                        }
                    }
                    else
                    {
                        // Regular scientist
                        if (CurrentMinigame.WhoHasInfo == InfoShare.HeadScientist)
                        {
                            // Regular scientist doesn't have info
                            await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                            {
                                Title       = $"You are a regular scientist on Team {AllPlayers[m]}.",
                                Description = CurrentMinigame.UninformedInstructions,
                                Color       = LastColorUsed
                            }.Build());
                        }
                        else if (CurrentMinigame.WhoHasInfo == InfoShare.RegularScientists)
                        {
                            if (AllPlayers[m] == 1 && m != Team1Lead)
                            {
                                // Regular scientist in team 1 have info
                                if (CurrentMinigame.TypeOfInfo == InfoType.Chat)
                                {
                                    // Regular scientist in team 1 have info (chat)
                                    await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                                    {
                                        Title       = $"You are one of Team1's many scientists. Your word is '{Cure[CurrentCurePosition].Item1}'",
                                        Description = CurrentMinigame.InformedInstructions,
                                        Color       = LastColorUsed
                                    }.Build());
                                }
                                else if (CurrentMinigame.TypeOfInfo == InfoType.Image)
                                {
                                    // Regular scientist in team 1 have info (image)
                                    await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                                    {
                                        Title = $"You are one of Team1's many scientists. Your word ({NounClass.TypeOfWord(Cure[CurrentCurePosition].Item2)}) is" +
                                                " associated with the image below",
                                        Description = CurrentMinigame.InformedInstructions,
                                        Color       = LastColorUsed
                                    }.Build());

                                    await m.SendFileAsync(NounClass.FetchImagePath(Cure[CurrentCurePosition].Item1));
                                }
                            }
                            else if (AllPlayers[m] == 2 && m != Team2Lead)
                            {
                                // Regular scientist in team 2 have info
                                if (CurrentMinigame.TypeOfInfo == InfoType.Chat)
                                {
                                    // Regular scientist in team 2 have info (chat)
                                    await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                                    {
                                        Title       = $"You are one of Team2's many scientists. Your word is '{Cure[CurrentCurePosition].Item1}'",
                                        Description = CurrentMinigame.InformedInstructions,
                                        Color       = LastColorUsed
                                    }.Build());
                                }
                                else if (CurrentMinigame.TypeOfInfo == InfoType.Image)
                                {
                                    // Regular scientist in team 2 have info (image)
                                    await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                                    {
                                        Title = $"You are one of Team2's many scientists. Your word ({NounClass.TypeOfWord(Cure[CurrentCurePosition].Item2)}) is" +
                                                " associated with the image below",
                                        Description = CurrentMinigame.InformedInstructions,
                                        Color       = LastColorUsed
                                    }.Build());

                                    await m.SendFileAsync(NounClass.FetchImagePath(Cure[CurrentCurePosition].Item1));
                                }
                            }
                        }
                    }
                }

                Console.WriteLine("Finished distributing info");

                // Starts Instruction timer (for players to get their bearings ... ~60 seconds)
                Console.WriteLine("Instruction timer started.");

                StartGenericTimer(ctx,
                                  "seconds remaining to read your instructions.",
                                  "The round is now starting.",
                                  60);
                GenericTimerActive = true;

                while (GenericTimerActive)
                {
                }   // Blocks until Intermission ends

                Console.WriteLine("Instruction period ended.");

                // Starts Round timer
                Console.WriteLine("Round timer started.");
                StartRoundTimer(ctx);
                RoundResult     = 0;
                RoundInProgress = true;

                while (RoundInProgress)
                {
                }   // Blocks until round ends

                if (RoundResult == 0)
                {
                    // We resetted the game, just return here.
                    Console.WriteLine("Finishing one game abruptly.");
                    return;
                }
                else if (RoundResult == -1)
                {
                    // Tie round
                    Console.WriteLine("Round ended with a tie.\nGenerating new but similar cures for the next round.");
                    NextRoundTIE();
                }
                else if (RoundResult != 0)
                {
                    // Update the values, then print a message
                    if (RoundResult == 1)
                    {
                        await NextRoundWIN(ctx, true);
                    }
                    else
                    {
                        await NextRoundWIN(ctx, false);
                    }
                }

                // Move everyone back into the same voice channel
                foreach (DiscordMember m in T1Channel.Users)
                {
                    Console.WriteLine($"Moving member: {m.DisplayName} to back to main voice channel");
                    await VoiceChannel.PlaceMemberAsync(m);
                }
                foreach (DiscordMember m in T2Channel.Users)
                {
                    Console.WriteLine($"Moving member: {m.DisplayName} to back to main voice channel");
                    await VoiceChannel.PlaceMemberAsync(m);
                }

                // Delete the old voice channels
                foreach (DiscordChannel d in ctx.Guild.Channels.Values)
                {
                    // If the channel's parent belong to the voice channel
                    if (d.Parent != null && d.Parent.Name == "Voice Channels")
                    {
                        if (d.Name.StartsWith("TEAM"))
                        {
                            await d.DeleteAsync("Deleting TEAM channel.");
                        }
                    }
                }

                // Starts Intermission timer
                Console.WriteLine("Intermission timer started.");
                StartGenericTimer(ctx,
                                  "seconds remaining for this intermission.",
                                  "Intermission is over.", 20); // debug was 15
                GenericTimerActive = true;

                while (GenericTimerActive)
                {
                }   // Blocks until Intermission ends

                Console.WriteLine("Intermission ended.");
            }

            string TitleMessage;

            if (Team1Score >= (MaxRounds - 1))
            {
                TitleMessage = "GAMEOVER. Team 1 wins!";
            }
            else
            {
                TitleMessage = "GAMEOVER. Team 2 wins!";
            }
            await ctx.Channel.SendMessageAsync(embed : new DiscordEmbedBuilder
            {
                Title       = TitleMessage,
                Description = $"__Current scores:__ **Team1: {Team1Score} | Team2: {Team2Score}**\n" +
                              $"__The cure was:__ {GetCure()}",
                Color = LastColorUsed
            }.Build());

            await ctx.Channel.SendMessageAsync("The game is now over, type !sg while in a voice channel with at least 4 players to start a new game!");

            StopGame();
        }