示例#1
0
文件: app.py 项目: lebalz/game_runner
def setup(force: bool = False):
    global socket_conn
    if force and socket_conn is not None:
        socket_conn.disconnect()
    with open(root.joinpath('running'), 'w') as f:
        f.write(str(os.getpid()))
    socket_conn = Connector('https://io.gbsl.website', '__GAME_RUNNER__')
    socket_conn.on_devices = on_client_devices
    socket_conn.on_data = on_highscore
    socket_conn.on_timer = on_timer
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from smartphone_connector import Connector, Colors
from typing import Union, Literal
from examples.server_address import SERVER_ADDRESS

device = Connector(SERVER_ADDRESS, 'FooBar')
device.clear_playground()
device.configure_playground(
    width=180,
    height=180,
    origin_x=10,
    origin_y=10,
    color=Colors.BISQUE,
)


def color(i: int, j: int) -> Union[Literal['white'], Literal['black']]:
    if i % 2 == 0:
        if j % 2 == 0:
            return 'black'
        else:
            return 'white'
    else:
        if j % 2 == 0:
            return 'white'
        else:
            return 'black'