✨ Independant blackjack loop
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -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
|
||||
|
56
Gwendolyn.py
56
Gwendolyn.py
@ -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
7
resources/games.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"trivia questions": {},
|
||||
"users": {
|
||||
"nikolaj": 1,
|
||||
"jonathanh\u00f8jlev": 6
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user