This commit is contained in:
NikolajDanger
2020-08-20 15:28:43 +02:00
parent f9cfe77d86
commit 0e4bdea3c7
3 changed files with 49 additions and 24 deletions

View File

@@ -93,10 +93,10 @@ class GameLoops():
self.bot.funcs.deleteGame("4 in a row games",str(channel.id)) self.bot.funcs.deleteGame("4 in a row games",str(channel.id))
async def runMonopoly(self,channel, command, user): async def runMonopoly(self,channel, command, user):
try: #try:
response, showImage, deleteImage, gameStarted, gameContinue = self.bot.monopoly.parseMonopoly(command,str(channel.id),user) response, showImage, deleteImage, gameStarted, gameContinue = self.bot.monopoly.parseMonopoly(command,str(channel.id),user)
except: #except:
logThis("Error parsing command (error code 1610)") # logThis("Error parsing command (error code 1610)")
if response != "": if response != "":
await channel.send(response) await channel.send(response)
logThis(response,str(channel.id)) logThis(response,str(channel.id))

View File

@@ -24,10 +24,10 @@ class Monopoly():
self.bot.database["monopoly games"].insert_one(newGame) self.bot.database["monopoly games"].insert_one(newGame)
try: #try:
self.draw.drawImage(channel) self.draw.drawImage(channel)
except: #except:
logThis("Error drawing board (error code 1640)") # 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 return "Started a monopoly game. Use \"!monopoly join\" to join within the next minute.", True, False, True, True
else: else:
@@ -73,6 +73,8 @@ class Monopoly():
return self.monopolyRoll(channel,user) return self.monopolyRoll(channel,user)
except: except:
logThis("Error rolling (error code 1650)") logThis("Error rolling (error code 1650)")
elif commands[0] == "stop":
return self.monopolyStop(channel)
else: else:
return "I didn't understand that (error code 1602)", False, False, False, False return "I didn't understand that (error code 1602)", False, False, False, False
@@ -95,10 +97,10 @@ class Monopoly():
self.bot.database["monopoly games"].update_one({"_id":channel},{"$set":{"turn":turn}}) self.bot.database["monopoly games"].update_one({"_id":channel},{"$set":{"turn":turn}})
playerList = list(game["players"].keys()) playerList = list(game["players"].keys())
try: #try:
self.draw.drawImage(channel) self.draw.drawImage(channel)
except: #except:
logThis("Error drawing board (error code 1640)") # logThis("Error drawing board (error code 1640)")
if playerList == []: if playerList == []:
return "No one joined. Ending game.", False, True, True return "No one joined. Ending game.", False, True, True
@@ -112,7 +114,7 @@ class Monopoly():
turn = game["turn"] turn = game["turn"]
currentPlayer = game["player list"][turn] currentPlayer = game["player list"][turn]
if user == currentPlayer: if user == currentPlayer or self.bot.options.testing:
rolls = [random.randint(1,6),random.randint(1,6)] rolls = [random.randint(1,6),random.randint(1,6)]
message = self.bot.funcs.getName(user)+" rolled a "+str(rolls[0])+" and a "+str(rolls[1])+"." message = self.bot.funcs.getName(user)+" rolled a "+str(rolls[0])+" and a "+str(rolls[1])+"."
if rolls[0] == rolls[1]: if rolls[0] == rolls[1]:
@@ -129,10 +131,14 @@ class Monopoly():
self.bot.database["monopoly games"].update_one({"_id":channel},{"$set":{"players."+user+".position":newPosition}}) self.bot.database["monopoly games"].update_one({"_id":channel},{"$set":{"players."+user+".position":newPosition}})
self.bot.database["monopoly games"].update_one({"_id":channel},{"$set":{"last roll":rolls}}) self.bot.database["monopoly games"].update_one({"_id":channel},{"$set":{"last roll":rolls}})
try: #try:
self.draw.drawImage(channel) self.draw.drawImage(channel)
except: #except:
logThis("Error drawing board (error code 1640)") # logThis("Error drawing board (error code 1640)")
return message, True, True, False, True return message, True, True, False, True
else: return "", False, False, False, False else: return "", False, False, False, False
def monopolyStop(self,channel):
self.bot.funcs.deleteGame("monopoly games",channel)
return "Stopped game", False, False, False, False

View File

@@ -5,10 +5,11 @@ from funcs import logThis
from PIL import Image, ImageDraw from PIL import Image, ImageDraw
w, h = 1440, 1440 w, h = 1440, 1440
largeSpace = 191 largeSpace = 190
smallSpace = math.floor((w - 2*largeSpace)/9) smallSpace = math.floor((w - 2*largeSpace)/9)
avatarSize = 50 avatarSize = 50
avatarHalf = math.floor(avatarSize/2) avatarHalf = math.floor(avatarSize/2)
avatarBuffer = 10
class DrawMonopoly(): class DrawMonopoly():
def __init__(self,bot): def __init__(self,bot):
@@ -20,11 +21,19 @@ class DrawMonopoly():
board = Image.open("resources/games/monopolyBoard.png") board = Image.open("resources/games/monopolyBoard.png")
d = ImageDraw.Draw(board,"RGBA") d = ImageDraw.Draw(board,"RGBA")
places = {}
for key, value in list(game["players"].items()): for key, value in list(game["players"].items()):
logThis("Drawing "+key) logThis("Drawing "+key)
if value["position"] in places:
places[value["position"]].append(key)
else:
places[value["position"]] = [key]
for key, value in list(places.items()):
for number, player in enumerate(value):
try: try:
x, y = self.getPosition(value["position"]) x, y = self.getPosition(key,number)
except: except:
logThis("Error getting position (error code 1641)") logThis("Error getting position (error code 1641)")
d.ellipse([(x-avatarHalf,y-avatarHalf),(x+avatarHalf,y+avatarHalf)],fill=(255,0,0)) d.ellipse([(x-avatarHalf,y-avatarHalf),(x+avatarHalf,y+avatarHalf)],fill=(255,0,0))
@@ -32,7 +41,7 @@ class DrawMonopoly():
board.save("resources/games/monopolyBoards/monopolyBoard"+channel+".png") board.save("resources/games/monopolyBoards/monopolyBoard"+channel+".png")
def getPosition(self, positionNumber): def getPosition(self, positionNumber, number):
x, y = 0, 0 x, y = 0, 0
if positionNumber == 0 or positionNumber >= 30: if positionNumber == 0 or positionNumber >= 30:
x = math.floor(largeSpace/2) x = math.floor(largeSpace/2)
@@ -52,6 +61,16 @@ class DrawMonopoly():
elif positionNumber > 30: elif positionNumber > 30:
y = h - math.floor(largeSpace - (smallSpace/2)) - (smallSpace*(positionNumber - 30)) y = h - math.floor(largeSpace - (smallSpace/2)) - (smallSpace*(positionNumber - 30))
if number%2 == 1:
x -= avatarBuffer + avatarSize
if math.floor(number/2) == 1:
y += avatarBuffer + avatarSize
elif math.floor(number/2) == 2:
y -= avatarBuffer + avatarSize
x += avatarSize
return x, y return x, y