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 collections
import random
from kivy.app import App from kivy import app, properties
from kivy import properties from kivy.uix import button, label
from kivy import graphics
from kivy.uix import label
from kivy.uix.floatlayout import FloatLayout from kivy.uix.floatlayout import FloatLayout
import math
MapCoords = collections.namedtuple('MapCoords', ['row', 'col']) MapCoords = collections.namedtuple('MapCoords', ['row', 'col'])
@ -22,10 +20,18 @@ class StrategyGame(FloatLayout):
for region in xrange(0, number_of_regions): for region in xrange(0, number_of_regions):
row = region / self.map_cols row = region / self.map_cols
col = 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 row_mod = row % 6
if col % 2 == 0: if col % 2 == 0:
if row_mod == 0: if row_mod == 0:
@ -48,22 +54,44 @@ class StrategyGame(FloatLayout):
class HexMapCell(label.Label): class HexMapCell(label.Label):
def __init__(self, row=0, col=0, **kwargs): def __init__(self, row=0, col=0, **kwargs):
self.region_in_map = MapCoords(row, col)
super(HexMapCell, self).__init__(**kwargs) super(HexMapCell, self).__init__(**kwargs)
self.coords = MapCoords(row, col)
class BU(HexMapCell): class BU(HexMapCell):
pass pass
class TD(HexMapCell): class TD(HexMapCell):
pass pass
class L(HexMapCell): class L(HexMapCell):
pass pass
class R(HexMapCell): class R(HexMapCell):
pass 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): def build(self):
return StrategyGame() return StrategyGame()

View File

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