Commit 23/05-24
This commit is contained in:
parent
b34722cc51
commit
64261170d5
10 changed files with 89 additions and 6 deletions
44
Main.py
44
Main.py
|
|
@ -4,9 +4,11 @@ from threading import Thread
|
||||||
|
|
||||||
sys.path.append('./Map')
|
sys.path.append('./Map')
|
||||||
sys.path.append('./Script')
|
sys.path.append('./Script')
|
||||||
|
sys.path.append('./Realms')
|
||||||
|
|
||||||
import ScriptUtils
|
import ScriptUtils
|
||||||
import MapManager
|
import MapManager
|
||||||
|
import RealmManager
|
||||||
|
|
||||||
# pygame setup
|
# pygame setup
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
@ -182,7 +184,7 @@ class uButtons:
|
||||||
"blue": (0, 0, 255,)
|
"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 colour_standby != (255,255,255):
|
||||||
if self.colours[colour_standby] != None:
|
if self.colours[colour_standby] != None:
|
||||||
colour_standby = self.colours[colour_standby]
|
colour_standby = self.colours[colour_standby]
|
||||||
|
|
@ -202,6 +204,7 @@ class uButtons:
|
||||||
"colour_standby": colour_standby,
|
"colour_standby": colour_standby,
|
||||||
"colour_hover": colour_hover,
|
"colour_hover": colour_hover,
|
||||||
"button_action": onAction,
|
"button_action": onAction,
|
||||||
|
"delOnAction": delOnAction,
|
||||||
"isHover": False
|
"isHover": False
|
||||||
}
|
}
|
||||||
self.buttons.append(button)
|
self.buttons.append(button)
|
||||||
|
|
@ -213,6 +216,8 @@ class uButtons:
|
||||||
if pos[0] > button["xPos"] and pos[0] < button["xPos"] + button["width"]:
|
if pos[0] > button["xPos"] and pos[0] < button["xPos"] + button["width"]:
|
||||||
if pos[1] > button["yPos"] and pos[1] < button["yPos"] + button["height"]:
|
if pos[1] > button["yPos"] and pos[1] < button["yPos"] + button["height"]:
|
||||||
button["isHover"] = True
|
button["isHover"] = True
|
||||||
|
elif button["isHover"] == True:
|
||||||
|
button["isHover"] = False
|
||||||
elif button["isHover"] == True:
|
elif button["isHover"] == True:
|
||||||
button["isHover"] = False
|
button["isHover"] = False
|
||||||
|
|
||||||
|
|
@ -223,19 +228,44 @@ class uButtons:
|
||||||
pygame.draw.rect(screen,(button["colour_standby"]),buttonRect)
|
pygame.draw.rect(screen,(button["colour_standby"]),buttonRect)
|
||||||
else:
|
else:
|
||||||
pygame.draw.rect(screen,(button["colour_hover"]),buttonRect)
|
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()
|
uButtoner = uButtons()
|
||||||
uTexter = uText()
|
uTexter = uText()
|
||||||
|
uCommunicator = uCommunicate()
|
||||||
|
|
||||||
def prerenderGraphics():
|
def prerenderGraphics():
|
||||||
uTexter.write("State",(1000,0))
|
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()
|
prerenderGraphics()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pygame.image.save(map, "./Map/Images/blackstripes.png")
|
pygame.image.save(map, "./Map/Images/blackstripes.png")
|
||||||
|
|
||||||
|
GameRealms = RealmManager.RealmManager()
|
||||||
|
|
||||||
GameMap = MapManager.MapManager()
|
GameMap = MapManager.MapManager()
|
||||||
|
|
||||||
GameMap.load(map)
|
GameMap.load(map)
|
||||||
|
|
@ -265,9 +295,11 @@ while running:
|
||||||
if pygame.mouse.get_pressed()[0] == True:
|
if pygame.mouse.get_pressed()[0] == True:
|
||||||
print(f"MB1 is true")
|
print(f"MB1 is true")
|
||||||
pos = pygame.mouse.get_pos()
|
pos = pygame.mouse.get_pos()
|
||||||
tile_pressed = GameMap.findTileAt(pos)
|
uButtoner.pressed(pos)
|
||||||
if tile_pressed != None:
|
if pos[0] < 830 and pos[1] < 580:
|
||||||
GameMap.paintTileBorder(tile_pressed, map)
|
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
|
# fill the screen with a color to wipe away anything from last frame
|
||||||
screen.fill("black")
|
screen.fill("black")
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 6.7 KiB |
|
|
@ -157,6 +157,9 @@ class MapManager:
|
||||||
tile.paint_pixels(mapObject, int(colour1),int(colour2),int(colour3))
|
tile.paint_pixels(mapObject, int(colour1),int(colour2),int(colour3))
|
||||||
tile.findBorder(mapObject)
|
tile.findBorder(mapObject)
|
||||||
|
|
||||||
|
def re_load(self):
|
||||||
|
print("To Be Implomented")
|
||||||
|
|
||||||
def findTileAt(self, pos):
|
def findTileAt(self, pos):
|
||||||
for x in self.tiles.keys():
|
for x in self.tiles.keys():
|
||||||
tile = self.tiles[f"{x}"]
|
tile = self.tiles[f"{x}"]
|
||||||
|
|
@ -192,6 +195,8 @@ class MapManager:
|
||||||
self.paintedTile.paint_border_pixels(mapObject)
|
self.paintedTile.paint_border_pixels(mapObject)
|
||||||
self.paintedTile = None
|
self.paintedTile = None
|
||||||
print("Cleared previous tile")
|
print("Cleared previous tile")
|
||||||
|
|
||||||
|
def claimTileFor(self, tileID):
|
||||||
|
|
||||||
|
|
||||||
class Tile:
|
class Tile:
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -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)]
|
||||||
BIN
Realms/__pycache__/RealmManager.cpython-312.pyc
Normal file
BIN
Realms/__pycache__/RealmManager.cpython-312.pyc
Normal file
Binary file not shown.
10
Realms/computer_names.txt
Normal file
10
Realms/computer_names.txt
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
Charles
|
||||||
|
Gustaf
|
||||||
|
Darwin
|
||||||
|
Alexander
|
||||||
|
Cleopatra
|
||||||
|
Elizabeth
|
||||||
|
Günther
|
||||||
|
Hans
|
||||||
|
Lisa
|
||||||
|
Alexandra
|
||||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue