Break out setup of game tile into a more complicated object.

This commit is contained in:
Dorian 2017-06-01 09:14:38 -04:00
parent c28457bbcf
commit 1a385d57bd
2 changed files with 27 additions and 13 deletions

View File

@ -13,8 +13,8 @@ import sys
from kivy import properties from kivy import properties
from kivy.app import App from kivy.app import App
from kivy.logger import Logger from kivy.logger import Logger
from kivy.uix.image import Image
from kivy.uix.gridlayout import GridLayout from kivy.uix.gridlayout import GridLayout
from kivy.uix.relativelayout import RelativeLayout
import justcheckers import justcheckers
@ -65,11 +65,21 @@ class GameBoard(GridLayout):
source = 'non_play' source = 'non_play'
elif row % 2 == 1 and col % 2 == 1: elif row % 2 == 1 and col % 2 == 1:
source = 'non_play' source = 'non_play'
self.add_widget(GameTile(source='images/{}.png'.format(source))) self.add_widget(GameTile(tile_state=source, coords=[row, col]))
class GameTile(Image): class GameTile(RelativeLayout):
pass tile_state = properties.StringProperty()
tile_coords = properties.ListProperty()
tile_image = properties.ObjectProperty()
tile_label = properties.ObjectProperty()
def __init__(self, tile_state='non_play', coords=None, **kwargs):
super(GameTile, self).__init__(**kwargs)
self.tile_state = tile_state
self.coords = coords if coords else [-1, -1]
self.tile_label.text = '{}, {}'.format(self.coords[0], self.coords[1])
self.tile_image.source = 'images/{}.png'.format(self.tile_state)
def log_system_and_game_info(): def log_system_and_game_info():

View File

@ -162,12 +162,16 @@ ScreenManager:
col_default_width: 50 col_default_width: 50
<GameTile@Image>: <GameTile@RelativeLayout>:
source: "images/play.png" tile_state: "play"
allow_stretch: True tile_coords: 0, 0
canvas.after: tile_image: image
Color: tile_label: label
rgba: [0, 1, 1, 0.75] Image:
Ellipse: id: image
pos: self.pos allow_stretch: True
size: self.width - 5, self.height / 2 Label:
id: label
color: [1, 0, 0, 0.75]
font_size: "20sp"