From 71fcf80eab6fa6a338b7c23da35c4cb54232fb5d Mon Sep 17 00:00:00 2001 From: NikolajDanger Date: Tue, 28 Jul 2020 12:00:35 +0200 Subject: [PATCH] :sparkles: Added doubling in blackjack --- Gwendolyn.py | 5 +++++ funcs/__init__.py | 2 +- funcs/games/__init__.py | 2 +- funcs/games/blackjack.py | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Gwendolyn.py b/Gwendolyn.py index 3ebd79a..ddc345d 100644 --- a/Gwendolyn.py +++ b/Gwendolyn.py @@ -377,6 +377,11 @@ async def on_message(message): await message.add_reaction("👍") else: await message.channel.send(response) + + if message.content.lower().startswith("!blackjack double"): + response = funcs.blackjackDouble(str(message.channel),message.author.name) + + await message.channel.send(response) # Is a bit sassy sometimes diff --git a/funcs/__init__.py b/funcs/__init__.py index eb1c763..edfec54 100644 --- a/funcs/__init__.py +++ b/funcs/__init__.py @@ -6,6 +6,6 @@ from .lookup import spellFunc, monsterFunc from .other import nameGen, tavernGen, movieFunc -from .games import triviaStart, triviaOtherThing, triviaCountPoints, checkBalance, addMoney, giveMoney, shuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackStand, blackjackHit +from .games import triviaStart, triviaOtherThing, triviaCountPoints, checkBalance, addMoney, giveMoney, shuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackStand, blackjackHit,blackjackDouble from .roll import roll_dice \ No newline at end of file diff --git a/funcs/games/__init__.py b/funcs/games/__init__.py index 582ba06..9a92e0d 100644 --- a/funcs/games/__init__.py +++ b/funcs/games/__init__.py @@ -1,3 +1,3 @@ from .money import checkBalance, giveMoney, addMoney from .trivia import triviaCountPoints, triviaStart, triviaOtherThing -from .blackjack import shuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand \ No newline at end of file +from .blackjack import shuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble \ No newline at end of file diff --git a/funcs/games/blackjack.py b/funcs/games/blackjack.py index 99f97d8..81c9c06 100644 --- a/funcs/games/blackjack.py +++ b/funcs/games/blackjack.py @@ -176,6 +176,42 @@ def blackjackHit(channel,user): logThis(user+" tried to hit on the first round") return "You can't hit before you see your cards" +def blackjackDouble(channel,user): + with open("resources/games/games.json", "r") as f: + data = json.load(f) + + if data["blackjack games"][channel]["user hands"][user]["hit"] == False: + if data["blackjack games"][channel]["user hands"][user]["standing"] == False: + bet = data["blackjack games"][channel]["user hands"][user]["bet"] + if money.checkBalance(user) >= bet: + money.addMoney(user,-1 * bet) + + data["blackjack games"][channel]["user hands"][user]["hand"].append(drawCard()) + data["blackjack games"][channel]["user hands"][user]["hit"] = True + data["blackjack games"][channel]["user hands"][user]["standing"] = True + data["blackjack games"][channel]["user hands"][user]["bet"] += bet + + handValue = calcHandValue(data["blackjack games"][channel]["user hands"][user]["hand"]) + + + if handValue > 21: + data["blackjack games"][channel]["user hands"][user]["busted"] = True + + + with open("resources/games/games.json", "w") as f: + json.dump(data,f,indent=4) + + return "Adding another "+str(bet)+" GwendoBucks to "+user+"'s bet" + else: + logThis(user+" doesn't have enough GwendoBucks") + return "You don't have enough GwendoBucks" + else: + logThis(user+" is already standing") + return "You can't hit when you're standing" + else: + logThis(user+" has already hit this round") + return "You've already hit this round" + def blackjackStand(channel,user): with open("resources/games/games.json", "r") as f: data = json.load(f)