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