Commit 01/06-24
This commit is contained in:
parent
081a8a948a
commit
efb4ebce97
9 changed files with 152 additions and 51 deletions
95
Main.py
95
Main.py
|
|
@ -13,7 +13,8 @@ import RealmManager
|
|||
|
||||
# pygame setup
|
||||
pygame.init()
|
||||
screen = pygame.display.set_mode((1280, 720))
|
||||
w,h = 1280, 720
|
||||
screen = pygame.display.set_mode((w, h))
|
||||
pygame.display.set_caption('CountDuchKing')
|
||||
clock = pygame.time.Clock()
|
||||
running = True
|
||||
|
|
@ -137,7 +138,11 @@ class uText:
|
|||
if textTest[0] != text and textTest[1] == position:
|
||||
self.texts.remove(textTest)
|
||||
self.texts.append((text,position))
|
||||
print(self.texts)
|
||||
#print("\n\nT E X T S :")
|
||||
#p = []
|
||||
#for t in self.texts:
|
||||
# p.append(t[0])
|
||||
#print(p)
|
||||
|
||||
def delete(self, parameter, info):
|
||||
text2 = []
|
||||
|
|
@ -155,22 +160,30 @@ class uText:
|
|||
textPrintRect = textPrintRect.move(int(text[1][0]),int(text[1][1]))
|
||||
screen.blit(textPrint, textPrintRect)
|
||||
|
||||
def runTextTile(self, tile_pressed):
|
||||
def runResourceView(self, info, mode):
|
||||
i=0
|
||||
info = GameMap.getTileInfo(tile_pressed)
|
||||
self.write(info["terrain"],(1000,50))
|
||||
|
||||
for bit in info["gameplay"]:
|
||||
if True: #type(bit) == "<class 'str'" or type(bit) == "<class 'int'"
|
||||
self.write(bit[0],(840,100 + 50*i))
|
||||
self.write(bit[1],(1090,100 + 50*i))
|
||||
i += 1
|
||||
tile_pressed = str(tile_pressed)
|
||||
tilePrint = self.font.render(tile_pressed, True, (255, 255, 255))
|
||||
tilePrintRect = tilePrint.get_rect()
|
||||
tilePrintRect = tilePrintRect.move(1100,0)
|
||||
screen.blit(tilePrint, tilePrintRect)
|
||||
if mode == "t": #If running resource view for tile
|
||||
info = GameMap.getTileInfo(info)
|
||||
self.write(info["terrain"],(1000,50))
|
||||
|
||||
for bit in info["gameplay"]:
|
||||
if True: #type(bit) == "<class 'str'" or type(bit) == "<class 'int'"
|
||||
self.write(bit[0],(840,100 + 50*i))
|
||||
self.write(bit[1],(1090,100 + 50*i))
|
||||
i += 1
|
||||
tilePrint = self.font.render(info["id"], True, (255, 255, 255))
|
||||
tilePrintRect = tilePrint.get_rect()
|
||||
tilePrintRect = tilePrintRect.move(1100,0)
|
||||
screen.blit(tilePrint, tilePrintRect)
|
||||
if mode == "p": #If running resource view for player
|
||||
info = GameRealms.getPlayer(info).resources
|
||||
self.write("Resources",(1000,50))
|
||||
|
||||
for key in info.keys():
|
||||
self.write(key,(840,100 + 50*i))
|
||||
self.write(info[key],(1090,100 + 50*i))
|
||||
i += 1
|
||||
|
||||
class uButtons:
|
||||
|
||||
def __init__(self):
|
||||
|
|
@ -185,7 +198,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"), delOnAction=False):
|
||||
def addButton(self, name, x, y, width, height, colour_standby=(255,255,255), colour_hover=(200, 200, 200), onAction=None, delOnAction=False):
|
||||
if colour_standby != (255,255,255):
|
||||
if self.colours[colour_standby] != None:
|
||||
colour_standby = self.colours[colour_standby]
|
||||
|
|
@ -234,10 +247,10 @@ class uButtons:
|
|||
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"]))
|
||||
exec(button["button_action"])
|
||||
else:
|
||||
print(f"No action found for button {button["text"]}")
|
||||
|
||||
|
|
@ -246,13 +259,28 @@ class uCommunicate:
|
|||
def __init__(self):
|
||||
self.globalGameState = 0 #0 = preround, 1 = active
|
||||
self.turnHolder = 0
|
||||
self.resourceView = False #False = State resources, True = Player resources
|
||||
self.resourceViewActive = True #False = No Button Rendered, True = Button Rendered
|
||||
|
||||
def startGame(self):
|
||||
GameRealms.load(map)
|
||||
self.globalGameState = 1
|
||||
uButtoner.addButton("Player", 850, 0, 120, 50, "darkgray", "gray", "uCommunicator.switchResourceView()", True)
|
||||
t2 = Thread(target=uCommunicator.gameLoop)
|
||||
t2.start()
|
||||
|
||||
|
||||
def switchResourceView(self):
|
||||
if self.resourceView:
|
||||
uButtoner.addButton("Player", 850, 0, 120, 50, "darkgray", "gray", "uCommunicator.switchResourceView()", True)
|
||||
self.resourceView = False
|
||||
elif not self.resourceView:
|
||||
if tile_pressed != None:
|
||||
uButtoner.addButton("State", 850, 0, 120, 50, "darkgray", "gray", "uCommunicator.switchResourceView()", True)
|
||||
self.resourceViewActive = True
|
||||
else:
|
||||
self.resourceViewActive = False
|
||||
self.resourceView = True
|
||||
|
||||
def gameLoop(self):
|
||||
while self.globalGameState == 1:
|
||||
for x in range(GameRealms.amount):
|
||||
|
|
@ -269,9 +297,22 @@ class uCommunicate:
|
|||
if not GameMap.tIsClaimed(GameMap.paintedTile.Id):
|
||||
ip = GameRealms.getPlayer(f"p1")
|
||||
pt = GameMap.paintedTile
|
||||
print(f"Claiming {pt.Id} for {ip.name}")
|
||||
GameMap.claimTileFor(pt.Id,ip)
|
||||
self.turnHolder += 1
|
||||
if pt.Id in ip.borderTiles and ip.resources["villagers"] > 0:
|
||||
print(f"Claiming {pt.Id} for {ip.name}")
|
||||
GameMap.claimTileFor(pt.Id,ip)
|
||||
for tile in GameMap.findBorderTiles(pt.Id):
|
||||
ip.borderTiles.append(int(tile))
|
||||
ip.resources["villagers"] -= 1
|
||||
self.turnHolder += 1
|
||||
elif ip.resources["settlers"] > 0:
|
||||
print(f"Settling {pt.Id} for {ip.name}")
|
||||
GameMap.claimTileFor(pt.Id,ip)
|
||||
for tile in GameMap.findBorderTiles(pt.Id):
|
||||
ip.borderTiles.append(int(tile))
|
||||
ip.resources["settlers"] -= 1
|
||||
self.turnHolder += 1
|
||||
else:
|
||||
self.turnHolder += 1
|
||||
|
||||
def expand_cccs(self, ccc):
|
||||
print(f"Using ccc = {ccc}")
|
||||
|
|
@ -352,6 +393,7 @@ while running:
|
|||
# pygame.QUIT event means the user clicked X to close your window
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
uCommunicator.globalGameState = 0
|
||||
running = False
|
||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||
if pygame.mouse.get_pressed()[0] == True:
|
||||
|
|
@ -366,8 +408,13 @@ while running:
|
|||
# fill the screen with a color to wipe away anything from last frame
|
||||
screen.fill("black")
|
||||
|
||||
if tile_pressed != None:
|
||||
uTexter.runTextTile(tile_pressed)
|
||||
if uCommunicator.resourceViewActive == False and uCommunicator.resourceView == True and tile_pressed != None:
|
||||
uButtoner.addButton("State", 850, 0, 120, 50, "darkgray", "gray", "uCommunicator.switchResourceView()", True)
|
||||
|
||||
if tile_pressed != None and uCommunicator.resourceView == False:
|
||||
uTexter.runResourceView(tile_pressed, "t")
|
||||
elif uCommunicator.globalGameState == 1:
|
||||
uTexter.runResourceView("p1", "p")
|
||||
|
||||
uButtoner.updateHover()
|
||||
uButtoner.drawButtons()
|
||||
|
|
|
|||
|
|
@ -148,14 +148,18 @@ class MapManager:
|
|||
tilesMapped[position[0]][position[1]] = self.TileWorker.get_rand_tType(tilesMapped, position)
|
||||
#print(f"{tilesMapped}")
|
||||
mappedColours = self.TileWorker.get_terrain("colours")
|
||||
print("Assigning terrains and features...")
|
||||
for x in self.tiles.keys():
|
||||
tile = self.tiles[f"{x}"]
|
||||
if tilesMapped[tile.Position[0]][tile.Position[1]] != "":
|
||||
colour = mappedColours[f"{tilesMapped[tile.Position[0]][tile.Position[1]]}"]
|
||||
terrain = f"{tilesMapped[tile.Position[0]][tile.Position[1]]}"
|
||||
colour = mappedColours[terrain]
|
||||
colour1, colour2, colour3 = colour[0], colour[1], colour[2]
|
||||
tile.add_terrain(f"{tilesMapped[tile.Position[0]][tile.Position[1]]}")
|
||||
tile.add_terrain(terrain)
|
||||
tile.paint_pixels(mapObject, int(colour1),int(colour2),int(colour3))
|
||||
tile.findBorder(mapObject)
|
||||
tile.add_resources(self.TileWorker.get_resource_for(terrain))
|
||||
|
||||
|
||||
def re_load(self):
|
||||
print("To Be Implomented")
|
||||
|
|
@ -179,6 +183,30 @@ class MapManager:
|
|||
print(f"Could not find tile at position: {pos[0]},{pos[1]}")
|
||||
return None
|
||||
|
||||
def findBorderTiles(self, id):
|
||||
bTiles = []
|
||||
id = int(id)
|
||||
pos = self.tiles[str(id)].Position
|
||||
if id != 0:
|
||||
bTiles.append(id-1)
|
||||
if self.findTileAtRel((pos[0],pos[1]-1)):
|
||||
bTiles.append(self.findTileAtRel((pos[0],pos[1]-1)))
|
||||
if self.findTileAtRel((pos[0],pos[1]+1)):
|
||||
bTiles.append(self.findTileAtRel((pos[0],pos[1]+1)))
|
||||
if pos[1] % 2 == 1:
|
||||
pos1 = (pos[0]+1)
|
||||
else:
|
||||
pos1 = (pos[0]-1)
|
||||
bTiles.append(self.findTileAtRel((pos1,pos[1]-1)))
|
||||
bTiles.append(self.findTileAtRel((pos1,pos[1]+1)))
|
||||
|
||||
if pos[1] == self.tiles[str(id+1)].Position[1]:
|
||||
bTiles.append(id+1)
|
||||
print(f"Tile: {id}/{pos} has bordertiles: ")
|
||||
for tile in bTiles:
|
||||
print(f"{tile}/{self.tiles[str(tile)].Position}")
|
||||
return bTiles
|
||||
|
||||
def findTileAtRel(self, pos):
|
||||
for x in self.tiles.keys():
|
||||
tile = self.tiles[f"{x}"]
|
||||
|
|
@ -200,6 +228,10 @@ class MapManager:
|
|||
info["gameplay"] = thistile.getGameplayInfo()
|
||||
return info
|
||||
|
||||
def illegalTilePaint(self, id, mapObject):
|
||||
tile = self.tiles[str(id)]
|
||||
tile.paint_border_pixels(mapObject)
|
||||
|
||||
def paintTileBorder(self, id, mapObject):
|
||||
if self.paintedTile != None:
|
||||
self.clearPaintedTile(mapObject)
|
||||
|
|
@ -233,7 +265,7 @@ class Tile:
|
|||
self.pixels = []
|
||||
self.colour = (0,0,0)
|
||||
self.terrain = ""
|
||||
self.resources = {}
|
||||
self.resources = []
|
||||
self.buildings = []
|
||||
self.units = {}
|
||||
self.owner = "Unclaimed"
|
||||
|
|
@ -264,6 +296,10 @@ class Tile:
|
|||
def add_terrain(self, terrain):
|
||||
self.terrain = terrain
|
||||
#print(f"Added terrain for tile {self.Id}, it is now a {self.terrain} / {terrain} biome")
|
||||
|
||||
def add_resources(self, resources):
|
||||
for resource in resources:
|
||||
self.resources.append(resource)
|
||||
|
||||
def paint_pixels(self, map, r,g,b):
|
||||
for pixel in self.pixels:
|
||||
|
|
|
|||
|
|
@ -4,19 +4,19 @@ class TerrainWorker:
|
|||
|
||||
def generateTerrain(self):
|
||||
self.terrains = []
|
||||
ocean = Terrain("ocean", (0, 102, 255), 2, True, ("plains", "forest", "hills"))
|
||||
ocean = Terrain("ocean", (0, 102, 255), 2, True, ("plains", "forest", "hills"),((0.5,"food"),))
|
||||
self.terrains.append(ocean)
|
||||
lake = Terrain("lake", (0, 204, 255), 1, True, ("plains", "forest", "hills"))
|
||||
lake = Terrain("lake", (0, 204, 255), 1, True, ("plains", "forest", "hills"),((1,"food"),))
|
||||
self.terrains.append(lake)
|
||||
plains = Terrain("plains", (0, 200, 0), 1, False, ("ocean", "lake", "forest", "hills", "desert"))
|
||||
plains = Terrain("plains", (0, 200, 0), 1, False, ("ocean", "lake", "forest", "hills", "desert"),((0.5,"food"),(0.25,"wood"),(0.25,"stone")))
|
||||
self.terrains.append(plains)
|
||||
forest = Terrain("forest", (0, 100, 0), 2, False, ("ocean", "lake", "plains", "hills"))
|
||||
forest = Terrain("forest", (0, 100, 0), 2, False, ("ocean", "lake", "plains", "hills"),((1,"wood"),(0.25,"stone"),(0.25,"food")))
|
||||
self.terrains.append(forest)
|
||||
hills = Terrain("hills", (102, 102, 153), 2, False, ("ocean", "lake", "plains", "forest"))
|
||||
hills = Terrain("hills", (102, 102, 153), 2, False, ("ocean", "lake", "plains", "forest"),((1,"stone"),(0.25,"wood"),(0.25,"food")))
|
||||
self.terrains.append(hills)
|
||||
desert = Terrain("desert", (230, 230, 0), 1, False, ("plains", "dune"))
|
||||
desert = Terrain("desert", (230, 230, 0), 1, False, ("plains", "dune"),((0.25,"stone"),))
|
||||
self.terrains.append(desert)
|
||||
dune = Terrain("dune", (153, 153, 0), 2, False, ("desert",))
|
||||
dune = Terrain("dune", (153, 153, 0), 2, False, ("desert",),((0.5,"stone"),))
|
||||
self.terrains.append(dune)
|
||||
self.terrainNames = []
|
||||
for terrain in self.terrains:
|
||||
|
|
@ -34,6 +34,11 @@ class TerrainWorker:
|
|||
#print(f"{dictionary}")
|
||||
return dictionary
|
||||
|
||||
def get_resource_for(self, terrainName):
|
||||
for terrain in self.terrains:
|
||||
if terrain.name == terrainName:
|
||||
return terrain.resources
|
||||
|
||||
def biomebalance(self, biome):
|
||||
if biome == "ocean":
|
||||
return 2
|
||||
|
|
@ -83,9 +88,10 @@ class TerrainWorker:
|
|||
|
||||
class Terrain:
|
||||
|
||||
def __init__(self, name, colour, moveC, water, proxys):
|
||||
def __init__(self, name, colour, moveC, water, proxys, resources):
|
||||
self.name = name
|
||||
self.colour = colour
|
||||
self.moveCost = moveC
|
||||
self.isWater = water
|
||||
self.proxys = proxys
|
||||
self.proxys = proxys
|
||||
self.resources = resources
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -8,18 +8,22 @@ class RealmManager:
|
|||
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()
|
||||
temptext = open("./Realms/valid_border_colours.txt", "r")
|
||||
self.colournames = temptext.read()
|
||||
print (self.colournames)
|
||||
self.colournames = self.colournames.split("\n")
|
||||
temptext.close()
|
||||
for x in range(self.amount):
|
||||
if x == 0:
|
||||
self.players[0] = Player("p1", self.colournames)
|
||||
self.players[x] = Player("c", self.colournames, x, self.compnames)
|
||||
c = self.colournames[random.randint(0,len(self.colournames)-1)]
|
||||
self.players[0] = Player("p1", c)
|
||||
self.colournames.remove(c)
|
||||
c1 = self.colournames[random.randint(0,len(self.colournames)-1)]
|
||||
c2 = self.compnames[random.randint(0,len(self.compnames)-1)]
|
||||
self.players[x] = Player("c", c1, x, c2)
|
||||
self.colournames.remove(c1)
|
||||
self.compnames.remove(c2)
|
||||
for x in self.players:
|
||||
p = self.players[x]
|
||||
print(f"Player {p.id}/{p.name} with colour {p.borderColour}")
|
||||
|
|
@ -33,13 +37,21 @@ class RealmManager:
|
|||
|
||||
class Player:
|
||||
|
||||
def __init__(self, controller, colour, id=0, names=None,):
|
||||
def __init__(self, controller, colour, id=0, name=None,):
|
||||
self.resources = {
|
||||
"settlers": 1,
|
||||
"villagers": 4,
|
||||
"wood": 0.0,
|
||||
"stone": 0.0,
|
||||
"food": 0.0,
|
||||
"weapons": 0.0,
|
||||
"tools": 0.0,
|
||||
}
|
||||
self.id = id
|
||||
self.controller = controller
|
||||
self.heldTiles = []
|
||||
colour = colour[random.randint(0,len(colour)-1)]
|
||||
self.borderTiles = []
|
||||
colour = colour.split(",")
|
||||
print (colour)
|
||||
self.borderColour = (int(colour[0]),int(colour[1]),int(colour[2]))
|
||||
if controller == "c":
|
||||
self.name = names[random.randint(0,len(names)-1)]
|
||||
self.name = name
|
||||
Binary file not shown.
|
|
@ -1,8 +1,8 @@
|
|||
255,0,0
|
||||
255,255,0
|
||||
255,51,102
|
||||
204,0,102
|
||||
255,128,0
|
||||
255,0,255
|
||||
0,0,0
|
||||
160,160,160
|
||||
0,100,0
|
||||
255,100,255
|
||||
180,0,180
|
||||
255,255,0
|
||||
102,0,204
|
||||
255,255,102
|
||||
204,51,255
|
||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue