diff --git a/.gitignore b/.gitignore index 286a5f4..107b037 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Gwendolyn.py b/Gwendolyn.py index 42defb6..291b322 100644 --- a/Gwendolyn.py +++ b/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) diff --git a/resources/games.json b/resources/games.json new file mode 100644 index 0000000..22b4179 --- /dev/null +++ b/resources/games.json @@ -0,0 +1,7 @@ +{ + "trivia questions": {}, + "users": { + "nikolaj": 1, + "jonathanh\u00f8jlev": 6 + } +} \ No newline at end of file