diff --git a/Main.py b/Main.py index 894b353..4dddbed 100644 --- a/Main.py +++ b/Main.py @@ -4,9 +4,11 @@ from threading import Thread sys.path.append('./Map') sys.path.append('./Script') +sys.path.append('./Realms') import ScriptUtils import MapManager +import RealmManager # pygame setup pygame.init() @@ -182,7 +184,7 @@ class uButtons: "blue": (0, 0, 255,) } - def addButton(self, name, x, y, width, height, colour_standby=(255,255,255), colour_hover=(200, 200, 200), onAction=print("Button pressed")): + def addButton(self, name, x, y, width, height, colour_standby=(255,255,255), colour_hover=(200, 200, 200), onAction=print("Button pressed"), delOnAction=False): if colour_standby != (255,255,255): if self.colours[colour_standby] != None: colour_standby = self.colours[colour_standby] @@ -202,6 +204,7 @@ class uButtons: "colour_standby": colour_standby, "colour_hover": colour_hover, "button_action": onAction, + "delOnAction": delOnAction, "isHover": False } self.buttons.append(button) @@ -213,6 +216,8 @@ class uButtons: if pos[0] > button["xPos"] and pos[0] < button["xPos"] + button["width"]: if pos[1] > button["yPos"] and pos[1] < button["yPos"] + button["height"]: button["isHover"] = True + elif button["isHover"] == True: + button["isHover"] = False elif button["isHover"] == True: button["isHover"] = False @@ -223,19 +228,44 @@ class uButtons: pygame.draw.rect(screen,(button["colour_standby"]),buttonRect) else: pygame.draw.rect(screen,(button["colour_hover"]),buttonRect) + + def pressed(self, pos): + for button in self.buttons: + if button["isHover"] == True: + if button["button_action"] != None: + exec(button["button_action"]) + if button["delOnAction"] == True: + self.buttons.remove(button) + uTexter.write("",(button["xPos"],button["yPos"])) + else: + print(f"No action found for button {button["text"]}") + +class uCommunicate: + + def claimState(): + if GameMap.paintedTile: + ip = GameRealms.getPlayer("p1") + pt = GameMap.paintedTile + print(f"Claiming {pt.Id} for {ip.name}") + + uButtoner = uButtons() uTexter = uText() +uCommunicator = uCommunicate() def prerenderGraphics(): uTexter.write("State",(1000,0)) - uButtoner.addButton("Claim",850,600,110,40,"darkgray","gray") + uButtoner.addButton("Start Game", 850, 500, 200, 50, "darkgray", "gray", "GameRealms.load(map)", True) + uButtoner.addButton("Claim",850,600,110,40,"darkgray","gray","uCommunicate.claimState()") + uButtoner.addButton("ReRender", 1000, 600, 180, 50, "gray", "blue","GameMap.re_load()") prerenderGraphics() - pygame.image.save(map, "./Map/Images/blackstripes.png") +GameRealms = RealmManager.RealmManager() + GameMap = MapManager.MapManager() GameMap.load(map) @@ -265,9 +295,11 @@ while running: if pygame.mouse.get_pressed()[0] == True: print(f"MB1 is true") pos = pygame.mouse.get_pos() - tile_pressed = GameMap.findTileAt(pos) - if tile_pressed != None: - GameMap.paintTileBorder(tile_pressed, map) + uButtoner.pressed(pos) + if pos[0] < 830 and pos[1] < 580: + tile_pressed = GameMap.findTileAt(pos) + if tile_pressed != None: + GameMap.paintTileBorder(tile_pressed, map) # fill the screen with a color to wipe away anything from last frame screen.fill("black") diff --git a/Map/Images/sampledone.png b/Map/Images/sampledone.png index 37d7091..c58c3ca 100644 Binary files a/Map/Images/sampledone.png and b/Map/Images/sampledone.png differ diff --git a/Map/MapManager.py b/Map/MapManager.py index 9da9ce5..f9d9aa8 100644 --- a/Map/MapManager.py +++ b/Map/MapManager.py @@ -157,6 +157,9 @@ class MapManager: tile.paint_pixels(mapObject, int(colour1),int(colour2),int(colour3)) tile.findBorder(mapObject) + def re_load(self): + print("To Be Implomented") + def findTileAt(self, pos): for x in self.tiles.keys(): tile = self.tiles[f"{x}"] @@ -192,6 +195,8 @@ class MapManager: self.paintedTile.paint_border_pixels(mapObject) self.paintedTile = None print("Cleared previous tile") + + def claimTileFor(self, tileID): class Tile: diff --git a/Map/__pycache__/MapManager.cpython-312.pyc b/Map/__pycache__/MapManager.cpython-312.pyc index d751afa..47a2228 100644 Binary files a/Map/__pycache__/MapManager.cpython-312.pyc and b/Map/__pycache__/MapManager.cpython-312.pyc differ diff --git a/Map/__pycache__/TileTypes.cpython-312.pyc b/Map/__pycache__/TileTypes.cpython-312.pyc index b0bab43..aa1fb08 100644 Binary files a/Map/__pycache__/TileTypes.cpython-312.pyc and b/Map/__pycache__/TileTypes.cpython-312.pyc differ diff --git a/Realms/RealmManager.py b/Realms/RealmManager.py index e69de29..f3900c0 100644 --- a/Realms/RealmManager.py +++ b/Realms/RealmManager.py @@ -0,0 +1,36 @@ +import random + +class RealmManager: + + def load(self, mapObject, amount=6): + print("Loading Players...") + self.players = {} + self.amount = amount + temptext = open("./Realms/computer_names.txt", "r") + self.compnames = temptext.read() + print (self.compnames) + self.compnames = self.compnames.split("\n") + temptext.close() + for x in range(self.amount): + if x == 0: + self.players[0] = Player("p1") + self.players[x] = Player("c", x, self.compnames) + for x in self.players: + p = self.players[x] + print(f"Player {p.id}/{p.name} with colour {p.borderColour}") + + def getPlayer(self, detail): + if detail == "p1": + return self.players[0] + else: + print("oopsie") + + +class Player: + + def __init__(self, controller, id=0, names=None): + self.id = id + self.controller = controller + self.borderColour = (random.randint(10,240),random.randint(10,240),random.randint(10,240)) + if controller == "c": + self.name = names[random.randint(0,len(names)-1)] \ No newline at end of file diff --git a/Realms/__pycache__/RealmManager.cpython-312.pyc b/Realms/__pycache__/RealmManager.cpython-312.pyc new file mode 100644 index 0000000..d26163c Binary files /dev/null and b/Realms/__pycache__/RealmManager.cpython-312.pyc differ diff --git a/Realms/computer_names.txt b/Realms/computer_names.txt new file mode 100644 index 0000000..a5ed8ed --- /dev/null +++ b/Realms/computer_names.txt @@ -0,0 +1,10 @@ +Charles +Gustaf +Darwin +Alexander +Cleopatra +Elizabeth +Günther +Hans +Lisa +Alexandra \ No newline at end of file diff --git a/Realms/template.realm b/Realms/template.realm deleted file mode 100644 index e69de29..0000000 diff --git a/Script/__pycache__/ScriptUtils.cpython-312.pyc b/Script/__pycache__/ScriptUtils.cpython-312.pyc index 24c6d33..c3644de 100644 Binary files a/Script/__pycache__/ScriptUtils.cpython-312.pyc and b/Script/__pycache__/ScriptUtils.cpython-312.pyc differ