🎨 Drawing stuff

This commit is contained in:
Nikolaj Danger
2020-07-29 18:21:30 +02:00
parent 21c3d17129
commit f24807fbc4
2 changed files with 85 additions and 63 deletions

View File

@ -187,53 +187,57 @@ def blackjackHit(channel,user,handNumber = 0):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
if data["blackjack games"][channel]["user hands"][user]["split"] == False:
hand = data["blackjack games"][channel]["user hands"][user]
otherHand = False
else:
if handNumber != 0:
if handNumber == 1:
hand = data["blackjack games"][channel]["user hands"][user]
otherHand = False
elif handNumber == 2:
hand = data["blackjack games"][channel]["user hands"][user]["other hand"]
otherHand = True
if user in data["blackjack games"][channel]["user hands"]:
if data["blackjack games"][channel]["user hands"][user]["split"] == False:
hand = data["blackjack games"][channel]["user hands"][user]
otherHand = False
else:
if handNumber != 0:
if handNumber == 1:
hand = data["blackjack games"][channel]["user hands"][user]
otherHand = False
elif handNumber == 2:
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:
logThis(user+" tried to hit without specifying which hand")
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 hand["hit"] == False:
if hand["standing"] == False:
hand["hand"].append(drawCard())
hand["hit"] = True
if data["blackjack games"][channel]["round"] > 0:
if hand["hit"] == False:
if hand["standing"] == False:
hand["hand"].append(drawCard())
hand["hit"] = True
handValue = calcHandValue(hand["hand"])
if handValue > 21:
hand["busted"] = True
if otherHand:
data["blackjack games"][channel]["user hands"][user]["other hand"] = hand
handValue = calcHandValue(hand["hand"])
if handValue > 21:
hand["busted"] = True
if otherHand:
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:
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"
logThis(user+" is already standing")
return "You can't hit when you're standing"
else:
logThis(user+" is already standing")
return "You can't hit when you're standing"
logThis(user+" has already hit this round")
return "You've already hit this round"
else:
logThis(user+" has already hit this round")
return "You've already hit this round"
logThis(user+" tried to hit on the 0th round")
return "You can't hit before you see your cards"
else:
logThis(user+" tried to hit on the 0th round")
return "You can't hit before you see your cards"
logThis(user+" tried to hit without being in the game")
return "You have to enter the game before you can hit"
# 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:
data = json.load(f)
hand = data["blackjack games"][channel]["user hands"][user]
if data["blackjack games"][channel]["round"] > 0:
if hand["hit"] == False:
if hand["standing"] == False:
hand["standing"] = True
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
if user in data["blackjack games"][channel]["user hands"]:
hand = data["blackjack games"][channel]["user hands"][user]
if data["blackjack games"][channel]["round"] > 0:
if hand["hit"] == False:
if hand["standing"] == False:
hand["standing"] = True
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:
logThis(user+" is already standing")
return "You're already standing"
logThis(user+" has already hit this round")
return "You've already hit this round"
else:
logThis(user+" has already hit this round")
return "You've already hit this round"
logThis(user+" tried to stand on the first round")
return "You can't stand before you see your cards"
else:
logThis(user+" tried to stand on the first round")
return "You can't stand before you see your cards"
logThis(user+" tried to stand without being in the game")
return "You have to enter the game before you can stand"
# When players try to split
def blackjackSplit(channel,user):

View File

@ -1,13 +1,18 @@
import json
import json, random
from PIL import Image, ImageDraw, ImageFont
border = 100
placement = [0,0]
rotation = 0
def drawImage(channel):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
fnt = ImageFont.truetype('resources/futura-bold.ttf', 50)
fntSmol = ImageFont.truetype('resources/futura-bold.ttf', 40)
borderSmol = int(border/3.5)
table = Image.open("resources/games/blackjackTable.png")
placement = [2,1,3,0,4]
@ -22,18 +27,18 @@ def drawImage(channel):
else:
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)):
key, value = list(hands.items())[x]
userHand = drawHand(value["hand"],False,value["busted"],value["blackjack"])
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"])
table.paste(userOtherHand,(32+(384*placement[x]),700),userOtherHand)
table.paste(userOtherHand,(32-borderSmol+(384*placement[x]),700-borderSmol),userOtherHand)
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]
if textWidth < 360:
@ -58,21 +63,30 @@ def drawHand(hand, dealer, busted, blackjack):
fnt = ImageFont.truetype('resources/futura-bold.ttf', 200)
fnt2 = ImageFont.truetype('resources/futura-bold.ttf', 120)
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)
if dealer:
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")
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:
for x in range(length):
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
textHeight = 290
textHeight = 390+border
if busted:
textWidth = fnt.getsize("BUSTED")[0]