🎨 Drawing stuff
This commit is contained in:
@@ -187,53 +187,57 @@ def blackjackHit(channel,user,handNumber = 0):
|
|||||||
with open("resources/games/games.json", "r") as f:
|
with open("resources/games/games.json", "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
if data["blackjack games"][channel]["user hands"][user]["split"] == False:
|
if user in data["blackjack games"][channel]["user hands"]:
|
||||||
hand = data["blackjack games"][channel]["user hands"][user]
|
if data["blackjack games"][channel]["user hands"][user]["split"] == False:
|
||||||
otherHand = False
|
hand = data["blackjack games"][channel]["user hands"][user]
|
||||||
else:
|
otherHand = False
|
||||||
if handNumber != 0:
|
else:
|
||||||
if handNumber == 1:
|
if handNumber != 0:
|
||||||
hand = data["blackjack games"][channel]["user hands"][user]
|
if handNumber == 1:
|
||||||
otherHand = False
|
hand = data["blackjack games"][channel]["user hands"][user]
|
||||||
elif handNumber == 2:
|
otherHand = False
|
||||||
hand = data["blackjack games"][channel]["user hands"][user]["other hand"]
|
elif handNumber == 2:
|
||||||
otherHand = True
|
hand = data["blackjack games"][channel]["user hands"][user]["other hand"]
|
||||||
|
otherHand = True
|
||||||
|
else:
|
||||||
|
logThis(user+" tried to hit without specifying which hand")
|
||||||
|
return "You have to specify the hand you're hitting with."
|
||||||
else:
|
else:
|
||||||
logThis(user+" tried to hit without specifying which hand")
|
logThis(user+" tried to hit without specifying which hand")
|
||||||
return "You have to specify the hand you're hitting with."
|
return "You have to specify the hand you're hitting with."
|
||||||
else:
|
|
||||||
logThis(user+" tried to hit without specifying which hand")
|
|
||||||
return "You have to specify the hand you're hitting with."
|
|
||||||
|
|
||||||
if data["blackjack games"][channel]["round"] > 0:
|
if data["blackjack games"][channel]["round"] > 0:
|
||||||
if hand["hit"] == False:
|
if hand["hit"] == False:
|
||||||
if hand["standing"] == False:
|
if hand["standing"] == False:
|
||||||
hand["hand"].append(drawCard())
|
hand["hand"].append(drawCard())
|
||||||
hand["hit"] = True
|
hand["hit"] = True
|
||||||
|
|
||||||
handValue = calcHandValue(hand["hand"])
|
handValue = calcHandValue(hand["hand"])
|
||||||
|
|
||||||
if handValue > 21:
|
if handValue > 21:
|
||||||
hand["busted"] = True
|
hand["busted"] = True
|
||||||
|
|
||||||
if otherHand:
|
if otherHand:
|
||||||
data["blackjack games"][channel]["user hands"][user]["other hand"] = hand
|
data["blackjack games"][channel]["user hands"][user]["other hand"] = hand
|
||||||
|
else:
|
||||||
|
data["blackjack games"][channel]["user hands"][user] = hand
|
||||||
|
|
||||||
|
with open("resources/games/games.json", "w") as f:
|
||||||
|
json.dump(data,f,indent=4)
|
||||||
|
|
||||||
|
return "accept"
|
||||||
else:
|
else:
|
||||||
data["blackjack games"][channel]["user hands"][user] = hand
|
logThis(user+" is already standing")
|
||||||
|
return "You can't hit when you're standing"
|
||||||
with open("resources/games/games.json", "w") as f:
|
|
||||||
json.dump(data,f,indent=4)
|
|
||||||
|
|
||||||
return "accept"
|
|
||||||
else:
|
else:
|
||||||
logThis(user+" is already standing")
|
logThis(user+" has already hit this round")
|
||||||
return "You can't hit when you're standing"
|
return "You've already hit this round"
|
||||||
else:
|
else:
|
||||||
logThis(user+" has already hit this round")
|
logThis(user+" tried to hit on the 0th round")
|
||||||
return "You've already hit this round"
|
return "You can't hit before you see your cards"
|
||||||
else:
|
else:
|
||||||
logThis(user+" tried to hit on the 0th round")
|
logThis(user+" tried to hit without being in the game")
|
||||||
return "You can't hit before you see your cards"
|
return "You have to enter the game before you can hit"
|
||||||
|
|
||||||
|
|
||||||
# When players try to double down
|
# When players try to double down
|
||||||
@@ -313,24 +317,28 @@ def blackjackStand(channel,user,handNumber = 0):
|
|||||||
with open("resources/games/games.json", "r") as f:
|
with open("resources/games/games.json", "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
hand = data["blackjack games"][channel]["user hands"][user]
|
if user in data["blackjack games"][channel]["user hands"]:
|
||||||
if data["blackjack games"][channel]["round"] > 0:
|
hand = data["blackjack games"][channel]["user hands"][user]
|
||||||
if hand["hit"] == False:
|
if data["blackjack games"][channel]["round"] > 0:
|
||||||
if hand["standing"] == False:
|
if hand["hit"] == False:
|
||||||
hand["standing"] = True
|
if hand["standing"] == False:
|
||||||
with open("resources/games/games.json", "w") as f:
|
hand["standing"] = True
|
||||||
json.dump(data,f,indent=4)
|
with open("resources/games/games.json", "w") as f:
|
||||||
|
json.dump(data,f,indent=4)
|
||||||
|
|
||||||
return "accept"
|
return "accept"
|
||||||
|
else:
|
||||||
|
logThis(user+" is already standing")
|
||||||
|
return "You're already standing"
|
||||||
else:
|
else:
|
||||||
logThis(user+" is already standing")
|
logThis(user+" has already hit this round")
|
||||||
return "You're already standing"
|
return "You've already hit this round"
|
||||||
else:
|
else:
|
||||||
logThis(user+" has already hit this round")
|
logThis(user+" tried to stand on the first round")
|
||||||
return "You've already hit this round"
|
return "You can't stand before you see your cards"
|
||||||
else:
|
else:
|
||||||
logThis(user+" tried to stand on the first round")
|
logThis(user+" tried to stand without being in the game")
|
||||||
return "You can't stand before you see your cards"
|
return "You have to enter the game before you can stand"
|
||||||
|
|
||||||
# When players try to split
|
# When players try to split
|
||||||
def blackjackSplit(channel,user):
|
def blackjackSplit(channel,user):
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
import json
|
import json, random
|
||||||
|
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
|
||||||
|
border = 100
|
||||||
|
placement = [0,0]
|
||||||
|
rotation = 0
|
||||||
|
|
||||||
def drawImage(channel):
|
def drawImage(channel):
|
||||||
with open("resources/games/games.json", "r") as f:
|
with open("resources/games/games.json", "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
fnt = ImageFont.truetype('resources/futura-bold.ttf', 50)
|
fnt = ImageFont.truetype('resources/futura-bold.ttf', 50)
|
||||||
fntSmol = ImageFont.truetype('resources/futura-bold.ttf', 40)
|
fntSmol = ImageFont.truetype('resources/futura-bold.ttf', 40)
|
||||||
|
borderSmol = int(border/3.5)
|
||||||
|
|
||||||
table = Image.open("resources/games/blackjackTable.png")
|
table = Image.open("resources/games/blackjackTable.png")
|
||||||
placement = [2,1,3,0,4]
|
placement = [2,1,3,0,4]
|
||||||
@@ -22,18 +27,18 @@ def drawImage(channel):
|
|||||||
else:
|
else:
|
||||||
dealerHand = drawHand(data["blackjack games"][channel]["dealer hand"],False,dealerBusted,dealerBlackjack)
|
dealerHand = drawHand(data["blackjack games"][channel]["dealer hand"],False,dealerBusted,dealerBlackjack)
|
||||||
|
|
||||||
table.paste(dealerHand,(800,20),dealerHand)
|
table.paste(dealerHand,(800-borderSmol,20-borderSmol),dealerHand)
|
||||||
|
|
||||||
for x in range(len(hands)):
|
for x in range(len(hands)):
|
||||||
key, value = list(hands.items())[x]
|
key, value = list(hands.items())[x]
|
||||||
userHand = drawHand(value["hand"],False,value["busted"],value["blackjack"])
|
userHand = drawHand(value["hand"],False,value["busted"],value["blackjack"])
|
||||||
|
|
||||||
if value["split"]:
|
if value["split"]:
|
||||||
table.paste(userHand,(32+(384*placement[x]),560),userHand)
|
table.paste(userHand,(32-borderSmol+(384*placement[x]),560-borderSmol),userHand)
|
||||||
userOtherHand = drawHand(value["other hand"]["hand"],False,value["other hand"]["busted"],value["other hand"]["blackjack"])
|
userOtherHand = drawHand(value["other hand"]["hand"],False,value["other hand"]["busted"],value["other hand"]["blackjack"])
|
||||||
table.paste(userOtherHand,(32+(384*placement[x]),700),userOtherHand)
|
table.paste(userOtherHand,(32-borderSmol+(384*placement[x]),700-borderSmol),userOtherHand)
|
||||||
else:
|
else:
|
||||||
table.paste(userHand,(32+(384*placement[x]),680),userHand)
|
table.paste(userHand,(32-borderSmol+(384*placement[x]),680-borderSmol),userHand)
|
||||||
|
|
||||||
textWidth = fnt.getsize(key)[0]
|
textWidth = fnt.getsize(key)[0]
|
||||||
if textWidth < 360:
|
if textWidth < 360:
|
||||||
@@ -58,21 +63,30 @@ def drawHand(hand, dealer, busted, blackjack):
|
|||||||
fnt = ImageFont.truetype('resources/futura-bold.ttf', 200)
|
fnt = ImageFont.truetype('resources/futura-bold.ttf', 200)
|
||||||
fnt2 = ImageFont.truetype('resources/futura-bold.ttf', 120)
|
fnt2 = ImageFont.truetype('resources/futura-bold.ttf', 120)
|
||||||
length = len(hand)
|
length = len(hand)
|
||||||
background = Image.new("RGBA", (691+(125*(length-1)),1065),(0,0,0,0))
|
background = Image.new("RGBA", ((border*2)+691+(125*(length-1)),(border*2)+1065),(0,0,0,0))
|
||||||
textImage = ImageDraw.Draw(background)
|
textImage = ImageDraw.Draw(background)
|
||||||
|
|
||||||
if dealer:
|
if dealer:
|
||||||
img = Image.open("resources/games/cards/"+hand[0].upper()+".png")
|
img = Image.open("resources/games/cards/"+hand[0].upper()+".png")
|
||||||
background.paste(img,(0,0),img)
|
#rotation = (random.randint(-20,20)/10.0)
|
||||||
|
img = img.rotate(rotation,expand = 1)
|
||||||
|
#placement = [random.randint(-20,20),random.randint(-20,20)]
|
||||||
|
background.paste(img,(border+placement[0],border+placement[1]),img)
|
||||||
img = Image.open("resources/games/cards/red_back.png")
|
img = Image.open("resources/games/cards/red_back.png")
|
||||||
background.paste(img,(125,0),img)
|
#rotation = (random.randint(-20,20)/10.0)
|
||||||
|
img = img.rotate(rotation,expand = 1)
|
||||||
|
#placement = [random.randint(-20,20),random.randint(-20,20)]
|
||||||
|
background.paste(img,(125+border+placement[0],border+placement[1]),img)
|
||||||
else:
|
else:
|
||||||
for x in range(length):
|
for x in range(length):
|
||||||
img = Image.open("resources/games/cards/"+hand[x].upper()+".png")
|
img = Image.open("resources/games/cards/"+hand[x].upper()+".png")
|
||||||
background.paste(img,(x*125,0),img)
|
#rotation = (random.randint(-20,20)/10.0)
|
||||||
|
img = img.rotate(rotation,expand = 1)
|
||||||
|
#placement = [random.randint(-20,20),random.randint(-20,20)]
|
||||||
|
background.paste(img,(border+(x*125)+placement[0],border+placement[1]),img)
|
||||||
|
|
||||||
w, h = background.size
|
w, h = background.size
|
||||||
textHeight = 290
|
textHeight = 390+border
|
||||||
|
|
||||||
if busted:
|
if busted:
|
||||||
textWidth = fnt.getsize("BUSTED")[0]
|
textWidth = fnt.getsize("BUSTED")[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user