diff --git a/.gitignore b/.gitignore index efdaf6b..2e92a77 100644 --- a/.gitignore +++ b/.gitignore @@ -154,5 +154,6 @@ resources/swcharacters.json resources/games/games.json resources/games/blackjackCards.txt resources/destinyPoints.txt -resources/games/tables/ +resources/games/blackjackTables/ +resources/games/4InARowBoards/ gwendolynTest.py diff --git a/Gwendolyn.py b/Gwendolyn.py index e462fa3..b2da851 100644 --- a/Gwendolyn.py +++ b/Gwendolyn.py @@ -63,6 +63,7 @@ async def on_message(message): data["trivia questions"] = {} data["blackjack games"] = {} + data["4 in a row games"] = {} with open("resources/games/games.json","w") as f: json.dump(data,f,indent=4) @@ -326,7 +327,7 @@ async def on_message(message): new_message = "Blackjack game started. Use \"!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/tables/blackjackTable"+str(message.channel)+".png")) + old_image = await message.channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(message.channel)+".png")) await asyncio.sleep(30) @@ -344,7 +345,7 @@ async def on_message(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/tables/blackjackTable"+str(message.channel)+".png")) + old_image = await message.channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(message.channel)+".png")) if allStanding: await asyncio.sleep(5) else: @@ -412,6 +413,15 @@ async def on_message(message): else: await message.channel.send("I didn't quite understand that") + + elif message.content.lower().startswith("!fourinarow"): + funcs.logThis(message.author.display_name+" ran \""+message.content+"\"") + response, showImage = funcs.decipherCommand(message.content.lower().replace("!fourinarow",""),str(message.channel),message.author.display_name) + await message.channel.send(response) + funcs.logThis(response) + if showImage: + await message.channel.send(file = discord.File("resources/games/4InARowBoards/board"+str(message.channel)+".png")) + # Is a bit sassy sometimes meanWords = ["stupid", "bitch", "fuck", "dumb", "idiot"] diff --git a/funcs/__init__.py b/funcs/__init__.py index 5d55d8a..e6d427b 100644 --- a/funcs/__init__.py +++ b/funcs/__init__.py @@ -6,6 +6,6 @@ from .lookup import spellFunc, monsterFunc from .other import nameGen, tavernGen, movieFunc -from .games import triviaStart, triviaOtherThing, triviaCountPoints, checkBalance, addMoney, giveMoney, shuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackStand, blackjackHit,blackjackDouble,blackjackSplit +from .games import triviaStart, triviaOtherThing, triviaCountPoints, checkBalance, addMoney, giveMoney, shuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackStand, blackjackHit,blackjackDouble,blackjackSplit, decipherCommand from .roll import roll_dice \ No newline at end of file diff --git a/funcs/games/__init__.py b/funcs/games/__init__.py index 1df43f7..399e3bf 100644 --- a/funcs/games/__init__.py +++ b/funcs/games/__init__.py @@ -1,3 +1,4 @@ from .money import checkBalance, giveMoney, addMoney from .trivia import triviaCountPoints, triviaStart, triviaOtherThing -from .blackjack import shuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit \ No newline at end of file +from .blackjack import shuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit +from .fourInARow import decipherCommand \ No newline at end of file diff --git a/funcs/games/blackjack.py b/funcs/games/blackjack.py index d8627f3..804f3f1 100644 --- a/funcs/games/blackjack.py +++ b/funcs/games/blackjack.py @@ -449,7 +449,7 @@ def blackjackStart(channel:str): with open("resources/games/games.json", "w") as f: json.dump(data,f,indent=4) - copyfile("resources/games/blackjackTable.png","resources/games/tables/blackjackTable"+channel+".png") + copyfile("resources/games/blackjackTable.png","resources/games/blackjackTables/blackjackTable"+channel+".png") return "started" else: diff --git a/funcs/games/blackjackDraw.py b/funcs/games/blackjackDraw.py index 598d1a0..639e97a 100644 --- a/funcs/games/blackjackDraw.py +++ b/funcs/games/blackjackDraw.py @@ -41,7 +41,7 @@ def drawImage(channel): textImage.text((32+(384*placement[x])+117-int(textWidth/2)+3,1010+3),key,fill=(0,0,0), font=fnt) textImage.text((32+(384*placement[x])+117-int(textWidth/2),1005),key,fill=(255,255,255), font=fnt) - table.save("resources/games/tables/blackjackTable"+channel+".png") + table.save("resources/games/blackjackTables/blackjackTable"+channel+".png") return diff --git a/funcs/games/draw4InARow.py b/funcs/games/draw4InARow.py new file mode 100644 index 0000000..a70ff78 --- /dev/null +++ b/funcs/games/draw4InARow.py @@ -0,0 +1,61 @@ +import json +import math + +from PIL import Image, ImageDraw, ImageFont +from funcs import logThis + +def drawImage(channel): + logThis("Drawing four in a row board") + with open("resources/games/games.json", "r") as f: + data = json.load(f) + + board = data["4 in a row games"][channel]["board"] + + border = 40 + gridBorder = 40 + cornerSize = 100 + outlineSize = 10 + w, h = 2800,2000 + backgroundColor = (128,128,128,255) + boardColor = (0,0,170) + + placeSize = 270 + boardSize = [w-(2*(border+gridBorder)),h-(2*(border+gridBorder))] + placeGridSize = [math.floor(boardSize[0]/7),math.floor(boardSize[1]/6)] + pieceStartx = (border+gridBorder)+math.floor(placeGridSize[0]/2)-math.floor(placeSize/2) + pieceStarty = (border+gridBorder)+math.floor(placeGridSize[1]/2)-math.floor(placeSize/2) + + + background = Image.new("RGBA", (w,h),backgroundColor) + d = ImageDraw.Draw(background) + + d.ellipse([(border,border),(border+cornerSize,border+cornerSize)],fill=boardColor,outline=(0,0,0),width=outlineSize) + d.ellipse([(w-(border+cornerSize),h-(border+cornerSize)),(w-border,h-border)],fill=boardColor,outline=(0,0,0),width=outlineSize) + d.ellipse([(border,h-(border+cornerSize)),(border+cornerSize,h-border)],fill=boardColor,outline=(0,0,0),width=outlineSize) + d.ellipse([(w-(border+cornerSize),border),(w-border,border+cornerSize)],fill=boardColor,outline=(0,0,0),width=outlineSize) + + d.rectangle([(border+math.floor(cornerSize/2),border),(w-(border+math.floor(cornerSize/2)),h-border)],fill=boardColor,outline=(0,0,0),width=outlineSize) + d.rectangle([(border,border+math.floor(cornerSize/2)),(w-border,h-(border+math.floor(cornerSize/2)))],fill=boardColor,outline=(0,0,0),width=outlineSize) + d.rectangle([(border+math.floor(cornerSize/2),border+math.floor(cornerSize/2)),(w-(border+math.floor(cornerSize/2)),h-(border+math.floor(cornerSize/2)))],fill=boardColor) + d.ellipse([(border+outlineSize,border+outlineSize),(border+cornerSize-outlineSize,border+cornerSize-outlineSize)],fill=boardColor) + d.ellipse([(w-(border+cornerSize)+outlineSize,h-(border+cornerSize)+outlineSize),(w-border-outlineSize,h-border-outlineSize)],fill=boardColor) + d.ellipse([(border+outlineSize,h-(border+cornerSize)+outlineSize),(border+cornerSize-outlineSize,h-border-outlineSize)],fill=boardColor) + d.ellipse([(w-(border+cornerSize)+outlineSize,border+outlineSize),(w-border-outlineSize,border+cornerSize-outlineSize)],fill=boardColor) + + for line in range(len(board)): + for place in range(len(board[line])): + piece = board[line][place] + + if piece == 1: + pieceColor = (255,255,0) + elif piece == 2: + pieceColor = (200,0,0) + else: + pieceColor = backgroundColor + + startx = pieceStartx + placeGridSize[0]*place + starty = pieceStarty + placeGridSize[1]*line + + d.ellipse([(startx,starty),(startx+placeSize,starty+placeSize)],fill=pieceColor,outline=(0,0,0),width=outlineSize) + + background.save("resources/games/4InARowBoards/board"+channel+".png") diff --git a/funcs/games/fourInARow.py b/funcs/games/fourInARow.py new file mode 100644 index 0000000..69f9ffc --- /dev/null +++ b/funcs/games/fourInARow.py @@ -0,0 +1,65 @@ +import json + +from . import draw4InARow + +def fourInARowStart(channel): + with open("resources/games/games.json", "r") as f: + data = json.load(f) + + if channel not in data["4 in a row games"]: + + board = [ [ 0 for i in range(7) ] for j in range(6) ] + + data["4 in a row games"][channel] = {"board": board} + + with open("resources/games/games.json", "w") as f: + json.dump(data,f,indent=4) + + draw4InARow.drawImage(channel) + + return "Started game", True + else: + return "There's already a 4 in a row game going on in this channel", False + + +def placePiece(channel : str,player : int,column : int): + with open("resources/games/games.json", "r") as f: + data = json.load(f) + + if channel in data["4 in a row games"]: + board = data["4 in a row games"][channel]["board"] + + placementx, placementy = -1, column + + for x in range(len(board)): + if board[x][column] == 0: + placementx = x + + + if placementx != -1: + board[placementx][placementy] = player + data["4 in a row games"][channel]["board"] = board + + with open("resources/games/games.json", "w") as f: + json.dump(data,f,indent=4) + + draw4InARow.drawImage(channel) + return "Placed the piece", True + else: + return "There isn't any room in that column", True + else: + return "There's no game in this channel", False + + + +def decipherCommand(command, channel, user): + if command == "" or command == " ": + return fourInARowStart(channel) + elif command.startswith(" place"): + commands = command.split(" ") + try: + return placePiece(channel,int(commands[2]),int(commands[3])-1) + except: + return "I didn't quite get that", False + else: + return "I didn't get that", False \ No newline at end of file diff --git a/funcs/games/test.png b/funcs/games/test.png new file mode 100644 index 0000000..1232a1f Binary files /dev/null and b/funcs/games/test.png differ diff --git a/funcs/gwendolynFuncs.py b/funcs/gwendolynFuncs.py index 85ecc6c..a363acd 100644 --- a/funcs/gwendolynFuncs.py +++ b/funcs/gwendolynFuncs.py @@ -143,7 +143,7 @@ def makeFiles(): f = open("resources/games/games.json","r") except: logThis("games.json didn't exist. Making it now.") - data = {"trivia questions":{},"blackjack games":{},"users":{}} + data = {"trivia questions":{},"blackjack games":{},"4 in a row games": {},"users":{}} with open("resources/games/games.json","w") as f: json.dump(data,f,indent = 4) finally: @@ -183,8 +183,8 @@ def makeFiles(): finally: f.close() - if os.path.isdir("resources/games/tables") == False: - os.makedirs("resources/games/tables") + if os.path.isdir("resources/games/blackjackTables") == False: + os.makedirs("resources/games/blackjackTables") logThis("The tables directory didn't exist") def replaceMultiple(mainString, toBeReplaces, newString):