Break out setup of game tile into a more complicated object.
This commit is contained in:
parent
c28457bbcf
commit
1a385d57bd
|
@ -13,8 +13,8 @@ import sys
|
|||
from kivy import properties
|
||||
from kivy.app import App
|
||||
from kivy.logger import Logger
|
||||
from kivy.uix.image import Image
|
||||
from kivy.uix.gridlayout import GridLayout
|
||||
from kivy.uix.relativelayout import RelativeLayout
|
||||
|
||||
import justcheckers
|
||||
|
||||
|
@ -65,11 +65,21 @@ class GameBoard(GridLayout):
|
|||
source = 'non_play'
|
||||
elif row % 2 == 1 and col % 2 == 1:
|
||||
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):
|
||||
pass
|
||||
class GameTile(RelativeLayout):
|
||||
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():
|
||||
|
|
|
@ -162,12 +162,16 @@ ScreenManager:
|
|||
col_default_width: 50
|
||||
|
||||
|
||||
<GameTile@Image>:
|
||||
source: "images/play.png"
|
||||
<GameTile@RelativeLayout>:
|
||||
tile_state: "play"
|
||||
tile_coords: 0, 0
|
||||
tile_image: image
|
||||
tile_label: label
|
||||
Image:
|
||||
id: image
|
||||
allow_stretch: True
|
||||
canvas.after:
|
||||
Color:
|
||||
rgba: [0, 1, 1, 0.75]
|
||||
Ellipse:
|
||||
pos: self.pos
|
||||
size: self.width - 5, self.height / 2
|
||||
Label:
|
||||
id: label
|
||||
color: [1, 0, 0, 0.75]
|
||||
font_size: "20sp"
|
||||
|
||||
|
|
Loading…
Reference in New Issue