Independant blackjack loop

This commit is contained in:
Nikolaj Danger
2020-07-29 17:38:57 +02:00
parent ec7b1891d4
commit 21c3d17129
3 changed files with 49 additions and 15 deletions

1
.gitignore vendored
View File

@ -156,5 +156,6 @@ resources/games/blackjackCards.txt
resources/games/hilo.txt
resources/destinyPoints.txt
resources/games/blackjackTables/
resources/games/oldImages/
resources/games/4InARowBoards/
gwendolynTest.py

View File

@ -20,6 +20,38 @@ blackjackDecks = 4
# Variable for reacting to messages
meanWords = ["stupid", "bitch", "fuck", "dumb", "idiot"]
# Loop of game rounds
async def blackjackLoop(channel,gameRound):
logThis("Loop "+str(gameRound))
with open("resources/games/oldImages/blackjack"+str(channel), "r") as f:
oldImage = await channel.fetch_message(int(f.read()))
new_message, allStanding, gamedone = blackjackContinue(str(channel))
if new_message != "":
await channel.send(new_message)
if gamedone == False:
await oldImage.delete()
oldImage = await channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(channel)+".png"))
with open("resources/games/oldImages/blackjack"+str(channel), "w") as f:
f.write(str(oldImage.id))
if allStanding:
await asyncio.sleep(5)
else:
await asyncio.sleep(30)
with open("resources/games/games.json", "r") as f:
realRound = json.load(f)["blackjack games"][str(channel)]["round"]
if gameRound == realRound:
if gamedone == False:
await blackjackLoop(channel,gameRound+1)
else:
new_message = blackjackFinish(str(channel))
await channel.send(new_message)
else:
logThis("Ending loop on round "+str(gameRound))
async def parseCommands(message,content):
# Sends the contents of a help file, as specified by the message.
if content.startswith("help"):
@ -389,7 +421,10 @@ async def parseCommands(message,content):
new_message = "Blackjack game started. Use \""+commandPrefix+"blackjack bet [amount]\" to enter the game within the next 30 seconds."
await message.channel.send(new_message)
old_image = await message.channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(message.channel)+".png"))
oldImage = await message.channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(message.channel)+".png"))
with open("resources/games/oldImages/blackjack"+str(message.channel), "w") as f:
f.write(str(oldImage.id))
await asyncio.sleep(30)
@ -402,20 +437,11 @@ async def parseCommands(message,content):
await message.channel.send("No one entered the game. Ending the game.")
# Loop of game rounds
while gamedone == False:
new_message, allStanding, gamedone = blackjackContinue(str(message.channel))
if new_message != "":
await message.channel.send(new_message)
if gamedone == False:
await old_image.delete()
old_image = await message.channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(message.channel)+".png"))
if allStanding:
await asyncio.sleep(5)
else:
await asyncio.sleep(30)
new_message = blackjackFinish(str(message.channel))
await message.channel.send(new_message)
if gamedone == False:
await blackjackLoop(message.channel,1)
else:
new_message = blackjackFinish(str(message.channel))
await message.channel.send(new_message)
else:
await message.channel.send(new_message)

7
resources/games.json Normal file
View File

@ -0,0 +1,7 @@
{
"trivia questions": {},
"users": {
"nikolaj": 1,
"jonathanh\u00f8jlev": 6
}
}