This commit is contained in:
jona605a
2020-08-06 17:22:33 +02:00
42 changed files with 1239 additions and 1842 deletions

View File

@ -1,9 +1,10 @@
"""Functions for games Gwendolyn can play."""
__all__ = ["checkBalance", "giveMoney", "addMoney","triviaCountPoints", "triviaStart", "triviaAnswer", "blackjackShuffle", "blackjackStart", "blackjackPlayerDrawHand", "blackjackContinue", "blackjackFinish", "blackjackHit", "blackjackStand", "blackjackDouble", "blackjackSplit", "parseFourInARow", "fourInARowAI", "parseHex","hexAI"]
__all__ = ["checkBalance", "giveMoney", "addMoney","triviaCountPoints", "triviaStart", "triviaAnswer", "blackjackShuffle", "blackjackStart", "blackjackPlayerDrawHand", "blackjackContinue", "blackjackFinish", "blackjackHit", "blackjackStand", "blackjackDouble", "blackjackSplit", "parseFourInARow", "fourInARowAI", "parseHex", "hexAI", "parseMonopoly", "monopolyContinue"]
from .money import checkBalance, giveMoney, addMoney
from .trivia import triviaCountPoints, triviaStart, triviaAnswer
from .blackjack import blackjackShuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit
from .fourInARow import parseFourInARow, fourInARowAI
from .hex import parseHex, hexAI
from .monopoly import parseMonopoly, monopolyContinue

View File

@ -197,126 +197,18 @@ def blackjackHit(channel,user,handNumber = 0):
data = json.load(f)
if user in data["blackjack games"][channel]["user hands"]:
if data["blackjack games"][channel]["user hands"][user]["split"] == 0:
hand = data["blackjack games"][channel]["user hands"][user]
handNumber = 0
else:
if handNumber != 0:
if handNumber == 1:
hand = data["blackjack games"][channel]["user hands"][user]
elif handNumber == 2:
hand = data["blackjack games"][channel]["user hands"][user]["other hand"]
elif handNumber == 3:
hand = data["blackjack games"][channel]["user hands"][user]["third hand"]
elif handNumber == 4:
hand = data["blackjack games"][channel]["user hands"][user]["fourth hand"]
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(channel))
hand["hit"] = True
handValue = calcHandValue(hand["hand"])
if handValue > 21:
hand["busted"] = True
if handNumber == 2:
data["blackjack games"][channel]["user hands"][user]["other hand"] = hand
elif handNumber == 3:
data["blackjack games"][channel]["user hands"][user]["third hand"] = hand
elif handNumber == 4:
data["blackjack games"][channel]["user hands"][user]["fourth 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)
response = "accept"
roundDone = True
for person in data["blackjack games"][channel]["user hands"].values():
if person["hit"] == False and person["standing"] == False:
roundDone = False
if person["split"] > 0:
if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False:
roundDone = False
if person["split"] > 1:
if person["third hand"]["hit"] == False and person["third hand"]["standing"] == False:
roundDone = False
if person["split"] > 2:
if person["fourth hand"]["hit"] == False and person["fourth hand"]["standing"] == False:
roundDone = False
return response + str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
else:
logThis(user+" is already standing")
return "You can't hit when you're standing"
else:
logThis(user+" has already hit this round")
return "You've already hit this round"
else:
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 without being in the game")
return "You have to enter the game before you can hit"
# When players try to double down
def blackjackDouble(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"] == 0:
hand = data["blackjack games"][channel]["user hands"][user]
handNumber = 0
else:
if handNumber != 0:
if handNumber == 1:
hand = data["blackjack games"][channel]["user hands"][user]
elif handNumber == 2:
hand = data["blackjack games"][channel]["user hands"][user]["other hand"]
elif handNumber == 3:
hand = data["blackjack games"][channel]["user hands"][user]["third hand"]
elif handNumber == 4:
hand = data["blackjack games"][channel]["user hands"][user]["fourth hand"]
else:
logThis(user+" tried to double without specifying which hand")
return "You have to specify the hand you're doubling down.",""
else:
logThis(user+" tried to double without specifying which hand")
return "You have to specify the hand you're doubling down.",""
if data["blackjack games"][channel]["round"] > 0:
if hand["hit"] == False:
if hand["standing"] == False:
if len(hand["hand"]) == 2:
bet = hand["bet"]
if money.checkBalance(user) >= bet:
money.addMoney(user,-1 * bet)
with open("resources/games/games.json", "r") as f:
data = json.load(f)
hand, handNumber = getHandNumber(data["blackjack games"][channel]["user hands"][user],handNumber)
print(hand)
if hand != None:
if data["blackjack games"][channel]["round"] > 0:
if hand["hit"] == False:
if hand["standing"] == False:
hand["hand"].append(drawCard(channel))
hand["hit"] = True
hand["doubled"] = True
hand["bet"] += bet
handValue = calcHandValue(hand["hand"])
if handValue > 21:
hand["busted"] = True
@ -333,41 +225,93 @@ def blackjackDouble(channel,user,handNumber = 0):
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
roundDone = True
response = "accept"
roundDone = isRoundDone(data["blackjack games"][channel])
for person in data["blackjack games"][channel]["user hands"].values():
if person["hit"] == False and person["standing"] == False:
roundDone = False
if person["split"] > 0:
if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False:
roundDone = False
if person["split"] > 1:
if person["third hand"]["hit"] == False and person["third hand"]["standing"] == False:
roundDone = False
if person["split"] > 2:
if person["fourth hand"]["hit"] == False and person["fourth hand"]["standing"] == False:
roundDone = False
return "Adding another "+str(bet)+" GwendoBucks to "+getName(user)+"'s bet and drawing another card.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
return response + str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
else:
logThis(user+" doesn't have enough GwendoBucks")
return "You don't have enough GwendoBucks",""
logThis(user+" is already standing")
return "You can't hit when you're standing"
else:
logThis(user+" tried to double on round "+str(data["blackjack games"][channel]["round"]))
return "You can only double down on the first round",""
logThis(user+" has already hit this round")
return "You've already hit this round"
else:
logThis(user+" is already standing")
return "You can't double when you're standing",""
logThis(user+" tried to hit on the 0th round")
return "You can't hit before you see your cards"
else:
logThis(user+" has already hit this round")
return "You've already hit this round",""
logThis(user+" didn't specify a hand")
return "You need to specify a hand"
else:
logThis(user+" tried to double on the 0th round")
return "You can't double down 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
def blackjackDouble(channel,user,handNumber = 0):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
if user in data["blackjack games"][channel]["user hands"]:
hand, handNumber = getHandNumber(data["blackjack games"][channel]["user hands"][user],handNumber)
if hand != None:
if data["blackjack games"][channel]["round"] > 0:
if hand["hit"] == False:
if hand["standing"] == False:
if len(hand["hand"]) == 2:
bet = hand["bet"]
if money.checkBalance(user) >= bet:
money.addMoney(user,-1 * bet)
with open("resources/games/games.json", "r") as f:
data = json.load(f)
hand["hand"].append(drawCard(channel))
hand["hit"] = True
hand["doubled"] = True
hand["bet"] += bet
handValue = calcHandValue(hand["hand"])
if handValue > 21:
hand["busted"] = True
if handNumber == 2:
data["blackjack games"][channel]["user hands"][user]["other hand"] = hand
elif handNumber == 3:
data["blackjack games"][channel]["user hands"][user]["third hand"] = hand
elif handNumber == 4:
data["blackjack games"][channel]["user hands"][user]["fourth 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)
roundDone = isRoundDone(data["blackjack games"][channel])
return "Adding another "+str(bet)+" GwendoBucks to "+getName(user)+"'s bet and drawing another card.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
else:
logThis(user+" doesn't have enough GwendoBucks")
return "You don't have enough GwendoBucks",""
else:
logThis(user+" tried to double on round "+str(data["blackjack games"][channel]["round"]))
return "You can only double down on the first round",""
else:
logThis(user+" is already standing")
return "You can't double when you're standing",""
else:
logThis(user+" has already hit this round")
return "You've already hit this round",""
else:
logThis(user+" tried to double on the 0th round")
return "You can't double down before you see your cards",""
else:
logThis(user+" didn't specify a hand")
return "You need to specify which hand"
else:
logThis(user+" tried to double without being in the game")
return "You can't double when you're not in the game",""
# When players try to stand
def blackjackStand(channel,user,handNumber = 0):
@ -375,62 +319,33 @@ def blackjackStand(channel,user,handNumber = 0):
data = json.load(f)
if user in data["blackjack games"][channel]["user hands"]:
if data["blackjack games"][channel]["user hands"][user]["split"] == 0:
hand = data["blackjack games"][channel]["user hands"][user]
handNumber = 0
else:
if handNumber != 0:
if handNumber == 1:
hand = data["blackjack games"][channel]["user hands"][user]
elif handNumber == 2:
hand = data["blackjack games"][channel]["user hands"][user]["other hand"]
elif handNumber == 3:
hand = data["blackjack games"][channel]["user hands"][user]["third hand"]
elif handNumber == 4:
hand = data["blackjack games"][channel]["user hands"][user]["fourth hand"]
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["standing"] = True
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
hand, handNumber = getHandNumber(data["blackjack games"][channel]["user hands"][user],handNumber)
response = "accept"
roundDone = True
if hand != None:
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)
for person in data["blackjack games"][channel]["user hands"].values():
if person["hit"] == False and person["standing"] == False:
roundDone = False
if person["split"] > 0:
if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False:
roundDone = False
response = "accept"
roundDone = isRoundDone(data["blackjack games"][channel])
if person["split"] > 1:
if person["third hand"]["hit"] == False and person["third hand"]["standing"] == False:
roundDone = False
if person["split"] > 2:
if person["fourth hand"]["hit"] == False and person["fourth hand"]["standing"] == False:
roundDone = False
return response + str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
return response + str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
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+" didn't specify a hand")
return "You need to specify which hand"
else:
logThis(user+" tried to stand without being in the game")
return "You have to enter the game before you can stand"
@ -526,23 +441,7 @@ def blackjackSplit(channel,user,handNumber = 0):
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
roundDone = True
for person in data["blackjack games"][channel]["user hands"].values():
if person["hit"] == False and person["standing"] == False:
roundDone = False
if person["split"] > 0:
if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False:
roundDone = False
if person["split"] > 1:
if person["third hand"]["hit"] == False and person["third hand"]["standing"] == False:
roundDone = False
if person["split"] > 2:
if person["fourth hand"]["hit"] == False and person["fourth hand"]["standing"] == False:
roundDone = False
roundDone = isRoundDone(data["blackjack games"][channel])
return "Splitting "+getName(user)+"'s hand into 2. Adding their original bet to the second hand. You can use \"!Blackjack hit/stand/double 1\" and \"!Blackjack hit/stand/double 2\" to play the different hands.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
else:
@ -744,4 +643,47 @@ def calcWinnings(hand, dealerValue, topLevel, dealerBlackjack, dealerBusted):
netWinnings += netWinningsTemp
reason += reasonTemp
return winnings, netWinnings, reason
return winnings, netWinnings, reason
def getHandNumber(user,handNumber):
try:
hand = None
if user["split"] == 0:
hand = user
handNumber = 0
else:
if handNumber != 0:
if handNumber == 1:
hand = user
elif handNumber == 2:
hand = user["other hand"]
elif handNumber == 3:
hand = user["third hand"]
elif handNumber == 4:
hand = user["fourth hand"]
return hand, handNumber
except:
logThis("Problem with getHandNumber() (error code 1322)")
def isRoundDone(game):
roundDone = True
for person in game["user hands"].values():
if person["hit"] == False and person["standing"] == False:
roundDone = False
if person["split"] > 0:
if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False:
roundDone = False
if person["split"] > 1:
if person["third hand"]["hit"] == False and person["third hand"]["standing"] == False:
roundDone = False
if person["split"] > 2:
if person["fourth hand"]["hit"] == False and person["fourth hand"]["standing"] == False:
roundDone = False
return roundDone

View File

@ -22,7 +22,7 @@ def drawImage(channel):
dealerBusted = data["blackjack games"][channel]["dealer busted"]
dealerBlackjack = data["blackjack games"][channel]["dealer blackjack"]
try:
if data["blackjack games"][channel]["all standing"] == False:
dealerHand = drawHand(data["blackjack games"][channel]["dealer hand"],True,False,False)
@ -36,7 +36,7 @@ def drawImage(channel):
for x in range(len(hands)):
key, value = list(hands.items())[x]
key = getName(key)
logThis("drawing "+key+"'s hand")
#logThis("Drawing "+key+"'s hand")
userHand = drawHand(value["hand"],False,value["busted"],value["blackjack"])
try:
if value["split"] == 3:

View File

@ -20,6 +20,9 @@ def drawImage(channel):
exampleCircles = 100
w, h = 2800,2000
backgroundColor = (128,128,128,255)
outlineColor = (0,0,0)
player1Color = (200,0,0)
player2Color = (255,255,0)
boardColor = (0,0,170)
placeSize = 285
white = (255,255,255,160)
@ -48,35 +51,33 @@ def drawImage(channel):
# This whole part was the easiest way to make a rectangle with rounded corners and an outline
# - Corners:
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.ellipse([(border,border),(border+cornerSize,border+cornerSize)],fill=boardColor,outline=outlineColor,width=outlineSize)
d.ellipse([(w-(border+cornerSize),h-(border+cornerSize)),(w-border,h-border)],fill=boardColor,outline=outlineColor,width=outlineSize)
d.ellipse([(border,h-(border+cornerSize)),(border+cornerSize,h-border)],fill=boardColor,outline=outlineColor,width=outlineSize)
d.ellipse([(w-(border+cornerSize),border),(w-border,border+cornerSize)],fill=boardColor,outline=outlineColor,width=outlineSize)
# - Rectangle:
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),(w-(border+math.floor(cornerSize/2)),h-border)],fill=boardColor,outline=outlineColor,width=outlineSize)
d.rectangle([(border,border+math.floor(cornerSize/2)),(w-border,h-(border+math.floor(cornerSize/2)))],fill=boardColor,outline=outlineColor,width=outlineSize)
# - Removing outline on the inside:
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)
d.rectangle([(border+math.floor(cornerSize/2),border+outlineSize),(w-(border+math.floor(cornerSize/2)),h-(border+outlineSize))],fill=boardColor)
d.rectangle([(border+outlineSize,border+math.floor(cornerSize/2)),(w-(border+outlineSize),h-(border+math.floor(cornerSize/2)))],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)
pieceColor = player1Color
elif piece == 2:
pieceColor = (200,0,0)
pieceColor = player2Color
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)
d.ellipse([(startx,starty),(startx+placeSize,starty+placeSize)],fill=pieceColor,outline=outlineColor,width=outlineSize)
if data["4 in a row games"][channel]["winner"] != 0:
coordinates = data["4 in a row games"][channel]["win coordinates"]
@ -120,8 +121,7 @@ def drawImage(channel):
winBar = winBar.rotate(diagonalAngle,expand=1)
startx -= placeGridSize[0]*3 + border
starty -= gridBorder + border
mask = winBar.copy()#.convert("L")
#mask.putalpha(128)
#mask.save("test.png")
@ -133,11 +133,11 @@ def drawImage(channel):
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.ellipse([(border,exampleHeight),(border+exampleCircles),(exampleHeight+exampleCircles)],fill=player1Color,outline=outlineColor,width=3)
d.text((border+exampleCircles+textPadding,exampleHeight),player1,font=fnt,fill=(0,0,0))
textWidth = fnt.getsize(player2)[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.ellipse([(w-border-exampleCircles-textWidth-textPadding,exampleHeight),(w-border-textWidth-textPadding),(exampleHeight+exampleCircles)],fill=player2Color,outline=outlineColor,width=3)
d.text((w-border-textWidth,exampleHeight),player2,font=fnt,fill=(0,0,0))

View File

@ -18,13 +18,13 @@ def addMoney(user,amount):
logThis("adding "+str(amount)+" to "+user+"'s account")
with open("resources/users.json", "r") as f:
data = json.load(f)
if user in data:
points = data[user]["money"]
data[user]["money"] = points + amount
else:
logThis("Error adding money")
with open("resources/users.json", "w") as f:
json.dump(data,f,indent=4)
@ -32,11 +32,11 @@ def addMoney(user,amount):
def giveMoney(user,targetUser,amount):
with open("resources/users.json", "r") as f:
data = json.load(f)
targetUser = getID(targetUser)
if amount > 0:
if targetUser.startswith("#"):
if targetUser != None:
if user in data:
if data[user]["money"] >= amount:
addMoney(user,-1 * amount)

141
funcs/games/monopoly.py Normal file
View File

@ -0,0 +1,141 @@
import json, random
from funcs import getName, logThis
from . import monopolyDraw
rulesAndTerms = {
"pass go money" : 200,
"money term" : "GP"
}
def monopolyStart(channel):
logThis("Starting a monopoly game")
with open("resources/games/monopolyGames.json", "r") as f:
data = json.load(f)
if channel not in data:
buildings = [0] * 40
data[channel] = {"players" : {}, "player list" : [],"turn" : 0, "buildings" : buildings, "last roll" : [0,0], "started" : False}
with open("resources/games/monopolyGames.json", "w") as f:
json.dump(data,f,indent=4)
try:
monopolyDraw.drawImage(channel)
except:
logThis("Error drawing board (error code 1640)")
return "Started a monopoly game. Use \"!monopoly join\" to join within the next minute.", True, False, True, True
else:
return "There's already a monopoly game going on.", False, False, False, False
def monopolyJoin(channel,user):
with open("resources/games/monopolyGames.json", "r") as f:
data = json.load(f)
if channel in data:
if not data[channel]["started"]:
if user not in data[channel]["players"]:
if len(data[channel]["players"]) < 6:
data[channel]["players"][user] = {"position" : 0, "properties" : [], "money" : 1500, "doubles" : 0}
with open("resources/games/monopolyGames.json", "w") as f:
json.dump(data,f,indent=4)
return getName(user)+" has joined the game.", False, False, False, False
else:
return "There are already 6 players in the game.", False, False, False, False
else:
return "You're already in the game!", False, False, False, False
else:
return "It's too late to join.", False, False, False, False
else:
return "There's no game going on.", False, False, False, False
def parseMonopoly(command, channel, user):
logThis("Parsing "+command)
commands = command.split()
if command in [" ", ""] or commands[0] == "start":
try:
return monopolyStart(channel)
except:
logThis("Error starting game (error code 1620)")
elif commands[0] == "join":
try:
return monopolyJoin(channel,user)
except:
logThis("Error joining game (error code 1630)")
elif commands[0] == "roll":
try:
return monopolyRoll(channel,user)
except:
logThis("Error rolling (error code 1650)")
else:
return "I didn't understand that (error code 1602)", False, False, False, False
def monopolyContinue(channel):
with open("resources/games/monopolyGames.json", "r") as f:
data = json.load(f)
if channel in data:
if data[channel]["started"] == False:
data[channel]["started"] = True
playerList = list(data[channel]["players"].keys())
random.shuffle(playerList)
data[channel]["player list"] = playerList
turn = 0
else:
if data[channel]["last roll"][0] == data[channel]["last roll"][1]:
turn = data[channel]["turn"]
else:
turn = (data[channel]["turn"] + 1)%len(data[channel]["player list"])
data[channel]["turn"] = turn
playerList = list(data[channel]["players"].keys())
with open("resources/games/monopolyGames.json", "w") as f:
json.dump(data,f,indent=4)
try:
monopolyDraw.drawImage(channel)
except:
logThis("Error drawing board (error code 1640)")
message = "It's "+getName(playerList[turn])+"'s turn. Use the 🎲 reaction to roll. You can also use \"!monopoly trade\" at any time."
return message, True, True, False
def monopolyRoll(channel,user):
with open("resources/games/monopolyGames.json", "r") as f:
data = json.load(f)
turn = data[channel]["turn"]
currentPlayer = data[channel]["player list"][turn]
if user == currentPlayer:
rolls = [random.randint(1,6),random.randint(1,6)]
message = getName(user)+" rolled a "+str(rolls[0])+" and a "+str(rolls[1])+"."
if rolls[0] == rolls[1]:
message += " Doubbles!"
roll = rolls[0] + rolls[1]
oldPosition = data[channel]["players"][user]["position"]
newPosition = (oldPosition + roll)%40
if newPosition < oldPosition:
data[channel]["players"][user]["money"] += rulesAndTerms["pass go money"]
message += "\nYou passed go and got "+str(rulesAndTerms["pass go money"])+" "+rulesAndTerms["money term"]+"."
data[channel]["players"][user]["position"] = newPosition
data[channel]["last roll"] = rolls
with open("resources/games/monopolyGames.json", "w") as f:
json.dump(data,f,indent=4)
try:
monopolyDraw.drawImage(channel)
except:
logThis("Error drawing board (error code 1640)")
return message, True, True, False, True
else: return "", False, False, False, False

View File

@ -0,0 +1,57 @@
import math, json
from funcs import logThis
from PIL import Image, ImageDraw
w, h = 1440, 1440
largeSpace = 191
smallSpace = math.floor((w - 2*largeSpace)/9)
avatarSize = 50
avatarHalf = math.floor(avatarSize/2)
def drawImage(channel):
logThis("Drawing monopoly board for "+channel)
with open("resources/games/monopolyGames.json", "r") as f:
data = json.load(f)
board = Image.open("resources/games/monopolyBoard.png")
d = ImageDraw.Draw(board,"RGBA")
for key, value in list(data[channel]["players"].items()):
logThis("Drawing "+key)
try:
x, y = getPosition(value["position"])
except:
logThis("Error getting position (error code 1641)")
print(str(x)+", "+str(y))
d.ellipse([(x-avatarHalf,y-avatarHalf),(x+avatarHalf,y+avatarHalf)],fill=(255,0,0))
board.save("resources/games/monopolyBoards/monopolyBoard"+channel+".png")
def getPosition(positionNumber):
print(positionNumber)
x, y = 0, 0
if positionNumber == 0 or positionNumber >= 30:
x = math.floor(largeSpace/2)
elif positionNumber > 0 and positionNumber < 10:
x = math.floor(largeSpace - (smallSpace/2)) + (smallSpace*positionNumber)
elif positionNumber >= 10 and positionNumber <= 20:
x = w - math.floor(largeSpace/2)
elif positionNumber > 20 and positionNumber < 30:
x = w - math.floor(largeSpace - (smallSpace/2)) - (smallSpace*(positionNumber - 20))
if positionNumber >= 0 and positionNumber <= 20:
y = math.floor(largeSpace/2)
elif positionNumber > 10 and positionNumber < 20:
y = math.floor(largeSpace - (smallSpace/2)) + (smallSpace*(positionNumber-10))
elif positionNumber >= 20 and positionNumber <= 30:
y = h - math.floor(largeSpace/2)
elif positionNumber > 30:
y = h - math.floor(largeSpace - (smallSpace/2)) - (smallSpace*(positionNumber - 30))
return x, y