Mar-10-2021, 01:34 PM
I am trying to learn python through making a game. In my game, I used a script that built the set up for Settlers of Catan. My board is slightly larger and I can move a game piece around the board to different hexes.
Now, in each hex I am looking to have different options based where the game piece is and the hex type (color for now but later art). At the moment, I just want to print the hex type (called environment, like lava and basalt) is when I press a key.
This is how I am drawing each hex and board.
class Board:
hexes = []
def __init__(self, size):
self.cX = screen.get_rect().centerx
self.cY = screen.get_rect().centery
self.hexHeight = 0.866 * size
~ ~ ~
# Second Ring
self.tiles = [LAVA, BASALT]*3
random.shuffle(self.tiles)
# Second Ring of hexes
self.hexes.append(Hex((self.cX, self.cY - (2*self.hexHeight)), size, self.tiles[0]))
self.hexes.append(Hex((self.cX - (1.5*size), self.cY - self.hexHeight), size, self.tiles[1]))
self.hexes.append(Hex((self.cX - (1.5*size), self.cY + self.hexHeight), size, self.tiles[2]))
self.hexes.append(Hex((self.cX, self.cY + (2*self.hexHeight)), size, self.tiles[3]))
self.hexes.append(Hex((self.cX + (1.5*size), self.cY + self.hexHeight), size, self.tiles[4]))
self.hexes.append(Hex((self.cX + (1.5*size), self.cY - self.hexHeight), size, self.tiles[5]))
~ ~ ~
Then, later when I press number key 5...and this is where I am stuck. I want to say something like...
elif event.key == K_KP5:
if HEX == LAVA:
print("LAVA")
I'd be happy to share the entire script in a pm for those interested.
Now, in each hex I am looking to have different options based where the game piece is and the hex type (color for now but later art). At the moment, I just want to print the hex type (called environment, like lava and basalt) is when I press a key.
This is how I am drawing each hex and board.
class Board:
hexes = []
def __init__(self, size):
self.cX = screen.get_rect().centerx
self.cY = screen.get_rect().centery
self.hexHeight = 0.866 * size
~ ~ ~
# Second Ring
self.tiles = [LAVA, BASALT]*3
random.shuffle(self.tiles)
# Second Ring of hexes
self.hexes.append(Hex((self.cX, self.cY - (2*self.hexHeight)), size, self.tiles[0]))
self.hexes.append(Hex((self.cX - (1.5*size), self.cY - self.hexHeight), size, self.tiles[1]))
self.hexes.append(Hex((self.cX - (1.5*size), self.cY + self.hexHeight), size, self.tiles[2]))
self.hexes.append(Hex((self.cX, self.cY + (2*self.hexHeight)), size, self.tiles[3]))
self.hexes.append(Hex((self.cX + (1.5*size), self.cY + self.hexHeight), size, self.tiles[4]))
self.hexes.append(Hex((self.cX + (1.5*size), self.cY - self.hexHeight), size, self.tiles[5]))
~ ~ ~
Then, later when I press number key 5...and this is where I am stuck. I want to say something like...
elif event.key == K_KP5:
if HEX == LAVA:
print("LAVA")
I'd be happy to share the entire script in a pm for those interested.