2016-06-04 15:35:33 -04:00
|
|
|
import collections
|
|
|
|
|
2016-06-04 14:31:07 -04:00
|
|
|
from kivy.app import App
|
2016-06-04 15:23:40 -04:00
|
|
|
from kivy import properties
|
2016-06-04 16:02:02 -04:00
|
|
|
from kivy import graphics
|
2016-06-04 15:54:21 -04:00
|
|
|
from kivy.uix import label
|
2016-06-04 14:31:07 -04:00
|
|
|
from kivy.uix.floatlayout import FloatLayout
|
2016-06-04 17:41:13 -04:00
|
|
|
import math
|
2016-06-04 14:59:40 -04:00
|
|
|
|
2016-06-04 15:35:33 -04:00
|
|
|
MapCoords = collections.namedtuple('MapCoords', ['row', 'col'])
|
|
|
|
|
|
|
|
|
2016-06-04 14:59:40 -04:00
|
|
|
class StrategyGame(FloatLayout):
|
2016-06-04 15:23:40 -04:00
|
|
|
main_map = properties.ObjectProperty(None)
|
|
|
|
map_rows = properties.NumericProperty(0)
|
|
|
|
map_cols = properties.NumericProperty(0)
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super(StrategyGame, self).__init__(**kwargs)
|
|
|
|
|
|
|
|
number_of_regions = self.map_rows * self.map_cols
|
|
|
|
for region in xrange(0, number_of_regions):
|
|
|
|
row = region / self.map_cols
|
|
|
|
col = region % self.map_cols
|
2016-06-04 17:41:13 -04:00
|
|
|
self.main_map.add_widget(self.pick_hex_cell(row=row, col=col))
|
2016-06-04 15:35:33 -04:00
|
|
|
|
|
|
|
|
2016-06-04 17:41:13 -04:00
|
|
|
def pick_hex_cell(self, row, col):
|
|
|
|
row_mod = row % 6
|
|
|
|
if col % 2 == 0:
|
2016-06-04 15:51:50 -04:00
|
|
|
if row_mod == 0:
|
2016-06-04 17:41:13 -04:00
|
|
|
return BU()
|
2016-06-04 15:51:50 -04:00
|
|
|
elif row_mod in (1, 2):
|
2016-06-04 17:41:13 -04:00
|
|
|
return L()
|
2016-06-04 15:51:50 -04:00
|
|
|
elif row_mod == 3:
|
2016-06-04 17:41:13 -04:00
|
|
|
return TD()
|
2016-06-04 15:51:50 -04:00
|
|
|
elif row_mod in (4, 5):
|
2016-06-04 17:41:13 -04:00
|
|
|
return R()
|
2016-06-04 15:51:50 -04:00
|
|
|
else:
|
|
|
|
if row_mod == 0:
|
2016-06-04 17:41:13 -04:00
|
|
|
return TD()
|
2016-06-04 15:51:50 -04:00
|
|
|
elif row_mod in (1, 2):
|
2016-06-04 17:41:13 -04:00
|
|
|
return R()
|
2016-06-04 15:51:50 -04:00
|
|
|
elif row_mod == 3:
|
2016-06-04 17:41:13 -04:00
|
|
|
return BU()
|
2016-06-04 15:51:50 -04:00
|
|
|
elif row_mod in (4, 5):
|
2016-06-04 17:41:13 -04:00
|
|
|
return L()
|
|
|
|
|
|
|
|
|
|
|
|
class HexMapCell(label.Label):
|
|
|
|
def __init__(self, row=0, col=0, **kwargs):
|
|
|
|
self.region_in_map = MapCoords(row, col)
|
|
|
|
super(HexMapCell, self).__init__(**kwargs)
|
|
|
|
|
|
|
|
class BU(HexMapCell):
|
|
|
|
pass
|
|
|
|
class TD(HexMapCell):
|
|
|
|
pass
|
|
|
|
class L(HexMapCell):
|
|
|
|
pass
|
|
|
|
class R(HexMapCell):
|
|
|
|
pass
|
2016-06-04 15:51:50 -04:00
|
|
|
|
2016-06-04 14:59:40 -04:00
|
|
|
|
|
|
|
class StrategyGameApp(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()
|