84 lines
2.5 KiB
Python
84 lines
2.5 KiB
Python
"""
|
|
Main application for justCheckers
|
|
|
|
:copyright: Copyright 2004-2017, Dorian Pula <dorian.pula@amber-penguin-software.ca>
|
|
:license: GPL v3+
|
|
"""
|
|
|
|
import json
|
|
import logging
|
|
import os
|
|
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
|
|
|
|
import justcheckers
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
class JustCheckersApp(App):
|
|
title = 'justCheckers'
|
|
icon = 'justcheckers/images/icon.png'
|
|
use_kivy_settings = False
|
|
|
|
def on_start(self):
|
|
log_system_and_game_info()
|
|
super(JustCheckersApp, self).on_start()
|
|
|
|
def build_config(self, config):
|
|
config.setdefaults('Theme', {'theme': 'Sunset', 'background': 'Sunset'})
|
|
|
|
def build_settings(self, settings):
|
|
# TODO: Add turn options for music and volume.
|
|
game_settings = [{
|
|
"type": "options",
|
|
"title": "Board Theme",
|
|
"section": "Theme",
|
|
"key": "theme",
|
|
"options": ["Sunset", "Basic"]
|
|
}, {
|
|
"type": "options",
|
|
"title": "Background",
|
|
"section": "Theme",
|
|
"key": "background",
|
|
"options": ["Sunset", "Basic"]
|
|
}]
|
|
settings.add_json_panel("justCheckers Settings", self.config, data=json.dumps(game_settings))
|
|
|
|
|
|
class GameBoard(GridLayout):
|
|
rows = properties.NumericProperty(8)
|
|
cols = properties.NumericProperty(8)
|
|
|
|
def __init__(self, **kwargs):
|
|
super(GameBoard, self).__init__(**kwargs)
|
|
for row in range(self.rows):
|
|
for col in range(self.cols):
|
|
source = 'play'
|
|
if row % 2 == 0 and col % 2 == 0:
|
|
source = 'non_play'
|
|
elif row % 2 == 1 and col % 2 == 1:
|
|
source = 'non_play'
|
|
self.add_widget(Image(source='images/{}.png'.format(source), allow_stretch=True))
|
|
|
|
|
|
def log_system_and_game_info():
|
|
"""Logs information about the game and system running the game."""
|
|
Logger.info('justCheckers -- v{}'.format(justcheckers.__version__))
|
|
|
|
message = 'I am running on {os}.\nMy screen is {height}x{width}'
|
|
root_window = App.get_running_app().root_window
|
|
|
|
os_sys = sys.platform
|
|
if sys.platform == 'posix':
|
|
os_name, _, _, _, os_arch = os.uname()
|
|
os_sys = '{name} {arch}'.format(name=os_name, arch=os_arch)
|
|
|
|
Logger.info(message.format(os=os_sys, height=root_window.height, width=root_window.width))
|