示例#1
0
 public Morpion(MorpionPlayer j1, MorpionPlayer j2)
 {
     isWon   = false;
     this.j1 = j1;
     this.j2 = j2;
     for (int i = 0; i < 3; i++)
     {
         for (int j = 0; j < 3; j++)
         {
             array[i, j] = 0;
         }
     }
 }
示例#2
0
        /// <summary>
        /// Makes the player's move, updates the game.
        /// </summary>
        /// <param name="content">A string sent by the user.</param>
        /// <param name="playerName">The username</param>
        /// <returns>
        /// The string containing the visual display of the game,
        /// or one of the error messages
        /// </returns>
        internal string step(int content, string playerName)
        {
            string returnString = "";

            if (first)
            {
                if (playerName == j1.discordName)
                {
                    current = j1;
                    first   = false;
                }
                if (playerName == j2.discordName)
                {
                    current = j2;
                    first   = false;
                }
            }

            int[] positions = parsePositions(content);

            if (array[positions[0], positions[1]] != 0)
            {
                returnString += "Quelqu'un a déjà joué ici :angry:" + Environment.NewLine;
                returnString += display();
            }
            else if (playerName != current.discordName)
            {
                returnString += "Ce n'est pas à vous de jouer !" + Environment.NewLine;
                returnString += display();
            }
            else
            {
                array[positions[0], positions[1]] = current.value;
                current       = (current == j1) ? j2 : j1;
                returnString += display();
            }

            isWon = getWon();
            isEnd = getDraw() && !isWon;

            return(returnString);
        }
示例#3
0
文件: Program.cs 项目: mguerny/Botana
        private async Task MessageReceived(SocketMessage message)
        {
            if (message.Author.Id == _client.CurrentUser.Id)
            {
                return;
            }

            bool allowedChannel = true;

            foreach (string line in channels)
            {
                if (message.Channel.Id == ulong.Parse(line))
                {
                    allowedChannel = true;
                }
            }

            if (!allowedChannel)
            {
                return;
            }

            if (message.Content.StartsWith("!help"))
            {
                Help help = new Help(message.Content);
                await message.Channel.SendMessageAsync(help.help);
            }

            if (message.Content == "!ping")
            {
                await message.Channel.SendMessageAsync("Raspy Pong!");
            }

            if (message.Content.StartsWith("!mot"))
            {
                Mot mot = new Mot();
                await message.Channel.SendMessageAsync(mot.value);
            }

            if (message.Content == "!wedzcode")
            {
                Humor humor = new Humor();
                await message.Channel.SendMessageAsync(humor.imageUrl);
            }

            if ((message.Content.StartsWith("!pendu") && !gameStarted) || penduStarted)
            {
                if (!penduStarted)
                {
                    penduStarted = true;
                    gameStarted  = true;
                    pendu        = new Pendu();
                    penduDisplay = await message.Channel.SendMessageAsync(pendu.guess);
                }
                else
                {
                    if (message.Content.Length > 1 || !Char.IsLetter(message.Content[0]))
                    {
                        await updatePendu(message, null);
                    }
                    else
                    {
                        string toDisplay = pendu.step(message.Content[0]);
                        await updatePendu(message, toDisplay);

                        await message.DeleteAsync();

                        if (pendu.isFinished || pendu.isWon)
                        {
                            penduStarted = false;
                            gameStarted  = false;
                        }
                    }
                }
            }

            if ((message.Content == "!morpion" && !gameStarted) || morpionStarted)
            {
                if (!morpionStarted)
                {
                    if (j1 == null)
                    {
                        j1 = new MorpionPlayer(message.Author.Username, 1);
                    }
                    else
                    {
                        j2             = new MorpionPlayer(message.Author.Username, 2);
                        gameStarted    = true;
                        morpionStarted = true;
                        morpion        = new Morpion(j1, j2);
                        await message.Channel.SendMessageAsync("Jouer avec le pavé numérique (en haut à droite => 9)");

                        morpionDisplay = await message.Channel.SendMessageAsync(morpion.display());
                    }
                }
                else
                {
                    int  n         = 0;
                    bool isNumeric = int.TryParse(message.Content, out n);

                    if (!isNumeric || n < 1 || n > 9)
                    {
                        await updateMorpion(message, null);
                    }
                    else
                    {
                        await updateMorpion(message, morpion.step(n, message.Author.Username));

                        await message.DeleteAsync();

                        if (morpion.isWon)
                        {
                            string winner = message.Author.Mention;
                            winner += " a gagné !";
                            await message.Channel.SendMessageAsync(winner);

                            gameStarted    = false;
                            morpionStarted = false;
                            j1             = null;
                            j2             = null;
                        }
                        if (morpion.isEnd)
                        {
                            await message.Channel.SendMessageAsync("Égalité");

                            gameStarted    = false;
                            morpionStarted = false;
                            j1             = null;
                            j2             = null;
                        }
                    }
                }
            }
        }