🖌️ Added stuff to the blackjack drawing

This commit is contained in:
NikolajDanger
2020-07-28 11:18:47 +02:00
parent 81012bada5
commit 9908671c40
6 changed files with 69 additions and 26 deletions

View File

@ -68,14 +68,18 @@ def dealerDraw(channel):
data = json.load(f)
done = False
dealerHand = data["blackjack games"][channel]["dealer hand"]
if calcHandValue(data["blackjack games"][channel]["dealer hand"]) < 17:
if calcHandValue(dealerHand) < 17:
data["blackjack games"][channel]["dealer hand"].append(drawCard())
else:
done = True
if calcHandValue(data["blackjack games"][channel]["dealer hand"]) > 21:
if calcHandValue(dealerHand) > 21:
data["blackjack games"][channel]["dealer busted"] = True
if calcHandValue(dealerHand) == 21 and len(dealerHand) == 2:
data["blackjack games"][channel]["dealer blackjack"] = True
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
@ -83,6 +87,7 @@ def dealerDraw(channel):
return done
def blackjackContinue(channel):
logThis("Continuing blackjack game")
with open("resources/games/games.json", "r") as f:
data = json.load(f)
@ -93,6 +98,7 @@ def blackjackContinue(channel):
allStanding = True
preAllStanding = True
message = "All players are standing. The dealer now shows his cards and draws."
if data["blackjack games"][channel]["all standing"]:
@ -111,6 +117,12 @@ def blackjackContinue(channel):
if data["blackjack games"][channel]["user hands"][user]["standing"] == False:
allStanding = False
if calcHandValue(data["blackjack games"][channel]["user hands"][user]["hand"]) >= 21:
data["blackjack games"][channel]["user hands"][user]["standing"] = True
else:
preAllStanding = False
data["blackjack games"][channel]["user hands"][user]["hit"] = False
if allStanding:
@ -128,6 +140,8 @@ def blackjackContinue(channel):
return message, True, done
else:
return "The dealer is done drawing cards", True, done
elif preAllStanding:
return "", True, done
else:
return "You have 20 seconds to either hit or stand with \"!blackjack hit\" or \"!blackjack stand\". It's assumed you're standing if you don't make a choice.", False, done
@ -143,10 +157,8 @@ def blackjackHit(channel,user):
handValue = calcHandValue(data["blackjack games"][channel]["user hands"][user]["hand"])
if handValue == 21:
data["blackjack games"][channel]["user hands"][user]["standing"] = True
elif handValue > 21:
data["blackjack games"][channel]["user hands"][user]["standing"] = True
if handValue > 21:
data["blackjack games"][channel]["user hands"][user]["busted"] = True
@ -205,7 +217,7 @@ def blackjackPlayerDrawHand(channel,user,bet):
data = json.load(f)
if handValue == 21:
data["blackjack games"][channel]["user hands"][user] = {"hand":playerHand,"bet":bet,"standing":True,"busted":False,"blackjack":True,"hit":True}
data["blackjack games"][channel]["user hands"][user] = {"hand":playerHand,"bet":bet,"standing":False,"busted":False,"blackjack":True,"hit":True}
else:
data["blackjack games"][channel]["user hands"][user] = {"hand":playerHand,"bet":bet,"standing":False,"busted":False,"blackjack":False,"hit":True}
@ -240,7 +252,7 @@ def blackjackStart(channel:str):
dealerHand = [drawCard(),drawCard()]
data["blackjack games"][channel] = {"dealer hand": dealerHand,"dealer busted":False,"user hands": {},"open for bets":True,"all standing":False}
data["blackjack games"][channel] = {"dealer hand": dealerHand,"dealer busted":False,"dealer blackjack":False,"user hands": {},"open for bets":True,"all standing":False}
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)