Merge branch 'dorian' of https://github.com/llfkj/gamecamp into llfkj

This commit is contained in:
Amy Wooding 2016-06-04 21:08:32 -07:00
commit 865e27ed82
2 changed files with 48 additions and 13 deletions

48
main.py
View File

@ -1,11 +1,9 @@
import collections
import random
from kivy.app import App
from kivy import properties
from kivy import graphics
from kivy.uix import label
from kivy import app, properties
from kivy.uix import button, label
from kivy.uix.floatlayout import FloatLayout
import math
MapCoords = collections.namedtuple('MapCoords', ['row', 'col'])
@ -22,10 +20,18 @@ class StrategyGame(FloatLayout):
for region in xrange(0, number_of_regions):
row = region / self.map_cols
col = region % self.map_cols
self.main_map.add_widget(self.pick_hex_cell(row=row, col=col))
# Add hex cells to make up the map.
hex_cell = self.pick_hex_cell(row=row, col=col)
self.main_map.add_widget(hex_cell)
def pick_hex_cell(self, row, col):
# Add overlay conditionally.
if (row % 6 == 2 and col % 2 == 0) or (row % 6 == 5 and col % 2 == 1):
print('({}, {})'.format(row, col))
self.add_widget(HexMapControlCell(hex_bind=hex_cell))
@staticmethod
def pick_hex_cell(row, col):
row_mod = row % 6
if col % 2 == 0:
if row_mod == 0:
@ -48,22 +54,44 @@ class StrategyGame(FloatLayout):
class HexMapCell(label.Label):
def __init__(self, row=0, col=0, **kwargs):
self.region_in_map = MapCoords(row, col)
super(HexMapCell, self).__init__(**kwargs)
self.coords = MapCoords(row, col)
class BU(HexMapCell):
pass
class TD(HexMapCell):
pass
class L(HexMapCell):
pass
class R(HexMapCell):
pass
class StrategyGameApp(App):
class HexMapControlCell(button.Button):
def __init__(self, hex_bind=None, **kwargs):
super(HexMapControlCell, self).__init__(**kwargs)
self.hex_bind = hex_bind
self.background_color = random.random(), random.random(), random.random(), 1
self.bind(pos=self.reposition_control_cell, size=self.resize_control_cell)
self.text = '({}, {})'.format(self.hex_bind.coords.row, self.hex_bind.coords.col)
def reposition_control_cell(self, obj, value):
self.pos = self.hex_bind.pos
def resize_control_cell(self, obj, value):
self.height = self.hex_bind.height * 2
self.width = self.hex_bind.width * 2
class StrategyGameApp(app.App):
def build(self):
return StrategyGame()

View File

@ -1,5 +1,4 @@
#:import math math
#:include debug.kv
<StrategyGame>:
id: _game
@ -16,12 +15,20 @@
BoxLayout:
orientation: 'vertical'
size_hint: .25, 1
DebugLabel:
Label:
id: _stats
text: 'status'
size_hint: 1, .66
DebugLabel:
canvas.before:
Color:
rgba: .49, .49, .81, 1
Rectangle:
pos: _stats.pos
size: _stats.size
Button:
text: 'mini-map'
size_hint: 1, .33
background_color: .75, .71, .99, 1
<BU>: