✨ Four in a row is almost done
This commit is contained in:
@ -16,18 +16,22 @@ def drawImage(channel):
|
||||
gridBorder = 40
|
||||
cornerSize = 100
|
||||
outlineSize = 20
|
||||
bottomBorder = 110
|
||||
exampleCircles = 100
|
||||
w, h = 2800,2000
|
||||
backgroundColor = (128,128,128,255)
|
||||
boardColor = (0,0,170)
|
||||
|
||||
placeSize = 285
|
||||
|
||||
fnt = ImageFont.truetype('resources/futura-bold.ttf', exampleCircles)
|
||||
|
||||
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("RGB", (w,h),backgroundColor)
|
||||
background = Image.new("RGB", (w,h+bottomBorder),backgroundColor)
|
||||
d = ImageDraw.Draw(background,"RGBA")
|
||||
|
||||
# This whole part was the easiest way to make a rectangle with rounded corners and an outline
|
||||
@ -110,4 +114,16 @@ def drawImage(channel):
|
||||
winBar.putalpha(mask)
|
||||
background.paste(winBar,(startx,starty),winBar)
|
||||
|
||||
# Bottom
|
||||
textPadding = 20
|
||||
|
||||
exampleHeight = h - border + int((bottomBorder+border)/2) - int(exampleCircles/2)
|
||||
d.ellipse([(border,exampleHeight),(border+exampleCircles),(exampleHeight+exampleCircles)],fill=(255,255,0),outline=(0,0,0),width=3)
|
||||
d.text((border+exampleCircles+textPadding,exampleHeight),data["4 in a row games"][channel]["players"][0],font=fnt,stroke_fill=(0,0,0))
|
||||
|
||||
textWidth = fnt.getsize(data["4 in a row games"][channel]["players"][1])[0]
|
||||
d.ellipse([(w-border-exampleCircles-textWidth-textPadding,exampleHeight),(w-border-textWidth-textPadding),(exampleHeight+exampleCircles)],fill=(255,0,0),outline=(0,0,0),width=3)
|
||||
d.text((w-border-textWidth,exampleHeight),data["4 in a row games"][channel]["players"][1],font=fnt,stroke_fill=(0,0,0))
|
||||
|
||||
|
||||
background.save("resources/games/4InARowBoards/board"+channel+".png")
|
||||
|
@ -4,7 +4,7 @@ from . import draw4InARow
|
||||
from funcs import logThis
|
||||
|
||||
# Starts the game
|
||||
def fourInARowStart(channel):
|
||||
def fourInARowStart(channel, user, opponent):
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
@ -13,14 +13,14 @@ def fourInARowStart(channel):
|
||||
board = [ [ 0 for i in range(7) ] for j in range(6) ]
|
||||
|
||||
data["4 in a row games"][channel] = {"board": board,"winner":0,"win direction":"",
|
||||
"win coordinates":[0,0],"players":["",""]}
|
||||
"win coordinates":[0,0],"players":[user,opponent],"turn":0}
|
||||
|
||||
with open("resources/games/games.json", "w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
|
||||
draw4InARow.drawImage(channel)
|
||||
|
||||
return "Started game", True, False, False
|
||||
return "Started game. It's "+user+"'s turn", True, False, False
|
||||
else:
|
||||
return "There's already a 4 in a row game going on in this channel", False, False, False
|
||||
|
||||
@ -42,6 +42,8 @@ def placePiece(channel : str,player : int,column : int):
|
||||
if placementx != -1:
|
||||
board[placementx][placementy] = player
|
||||
data["4 in a row games"][channel]["board"] = board
|
||||
turn = (data["4 in a row games"][channel]["turn"]+1)%2
|
||||
data["4 in a row games"][channel]["turn"] = turn
|
||||
|
||||
with open("resources/games/games.json", "w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
@ -57,7 +59,7 @@ def placePiece(channel : str,player : int,column : int):
|
||||
message = data["4 in a row games"][channel]["players"][won-1]+" won"
|
||||
else:
|
||||
gameWon = False
|
||||
message = "Placed a piece"
|
||||
message = "Placed a piece. It's now "+data["4 in a row games"][channel]["players"][turn]+"'s turn."
|
||||
|
||||
with open("resources/games/games.json", "w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
@ -72,8 +74,24 @@ def placePiece(channel : str,player : int,column : int):
|
||||
|
||||
# Parses command
|
||||
def parseFourInARow(command, channel, user):
|
||||
|
||||
print(command)
|
||||
if command == "" or command == " ":
|
||||
return fourInARowStart(channel)
|
||||
return "I didn't get that. \"Use !fourinarow start\" to start a game.", False, False, False
|
||||
|
||||
|
||||
elif command.startswith(" start "):
|
||||
command = command.replace(" start ","")
|
||||
return fourInARowStart(channel,user,command)
|
||||
|
||||
elif command.startswith(" stop"):
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
if user in data["4 in a row games"][channel]["players"]:
|
||||
return "Ending game.", False, False, True
|
||||
else:
|
||||
return "You can't end a game where you're not a player.", False, False, False
|
||||
elif command.startswith(" place"):
|
||||
commands = command.split(" ")
|
||||
#try:
|
||||
|
Reference in New Issue
Block a user