🧹 Smaal clean-up with connect four

Removing the unused function in gameLoops and changing the class name to
start with a capital letter
This commit is contained in:
NikolajDanger
2021-04-04 15:38:26 +02:00
parent e4a44fffef
commit 5647cea552
3 changed files with 3 additions and 72 deletions

View File

@ -19,7 +19,7 @@ AISCORES = {
ROWCOUNT = 6
COLUMNCOUNT = 7
class connectFour():
class ConnectFour():
def __init__(self,bot):
self.bot = bot
self.draw = drawConnectFour(bot)

View File

@ -21,75 +21,6 @@ class GameLoops():
return oldMessage
# Runs connect four
async def connectFour(self, ctx, command, user = None, channelId = None):
if user is None:
user = "#"+str(ctx.author.id)
if channelId is None:
channelId = str(ctx.channel_id)
response, showImage, deleteImage, gameDone, gwendoTurn = self.bot.games.connectFour.parseconnectFour(command,channelId, user)
if hasattr(ctx, "send"):
await ctx.send(response)
else:
await ctx.channel.send(response)
self.bot.log(response, channelId)
if showImage:
if deleteImage:
oldImage = await self.deleteMessage("connectFour"+channelId,ctx.channel)
oldImage = await ctx.channel.send(file = discord.File("resources/games/connect4Boards/board"+channelId+".png"))
if gameDone == False:
if gwendoTurn:
response, showImage, deleteImage, gameDone, gwendoTurn = await self.bot.games.connectFour.connectFourAI(channelId)
await ctx.channel.send(response)
self.bot.log(response,channelId)
if showImage:
if deleteImage:
await oldImage.delete()
oldImage = await ctx.channel.send(file = discord.File("resources/games/connect4Boards/board"+channelId+".png"))
if gameDone == False:
with open("resources/games/oldImages/connectFour"+channelId, "w") as f:
f.write(str(oldImage.id))
try:
reactions = ["1","2","3","4","5","6","7"]
for reaction in reactions:
await oldImage.add_reaction(reaction)
except:
self.bot.log("Image deleted before I could react to all of them")
else:
with open("resources/games/oldImages/connectFour"+channelId, "w") as f:
f.write(str(oldImage.id))
try:
reactions = ["1","2","3","4","5","6","7"]
for reaction in reactions:
await oldImage.add_reaction(reaction)
except:
self.bot.log("Image deleted before I could react to all of them")
if gameDone:
game = self.bot.database["connect 4 games"].find_one({"_id":channelId})
try:
with open("resources/games/oldImages/connectFour"+channelId, "r") as f:
oldImage = await channel.fetch_message(int(f.read()))
await oldImage.delete()
except:
self.bot.log("The old image was already deleted")
winner = game["winner"]
difficulty = int(game["difficulty"])
reward = difficulty**2 + 5
if winner != 0:
if game["players"][winner-1].lower() != "gwendolyn":
self.bot.money.addMoney(game["players"][winner-1].lower(),reward)
self.bot.databaseFuncs.deleteGame("connect 4 games",channelId)
# Runs Hex
async def runHex(self,ctx,command,user):
channelId = ctx.channel_id

View File

@ -1,7 +1,7 @@
from .invest import Invest
from .trivia import Trivia
from .blackjack import Blackjack
from .connectFour import connectFour
from .connectFour import ConnectFour
from .gameLoops import GameLoops
from .hangman import Hangman
from .hex import HexGame
@ -13,7 +13,7 @@ class Games():
self.invest = Invest(bot)
self.trivia = Trivia(bot)
self.blackjack = Blackjack(bot)
self.connectFour = connectFour(bot)
self.connectFour = ConnectFour(bot)
self.gameLoops = GameLoops(bot)
self.hangman = Hangman(bot)
self.hex = HexGame(bot)