🚧 Started on 4 in a row game
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@ -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
|
||||
|
14
Gwendolyn.py
14
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:
|
||||
@ -413,6 +414,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"]
|
||||
if ("gwendolyn" in message.content.lower() or message.content.startswith("!")) and any(x in message.content.lower() for x in meanWords) and "ikke" not in message.content.lower() and "not" not in message.content.lower():
|
||||
|
@ -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
|
@ -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
|
||||
from .fourInARow import decipherCommand
|
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
61
funcs/games/draw4InARow.py
Normal file
61
funcs/games/draw4InARow.py
Normal file
@ -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")
|
65
funcs/games/fourInARow.py
Normal file
65
funcs/games/fourInARow.py
Normal file
@ -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
|
BIN
funcs/games/test.png
Normal file
BIN
funcs/games/test.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 75 KiB |
@ -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):
|
||||
|
Reference in New Issue
Block a user