53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
from kivy import app, properties
|
|
from kivy.uix.label import Label
|
|
from kivy.uix.boxlayout import BoxLayout
|
|
from kivy.graphics import Color, Rectangle
|
|
|
|
from hexmap import Tile
|
|
|
|
|
|
class HexSpace(Label):
|
|
def __init__(self):
|
|
super(HexSpace, self).__init__(size_hint=(0.5, 1), text=':)')
|
|
|
|
|
|
class StrategyGame(BoxLayout):
|
|
main_map = properties.ObjectProperty(None)
|
|
status = properties.ObjectProperty(None)
|
|
map_rows = properties.NumericProperty(0)
|
|
map_cols = properties.NumericProperty(0)
|
|
|
|
def __init__(self, **kwargs):
|
|
super(StrategyGame, self).__init__(**kwargs)
|
|
|
|
for row in range(0, self.map_rows):
|
|
|
|
hex_map_row = BoxLayout(orientation='horizontal')
|
|
|
|
if row % 2 == 1:
|
|
hex_map_row.add_widget(HexSpace())
|
|
|
|
for col in range(0, self.map_cols):
|
|
map_tile = Tile(row=row, col=col)
|
|
hex_map_row.add_widget(map_tile)
|
|
|
|
if row % 2 == 0:
|
|
hex_map_row.add_widget(HexSpace())
|
|
|
|
self.main_map.add_widget(hex_map_row)
|
|
|
|
def update_selected_cell(self, selected_tile, *args):
|
|
self.status.text = selected_tile.map_display_text()
|
|
with self.status.canvas.before:
|
|
Color(*selected_tile.terrain_colour)
|
|
Rectangle(pos=self.status.pos, size=self.status.size)
|
|
return True
|
|
|
|
|
|
class StrategyGameApp(app.App):
|
|
def build(self):
|
|
return StrategyGame()
|
|
|
|
if __name__ == '__main__':
|
|
StrategyGameApp().run()
|