From 0e4bdea3c7525632c524b588485cfa1ca74b6b1a Mon Sep 17 00:00:00 2001 From: NikolajDanger Date: Thu, 20 Aug 2020 15:28:43 +0200 Subject: [PATCH] :game_die: --- funcs/games/gameLoops.py | 8 ++++---- funcs/games/monopoly.py | 32 +++++++++++++++++++------------- funcs/games/monopolyDraw.py | 33 ++++++++++++++++++++++++++------- 3 files changed, 49 insertions(+), 24 deletions(-) diff --git a/funcs/games/gameLoops.py b/funcs/games/gameLoops.py index 4a558bf..b5584e1 100644 --- a/funcs/games/gameLoops.py +++ b/funcs/games/gameLoops.py @@ -93,10 +93,10 @@ class GameLoops(): self.bot.funcs.deleteGame("4 in a row games",str(channel.id)) async def runMonopoly(self,channel, command, user): - try: - response, showImage, deleteImage, gameStarted, gameContinue = self.bot.monopoly.parseMonopoly(command,str(channel.id),user) - except: - logThis("Error parsing command (error code 1610)") + #try: + response, showImage, deleteImage, gameStarted, gameContinue = self.bot.monopoly.parseMonopoly(command,str(channel.id),user) + #except: + # logThis("Error parsing command (error code 1610)") if response != "": await channel.send(response) logThis(response,str(channel.id)) diff --git a/funcs/games/monopoly.py b/funcs/games/monopoly.py index 749e12f..f8e810f 100644 --- a/funcs/games/monopoly.py +++ b/funcs/games/monopoly.py @@ -24,10 +24,10 @@ class Monopoly(): self.bot.database["monopoly games"].insert_one(newGame) - try: - self.draw.drawImage(channel) - except: - logThis("Error drawing board (error code 1640)") + #try: + self.draw.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: @@ -73,6 +73,8 @@ class Monopoly(): return self.monopolyRoll(channel,user) except: logThis("Error rolling (error code 1650)") + elif commands[0] == "stop": + return self.monopolyStop(channel) else: 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}}) playerList = list(game["players"].keys()) - try: - self.draw.drawImage(channel) - except: - logThis("Error drawing board (error code 1640)") + #try: + self.draw.drawImage(channel) + #except: + # logThis("Error drawing board (error code 1640)") if playerList == []: return "No one joined. Ending game.", False, True, True @@ -112,7 +114,7 @@ class Monopoly(): turn = game["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)] message = self.bot.funcs.getName(user)+" rolled a "+str(rolls[0])+" and a "+str(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":{"last roll":rolls}}) - try: - self.draw.drawImage(channel) - except: - logThis("Error drawing board (error code 1640)") + #try: + self.draw.drawImage(channel) + #except: + # logThis("Error drawing board (error code 1640)") return message, True, True, False, True else: return "", False, False, False, False + + def monopolyStop(self,channel): + self.bot.funcs.deleteGame("monopoly games",channel) + return "Stopped game", False, False, False, False diff --git a/funcs/games/monopolyDraw.py b/funcs/games/monopolyDraw.py index 20cbf34..a4b848e 100644 --- a/funcs/games/monopolyDraw.py +++ b/funcs/games/monopolyDraw.py @@ -5,10 +5,11 @@ from funcs import logThis from PIL import Image, ImageDraw w, h = 1440, 1440 -largeSpace = 191 +largeSpace = 190 smallSpace = math.floor((w - 2*largeSpace)/9) avatarSize = 50 avatarHalf = math.floor(avatarSize/2) +avatarBuffer = 10 class DrawMonopoly(): def __init__(self,bot): @@ -20,19 +21,27 @@ class DrawMonopoly(): board = Image.open("resources/games/monopolyBoard.png") d = ImageDraw.Draw(board,"RGBA") + places = {} for key, value in list(game["players"].items()): logThis("Drawing "+key) - try: - x, y = self.getPosition(value["position"]) - except: - logThis("Error getting position (error code 1641)") - d.ellipse([(x-avatarHalf,y-avatarHalf),(x+avatarHalf,y+avatarHalf)],fill=(255,0,0)) + 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: + x, y = self.getPosition(key,number) + except: + logThis("Error getting position (error code 1641)") + d.ellipse([(x-avatarHalf,y-avatarHalf),(x+avatarHalf,y+avatarHalf)],fill=(255,0,0)) board.save("resources/games/monopolyBoards/monopolyBoard"+channel+".png") - def getPosition(self, positionNumber): + def getPosition(self, positionNumber, number): x, y = 0, 0 if positionNumber == 0 or positionNumber >= 30: x = math.floor(largeSpace/2) @@ -52,6 +61,16 @@ class DrawMonopoly(): elif 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