This commit is contained in:
NikolajDanger
2020-07-29 23:55:18 +02:00
parent 7b8d144a56
commit 86e5b61f7a
2 changed files with 22 additions and 10 deletions

View File

@ -21,7 +21,7 @@ blackjackDecks = 4
meanWords = ["stupid", "bitch", "fuck", "dumb", "idiot"]
# Loop of game rounds
async def blackjackLoop(channel,gameRound):
async def blackjackLoop(channel,gameRound,gameID):
logThis("Loop "+str(gameRound))
with open("resources/games/oldImages/blackjack"+str(channel), "r") as f:
@ -46,11 +46,12 @@ async def blackjackLoop(channel,gameRound):
if str(channel) in data["blackjack games"]:
realRound = data["blackjack games"][str(channel)]["round"]
realGameID = data["blackjack games"][str(channel)]["id"]
if gameRound == realRound:
if gameRound == realRound and realGameID == gameID:
if gamedone == False:
logThis("Loop "+str(gameRound)+" calling blackjackLoop()")
await blackjackLoop(channel,gameRound+1)
await blackjackLoop(channel,gameRound+1,gameID)
else:
new_message = blackjackFinish(str(channel))
await channel.send(new_message)
@ -442,11 +443,12 @@ async def parseCommands(message,content):
if len(data["blackjack games"][str(message.channel)]["user hands"]) == 0:
gamedone = True
await message.channel.send("No one entered the game. Ending the game.")
gameID = data["blackjack games"][str(message.channel)]["id"]
# Loop of game rounds
if gamedone == False:
logThis("!blackjack calling blackjackLoop()")
await blackjackLoop(message.channel,1)
await blackjackLoop(message.channel,1,gameID)
else:
new_message = blackjackFinish(str(message.channel))
await message.channel.send(new_message)
@ -468,7 +470,7 @@ async def parseCommands(message,content):
# Hitting
elif content.startswith("blackjack hit"):
if content == "blackjack hit" or content == "blackjack hit ":
response= blackjackHit(str(message.channel),message.author.display_name)
response = blackjackHit(str(message.channel),message.author.display_name)
else:
commands = content.split(" ")
try:
@ -481,8 +483,10 @@ async def parseCommands(message,content):
await message.add_reaction("👍")
try:
if response[6] == "T":
with open("resources/games/games.json", "r") as f:
gameID = json.load(f)["blackjack games"][str(message.channel)]["id"]
logThis("Hit calling blackjackLoop()")
await blackjackLoop(message.channel,int(response[7:])+1)
await blackjackLoop(message.channel,int(response[7:])+1,gameID)
except:
logThis("Something fucked up")
await message.channel.send("something fucked up")
@ -498,8 +502,10 @@ async def parseCommands(message,content):
await message.add_reaction("👍")
try:
if response[6] == "T":
with open("resources/games/games.json", "r") as f:
gameID = json.load(f)["blackjack games"][str(message.channel)]["id"]
logThis("Stand calling blackjackLoop()")
await blackjackLoop(message.channel,int(response[7:])+1)
await blackjackLoop(message.channel,int(response[7:])+1,gameID)
except:
logThis("Something fucked up")
await message.channel.send("something fucked up")
@ -519,8 +525,10 @@ async def parseCommands(message,content):
try:
if roundDone[0] == "T":
with open("resources/games/games.json", "r") as f:
gameID = json.load(f)["blackjack games"][str(message.channel)]["id"]
logThis("Double calling blackjackLoop()")
await blackjackLoop(message.channel,int(roundDone[1:])+1)
await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID)
except:
logThis("Something fucked up")
await message.channel.send("something fucked up")
@ -533,8 +541,10 @@ async def parseCommands(message,content):
#try:
if roundDone[0] == "T":
with open("resources/games/games.json", "r") as f:
gameID = json.load(f)["blackjack games"][str(message.channel)]["id"]
logThis("Split calling blackjackLoop()")
await blackjackLoop(message.channel,int(roundDone[1:])+1)
await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID)
#except:
# logThis("Something fucked up")
# await message.channel.send("something fucked up")

View File

@ -1,6 +1,7 @@
import random
import json
import math
import datetime
from shutil import copyfile
@ -517,8 +518,9 @@ def blackjackStart(channel:str):
if channel not in data["blackjack games"]:
dealerHand = [drawCard(),drawCard()]
gameID = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
data["blackjack games"][channel] = {"dealer hand": dealerHand,"dealer busted":False,"dealer blackjack":False,"user hands": {},"all standing":False,"round":0}
data["blackjack games"][channel] = {"dealer hand": dealerHand,"dealer busted":False,"dealer blackjack":False,"user hands": {},"all standing":False,"round":0,"id":gameID}
if calcHandValue(dealerHand) == 21:
data["blackjack games"][channel]["dealer blackjack"] = True