2016-11-14 22:40:47 -05:00
|
|
|
import random
|
|
|
|
|
2016-06-04 20:37:39 -04:00
|
|
|
from kivy import app, properties
|
2016-11-14 22:40:47 -05:00
|
|
|
from kivy.uix.button import Button
|
|
|
|
from kivy.uix.label import Label
|
|
|
|
from kivy.uix.boxlayout import BoxLayout
|
|
|
|
from kivy.graphics import Color, Rectangle, Ellipse
|
2016-07-16 23:59:28 -04:00
|
|
|
|
2016-07-16 17:49:58 -04:00
|
|
|
from hexmap import HexMapCell
|
2016-06-04 14:59:40 -04:00
|
|
|
|
2016-06-04 15:35:33 -04:00
|
|
|
|
2016-11-14 22:40:47 -05:00
|
|
|
class HexSpace(Label):
|
|
|
|
def __init__(self):
|
|
|
|
super(HexSpace, self).__init__(size_hint=(0.5, 1), text=':)')
|
|
|
|
|
|
|
|
|
|
|
|
class StrategyGame(BoxLayout):
|
2016-06-04 15:23:40 -04:00
|
|
|
main_map = properties.ObjectProperty(None)
|
2016-07-16 19:35:29 -04:00
|
|
|
status = properties.ObjectProperty(None)
|
2016-06-04 15:23:40 -04:00
|
|
|
map_rows = properties.NumericProperty(0)
|
|
|
|
map_cols = properties.NumericProperty(0)
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super(StrategyGame, self).__init__(**kwargs)
|
|
|
|
|
2016-11-14 22:40:47 -05:00
|
|
|
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 = HexMapCell(col=col, row=row)
|
|
|
|
# map_tile.visible_on_map = True
|
|
|
|
# map_tile.disabled = False
|
|
|
|
|
|
|
|
# map_tile.bind(pos=map_tile.update_pos, size=map_tile.update_pos)
|
|
|
|
|
|
|
|
map_tile = Button(text="{} {}".format(col, row), background_color=(
|
|
|
|
random.random(), random.random(), random.random(), 0.6))
|
|
|
|
with map_tile.canvas.after:
|
|
|
|
Color(random.random(), random.random(), random.random(), 0.6)
|
|
|
|
solid_x = map_tile.x - map_tile.height
|
|
|
|
solid_y = map_tile.y - map_tile.height
|
|
|
|
solid_size = (map_tile.height, map_tile.height)
|
|
|
|
Ellipse(pos=(solid_x, solid_y), size=solid_size, segments=6)
|
|
|
|
|
|
|
|
hex_map_row.add_widget(map_tile)
|
2016-06-04 15:35:33 -04:00
|
|
|
|
2016-11-14 22:40:47 -05:00
|
|
|
if row % 2 == 0:
|
|
|
|
hex_map_row.add_widget(HexSpace())
|
2016-06-04 15:35:33 -04:00
|
|
|
|
2016-11-14 22:40:47 -05:00
|
|
|
self.main_map.add_widget(hex_map_row)
|
2016-07-16 14:00:48 -04:00
|
|
|
|
2016-11-14 22:40:47 -05:00
|
|
|
# number_of_regions = self.map_rows * self.map_cols
|
|
|
|
# for region in range(0, number_of_regions):
|
|
|
|
# row = region / self.map_cols
|
|
|
|
# col = region % self.map_cols
|
|
|
|
#
|
|
|
|
# # Add hex cells to make up the map.
|
|
|
|
# hex_cell = HexMapCell(row, col)
|
|
|
|
# hex_cell.disabled = True
|
|
|
|
# self.main_map.add_widget(hex_cell)
|
|
|
|
#
|
|
|
|
# # Add overlay conditionally.
|
|
|
|
# if (row % 6 == 1 and col % 2 == 1) or (row % 6 == 4 and col % 2 == 0) and (col > 0):
|
|
|
|
# hex_cell.disabled = False
|
|
|
|
# hex_cell.visible_on_map = True
|
|
|
|
#
|
|
|
|
# # Bind the cell code so as to update its position and size when the parent widget resizes.
|
|
|
|
# hex_cell.bind(pos=hex_cell.update_pos, size=hex_cell.update_pos)
|
|
|
|
#
|
2016-06-05 01:20:00 -04:00
|
|
|
|
2016-07-16 19:40:30 -04:00
|
|
|
def update_selected_cell(self, coords, terrain_colour, *args):
|
2016-07-16 19:35:29 -04:00
|
|
|
self.status.text = 'Coords: ({}, {})'.format(coords[0], coords[1])
|
2016-07-16 20:09:28 -04:00
|
|
|
with self.status.canvas.before:
|
|
|
|
Color(*terrain_colour)
|
|
|
|
Rectangle(pos=self.status.pos, size=self.status.size)
|
2016-07-16 19:35:29 -04:00
|
|
|
return True
|
|
|
|
|
2016-06-04 20:37:39 -04:00
|
|
|
|
|
|
|
class StrategyGameApp(app.App):
|
2016-06-04 14:31:07 -04:00
|
|
|
def build(self):
|
2016-06-04 14:59:40 -04:00
|
|
|
return StrategyGame()
|
2016-06-04 14:31:07 -04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-06-04 14:59:40 -04:00
|
|
|
StrategyGameApp().run()
|