예제 #1
0
파일: Game.cs 프로젝트: Damitrix/Sabrina
        public async Task BlackjackAsync(CommandContext ctx, int betEdges)
        {
            if (betEdges < 1)
            {
                await ctx.RespondAsync("No. >.<");

                return;
            }

            if (betEdges > 30)
            {
                await ctx.RespondAsync("Sorry, max bet is 20 for now");

                return;
            }

            // Create a new Game and Deal to Player and House
            var game        = new BlackJackGame(betEdges, ctx);
            var playerHolds = false;

            await ctx.RespondAsync("Game Start!\n");

            string drawingsText = string.Empty;

            drawingsText +=
                $"You draw a **{game.PlayerCards[0].Variation.ToString()} __{game.PlayerCards[0].Value.ToString()}__**\n";
            drawingsText +=
                $"You draw a **{game.PlayerCards[1].Variation.ToString()} __{game.PlayerCards[1].Value.ToString()}__**\n";
            drawingsText +=
                $"The House draws a {game.HouseCards[0].Variation.ToString()} __{game.HouseCards[0].Value.ToString()}__\n";
            drawingsText += $"The House draws a Card.\n";

            await ctx.RespondAsync(drawingsText);

            if (BlackJackGame.IsBlackJack(game.PlayerCards) && BlackJackGame.IsBlackJack(game.HouseCards))
            {
                // Both Blackjack, push
                await ctx.RespondAsync("Both of you have Blackjack!");

                game.OnNeutral();
                return;
            }

            if (BlackJackGame.IsBlackJack(game.HouseCards))
            {
                // House Blackjack, House wins
                await ctx.RespondAsync("House has BlackJack!");

                game.OnLoose();
                return;
            }

            // Loop as long as Player does not hold
            while (!game.PlayerBusts && !playerHolds && !BlackJackGame.IsBlackJack(game.PlayerCards))
            {
                await ctx.RespondAsync("Hit or Stand?");

                var m = await ctx.Client.GetInteractivity().WaitForMessageAsync(
                    x => x.Channel.Id == ctx.Channel.Id && x.Author.Id == ctx.Member.Id &&
                    Regex.IsMatch(x.Content, HitStayRegex),
                    TimeSpan.FromSeconds(60));

                if (!m.TimedOut)
                {
                    await ctx.RespondAsync(
                        $"You didn't answer me in 60 seconds, i see that as *giving up*. Well, {game.BetEdges} Edges to your wallet :)");

                    await ctx.RespondAsync("House wins.");

                    game.OnLoose();
                }

                // If user says hit
                if (Regex.IsMatch(m.Result.Content, HitRegex))
                {
                    game.DrawCardPlayer();
                    await ctx.RespondAsync(
                        $"You got a {game.PlayerCards[game.PlayerCards.Count - 1].Variation.ToString()} {game.PlayerCards[game.PlayerCards.Count - 1].Value.ToString()}");
                }

                // If user says stand
                else if (Regex.IsMatch(m.Result.Content, StandRegex))
                {
                    await ctx.RespondAsync("You Stand.");

                    playerHolds = true;
                }
            }

            if (game.PlayerBusts)
            {
                // House Wins#
                await ctx.RespondAsync("You bust!");

                game.OnLoose();
                return;
            }

            if (BlackJackGame.IsBlackJack(game.PlayerCards))
            {
                if (game.HouseCards[0].Value == BlackJackGame.Card.CardValue.Ace)
                {
                    // Ask for even
                    await ctx.RespondAsync(
                        "You have a Blackjack, but the House has an Ace, do you want to take even money?");

                    var m = await ctx.Client.GetInteractivity().WaitForMessageAsync(
                        x => x.Channel.Id == ctx.Channel.Id && x.Author.Id == ctx.Member.Id &&
                        Regex.IsMatch(x.Content, ConfirmRegex));

                    if (m.TimedOut)
                    {
                        await ctx.RespondAsync(
                            $"You didn't answer me in 60 seconds, i see that as *giving up*. Well, {game.BetEdges} Edges to your wallet :)");

                        await ctx.RespondAsync("House wins.");

                        game.OnLoose();
                    }

                    if (Regex.IsMatch(m.Result.Content, YesRegex))
                    {
                        // Even Money
                        await ctx.RespondAsync("Alrighty! Even it is.");

                        return;
                    }

                    await ctx.RespondAsync("Good Luck.");
                }
                else
                {
                    // Player wins with BlackJack (3/2)
                    await ctx.RespondAsync("Blackjack! You win!");

                    game.OnSpecialWin();
                    return;
                }
            }
            else
            {
                if (game.HouseCards[0].Value == BlackJackGame.Card.CardValue.Ace)
                {
                    // Ask for even
                    await ctx.RespondAsync("House has an Ace, do you want to take insurance?");

                    var m = await ctx.Client.GetInteractivity().WaitForMessageAsync(
                        x => x.Channel.Id == ctx.Channel.Id && x.Author.Id == ctx.Member.Id &&
                        Regex.IsMatch(x.Content, ConfirmRegex));

                    if (m.TimedOut)
                    {
                        await ctx.RespondAsync(
                            $"You didn't answer me in 60 seconds, i see that as *giving up*. Well, {game.BetEdges} Edges to your wallet :)");

                        await ctx.RespondAsync("House wins.");

                        game.OnLoose();
                    }

                    if (Regex.IsMatch(m.Result.Content, YesRegex))
                    {
                        // Insurance
                        await ctx.RespondAsync("Alrighty! Insurance it is.");

                        game.OnNeutral();
                        return;
                    }

                    await ctx.RespondAsync("Good Luck.");
                }
            }

            // Flip House' Card
            await ctx.RespondAsync(
                $"House' Card #2 is a {game.HouseCards[game.HouseCards.Count - 1].Variation.ToString()} {game.HouseCards[game.HouseCards.Count - 1].Value.ToString()}\n");

            // Draw for House while Value is under 17
            while (BlackJackGame.GetMaxSumWithoutOvershoot(game.HouseCards) < 17)
            {
                game.DrawCardHouse();
                await ctx.RespondAsync(
                    $"House got a {game.HouseCards[game.HouseCards.Count - 1].Variation.ToString()} {game.HouseCards[game.HouseCards.Count - 1].Value.ToString()}\n");

                if (BlackJackGame.GetMaxSumWithoutOvershoot(game.HouseCards)
                    == BlackJackGame.GetMaxSumWithoutOvershoot(game.PlayerCards))
                {
                    // Draw, no one wins
                    await ctx.RespondAsync("It's a Draw!");

                    game.OnNeutral();
                    return;
                }

                if (BlackJackGame.GetMinSum(game.HouseCards) > 21)
                {
                    // House overshoots, you win
                    await ctx.RespondAsync("House busts. You win!");

                    game.OnWin();
                    return;
                }
            }

            if (BlackJackGame.IsBlackJack(game.PlayerCards) && BlackJackGame.IsBlackJack(game.HouseCards))
            {
                // Both Blackjack, push
                await ctx.RespondAsync("Both have Blackjack!");

                game.OnNeutral();
                return;
            }

            if (BlackJackGame.GetMaxSumWithoutOvershoot(game.HouseCards)
                == BlackJackGame.GetMaxSumWithoutOvershoot(game.PlayerCards))
            {
                // Draw, no one wins
                await ctx.RespondAsync("It's a Draw!");

                game.OnNeutral();
                return;
            }

            if (BlackJackGame.GetMaxSumWithoutOvershoot(game.HouseCards)
                > BlackJackGame.GetMaxSumWithoutOvershoot(game.PlayerCards))
            {
                // House wins
                await ctx.RespondAsync("House wins.");

                game.OnLoose();
            }
            else if (BlackJackGame.IsBlackJack(game.PlayerCards))
            {
                // Player wins cause of more Points AND Blackjack, so Money is 3/2
                await ctx.RespondAsync("You win!");

                game.OnSpecialWin();
            }
            else
            {
                // Player wins cause of more Points
                await ctx.RespondAsync("You win!");

                game.OnWin();
            }
        }
예제 #2
0
        public async Task Blackjack(CommandContext ctx, int betEdges)
        {
            betEdges = 5;
            //Create a new Game and Deal to Player and House
            var  game        = new BlackJackGame(betEdges);
            bool playerHolds = false;

            await ctx.RespondAsync("Game Start!\n");

            string drawingsText = "";

            drawingsText +=
                $"You draw a {game.PlayerCards[0].Variation.ToString()} {game.PlayerCards[0].Value.ToString()}\n";
            drawingsText += $"The House draws a {game.HouseCards[0].Variation.ToString()} {game.HouseCards[0].Value.ToString()}\n";

            drawingsText +=
                $"You draw a {game.PlayerCards[1].Variation.ToString()} {game.PlayerCards[1].Value.ToString()}\n";
            drawingsText += $"The House draws a Card.\n";

            await ctx.RespondAsync(drawingsText);

            if (BlackJackGame.IsBlackJack(game.PlayerCards) && BlackJackGame.IsBlackJack(game.HouseCards))
            {
                //Both Blackjack, push
                await ctx.RespondAsync("It's a Draw!");

                return;
            }

            if (BlackJackGame.IsBlackJack(game.HouseCards))
            {
                //House Blackjack, House wins
                await ctx.RespondAsync("House wins.");

                return;
            }

            //Loop as long as Player does not hold
            while (!game.PlayerBusts && !playerHolds && !BlackJackGame.IsBlackJack(game.PlayerCards))
            {
                await ctx.RespondAsync("Hit or Stand?");

                var m = await dep.Interactivity.WaitForMessageAsync(
                    x => x.Channel.Id == ctx.Channel.Id &&
                    x.Author.Id == ctx.Member.Id &&
                    Regex.IsMatch(x.Content, HitStayRegex));

                if (Regex.IsMatch(m.Message.Content, HitRegex))
                {
                    game.DrawCardPlayer();
                    await ctx.RespondAsync($"You got a {game.PlayerCards[game.PlayerCards.Count - 1].Variation.ToString()} {game.PlayerCards[game.PlayerCards.Count - 1].Value.ToString()}");
                }

                else if (Regex.IsMatch(m.Message.Content, StandRegex))
                {
                    await ctx.RespondAsync("You Stand.");

                    playerHolds = true;
                }
            }

            if (game.PlayerBusts)
            {
                //House Wins#
                await ctx.RespondAsync("You bust!");

                return;
            }

            if (BlackJackGame.IsBlackJack(game.PlayerCards))
            {
                if (game.HouseCards[0].Value == BlackJackGame.Card.CardValue.Ace)
                {
                    //Ask for even

                    await ctx.RespondAsync("You have a Blackjack, but the House has an Ace, do you want to take even money?");

                    var m = await dep.Interactivity.WaitForMessageAsync(
                        x => x.Channel.Id == ctx.Channel.Id &&
                        x.Author.Id == ctx.Member.Id &&
                        Regex.IsMatch(x.Content, ConfirmRegex));

                    if (Regex.IsMatch(m.Message.Content, YesRegex))
                    {
                        //Even Money
                        await ctx.RespondAsync("Alrighty! Even it is.");

                        return;
                    }
                    else
                    {
                        await ctx.RespondAsync("Good Luck.");
                    }
                }
                else
                {
                    //Player wins with BlackJack (3/2)
                    await ctx.RespondAsync("Blackjack! You win!");

                    return;
                }
            }
            else
            {
                if (game.HouseCards[0].Value == BlackJackGame.Card.CardValue.Ace)
                {
                    //Ask for even

                    await ctx.RespondAsync("House has an Ace, do you want to take insurance?");

                    var m = await dep.Interactivity.WaitForMessageAsync(
                        x => x.Channel.Id == ctx.Channel.Id &&
                        x.Author.Id == ctx.Member.Id &&
                        Regex.IsMatch(x.Content, ConfirmRegex));

                    if (Regex.IsMatch(m.Message.Content, YesRegex))
                    {
                        //Insurance
                        await ctx.RespondAsync("Alrighty! Insurance it is.");

                        return;
                    }
                    else
                    {
                        await ctx.RespondAsync("Good Luck.");
                    }
                }
            }

            //Flip House' Card
            await ctx.RespondAsync($"House' Card #2 is a {game.HouseCards[game.HouseCards.Count - 1].Variation.ToString()} {game.HouseCards[game.HouseCards.Count - 1].Value.ToString()}\n");

            //Draw for House while Value is under 17
            while (BlackJackGame.GetMaxSumWithoutOvershoot(game.HouseCards) < 17)
            {
                game.DrawCardHouse();
                await ctx.RespondAsync($"House got a {game.HouseCards[game.HouseCards.Count - 1].Variation.ToString()} {game.HouseCards[game.HouseCards.Count - 1].Value.ToString()}\n");

                if (BlackJackGame.GetMaxSumWithoutOvershoot(game.HouseCards) == BlackJackGame.GetMaxSumWithoutOvershoot(game.PlayerCards))
                {
                    //Draw, no one wins
                    await ctx.RespondAsync("It's a Draw!");

                    return;
                }

                if (BlackJackGame.GetMinSum(game.HouseCards) > 21)
                {
                    //House overshoots, you win
                    await ctx.RespondAsync("House busts. You win!");

                    return;
                }
            }

            if (BlackJackGame.IsBlackJack(game.PlayerCards) && BlackJackGame.IsBlackJack(game.HouseCards))
            {
                //Both Blackjack, push
                await ctx.RespondAsync("It's a Draw!");

                return;
            }

            if (BlackJackGame.GetMaxSumWithoutOvershoot(game.HouseCards) == BlackJackGame.GetMaxSumWithoutOvershoot(game.PlayerCards))
            {
                //Draw, no one wins
                await ctx.RespondAsync("It's a Draw!");

                return;
            }

            if (BlackJackGame.GetMaxSumWithoutOvershoot(game.HouseCards) > BlackJackGame.GetMaxSumWithoutOvershoot(game.PlayerCards))
            {
                //House wins
                await ctx.RespondAsync("House wins.");

                return;
            }
            else if (BlackJackGame.IsBlackJack(game.PlayerCards))
            {
                //Player wins cause of more Points AND Blackjack, so Money is 3/2
                await ctx.RespondAsync("You win!");

                return;
            }
            else
            {
                //Player wins cause of more Points
                await ctx.RespondAsync("You win!");

                return;
            }
        }