Contents

Boards: TiledBoard

Contents

Boards: TiledBoard

TiledBoard is a child class of Board

classDiagram BaseBoard <|-- Board Board <|-- PixelBoard BaseBoard <|-- TiledBoard PixelBoard <|-- PhysicsBoard class BaseBoard{ } class Board{ } class PixelBoard{ } class TiledBoard{ } class PhysicsBoard{ }

TiledBoard

class miniworldmaker.boards.board_templates.tiled_board.tiled_board.TiledBoard(view_x=20, view_y=16, tile_size=40, empty=False)[source]

A TiledBoard is a Board where each Token is placed in one Tile.

With Tiled Board, you can realize RPGs and Boardgames.

TiledBoard

Each Token on a TiledBoard can be placed on a Tile, on a Corner between Tiles or on an Edge between Tiles.

Examples

Create Token on Tile, Corner and Edge:

from miniworldmaker import *
board = TiledBoard(6, 3)
board.grid = True
last_corner = None

tile = Tile((1,1))
t1 = tile.create_token()
t1.fill_color = (255,255,255)

corner = Corner((3,1), "nw")
t2 = corner.create_token()
t2.fill_color = (255,0,0)

edge = Edge((5,1), "w")
t3 = edge.create_token()
t3.fill_color = (0,0,255)
t3.size = (0.2,1)
t3.direction = edge.angle

board.run()
Placing Tokens on a Tile, on a Corner or in a Edge

Public Data Attributes:

grid

Displays grid overlay on background.

Inherited from : py: class:Board

speed

speed defines how often the method act() will be called.

fps

Frames per second shown on the screen.

width

Gets width of board in pixels.

height

Gets height of board in pixels.

boundary_x

The x-boundary (defaults to view_size)

boundary_y

The y-boundary (defaults to view_size)

viewport_width

int

viewport_height

The y-boundary (defaults to view_size)

columns

int

rows

int

camera_x

camera_y

tile_size

Tile size of each tile, if board has tiles

size

Set the size of board

default_fill_color

Set default fill color for borders and lines

default_is_filled

default_stroke_color

Set default stroke color for borders and lines.

default_border_color

Set default border color for borders and lines.

default_border

Sets default border color for tokens

tokens

A list of all tokens registered to the board.

backgrounds

Returns the background of board.

background

Returns the background of board.

container_width

The width of the container

container_height

The height of the container

has_background

bool

registered_events

set

image

The current displayed image

fill_color

color

Inherited from : py: class:BaseBoard

subclasses

class_name

str

window

Gets the parent window

Inherited from : py: class:Container

container_width

The width of the container

container_height

The height of the container

window

Gets the parent window

size

Set the size of board

rect

window_docking_position

width

Gets width of board in pixels.

height

Gets height of board in pixels.

Public Methods:

__init__([view_x, view_y, tile_size, empty])

Initializes the TiledBoard

clear_tiles()

Removes all tiles, coners and edges from Board

setup_board()

In this method, corners and edges are created.

add_tile_to_board(position)

add_corner_to_board(position, direction)

add_edge_to_board(position, direction)

get_tile(position)

Gets Tile at Position.

get_tokens_at_position(position)

Alias for get_tokens_from_pixel

get_corner(position[, direction])

Gets Corner at Position.

get_edge(position[, direction])

Gets Edge at Position.

is_position_on_the_board(position)

Returns True if a position is on the board.

borders(value)

Returns the Board's borders, if token is near a Border.

detect_tokens_at_position(position)

Sensing tokens at same position

detect_token_at_position(position)

Sensing single token at same position

draw_on_image(image, position)

get_from_pixel(position)

Gets board position from pixel coordinates

get_board_position_from_pixel(position)

Gets board position from pixel coordinates

get_tile_from_pixel(position)

Gets nearest Tile from pixel

get_edge_points()

rtype:

Dict[Tuple, Position]

get_corner_points()

rtype:

Dict[Tuple, Position]

is_edge(position)

Returns True, if position is a edge.

is_corner(position)

Returns True, if position is a corner.

is_tile(position)

Returns True, if position is a tile.

to_pixel(position[, size, origin])

Converts BoardPosition to pixel coordinates

Inherited from : py: class:Board

__init__([view_x, view_y, tile_size, empty])

Initializes the TiledBoard

contains_position(pos)

Checks if position is on the board.

contains_rect(rect)

Detects if rect is completly on the board.

is_position_on_the_board(position)

Returns True if a position is on the board.

setup_board()

In this method, corners and edges are created.

borders(value)

Returns the Board's borders, if token is near a Border.

set_tile_size(value)

default_fill(value)

Set default fill color for borders and lines

get_background()

Implemented in subclass

switch_background(background)

Switches the background of board

remove_background([background])

Removes a background from board

add_background(source)

Adds a new background to the board

start()

Starts the board, if board is not running.

stop([frames])

Stops the board.

start_listening()

stop_listening()

clear()

Alias of clean

clean()

removes all tokens

run([fullscreen, fit_desktop, replit, ...])

The method show() should always called at the end of your program.

init_display()

play_sound(path)

plays sound from path

stop_sounds()

play_music(path)

plays a music from path

stop_music()

plays a music from path

get_mouse_position()

Gets the current mouse_position

get_mouse_x()

Gets x-coordinate of mouse-position

get_mouse_y()

Gets y-coordinate of mouse-position

get_prev_mouse_position()

gets mouse-position of last frame

is_mouse_pressed()

Returns True, if mouse is pressed

is_mouse_left_pressed()

Returns True, if mouse left button is pressed

is_mouse_right_pressed()

Returns True, if mouse right button is pressed

send_message(message[, data])

Sends broadcast message

quit([exit_code])

quits app and closes the window

reset()

Resets the board Creates a new board with init-function - recreates all tokens and actors on the board.

switch_board(new_board)

Switches to another board

get_color_from_pixel(position)

Returns the color at a specific position

get_from_pixel(position)

Gets board position from pixel coordinates

get_board_position_from_pixel(position)

Gets board position from pixel coordinates

to_pixel(position[, size, origin])

Converts BoardPosition to pixel coordinates

on_setup()

Overwrite or register this method to call on_setup-Actions

__str__()

Return str(self).

add_to_board(token, position)

Adds a Token to the board.

get_tokens_from_pixel(pixel)

Gets all tokens by Pixel.

get_tokens_at_position(position)

Alias for get_tokens_from_pixel

repaint()

Implemented in subclasses

update()

This is the board-mainloop() Called in app.update() when update() vom all containers is called.

act_all()

Overwritten in subclasses, e.g.

handle_event(event[, data])

Event handling

register(method)

Used as decorator e.g.

unregister(method)

direction(point1, point2)

distance_to(pos1, pos2)

direction_to(pos1, pos2)

rtype:

Direction

Inherited from : py: class:BaseBoard

__init__([view_x, view_y, tile_size, empty])

Initializes the TiledBoard

get_token_connector(token)

rtype:

TokenConnector

add_container(container, dock[, size])

remove_container(container)

blit_surface_to_window_surface()

load_board_from_db(file)

Loads a sqlite db file.

load_tokens_from_db(file, token_classes)

Loads all tokens from db.

save_to_db(file)

Saves the current board an all actors to database.

screenshot([filename])

Creates a screenshot in given file.

get_background()

Implemented in subclass

Inherited from : py: class:Container

__init__([view_x, view_y, tile_size, empty])

Initializes the TiledBoard

update_width_and_height()

repaint()

Implemented in subclasses

blit_surface_to_window_surface()

remove()

Implemented in subclasses

handle_event(event[, data])

Event handling

get_event(event, data)

Implemented in subclasses

is_in_container(x, y)

rtype:

bool

position_is_in_container(pos)

rtype:

bool

update()

This is the board-mainloop() Called in app.update() when update() vom all containers is called.

get_local_position(position)

rtype:

tuple

Private Data Attributes:

_abc_impl

Inherited from : py: class:Board

_abc_impl

Inherited from : py: class:BaseBoard

_abc_impl

Inherited from : py: class:ABC

_abc_impl

Private Methods:

_get_tile_factory()

_get_camera_manager_class()

_templates()

Returns Classes for Tile, Edge and Corner

_setup_tiles()

Adds Tile to Board for each BoardPosition

_setup_corners()

Add all Corner to Board for each Tile.

_setup_edges()

Add all Edges to Board for each Tile

_get_token_connector_class()

needed by get_token_connector in parent class

_update_token_positions()

Updates the dynamic_tokens_dict.

Inherited from : py: class:Board

_tick_timed_objects()

Inherited from : py: class:BaseBoard

_get_camera_manager_class()

_get_token_connector_class()

needed by get_token_connector in parent class

Inherited from : py: class:Container

_add_to_window(app, dock[, size])


__init__(view_x=20, view_y=16, tile_size=40, empty=False)[source]

Initializes the TiledBoard

Parameters:
  • view_x – The number of columns

  • view_y – The number of rows

  • empty – The board has no tiles, edges, and corners. They must be created manually

add_corner_to_board(position, direction)[source]
add_edge_to_board(position, direction)[source]
add_tile_to_board(position)[source]
borders(value)[source]

Returns the Board’s borders, if token is near a Border.

Return type:

list

clear_tiles()[source]

Removes all tiles, coners and edges from Board

Instead of clearing the board, you can add the parameter empty to Board to create a new Board from scratch.

Examples

Clear and re-create board:

from miniworldmaker import *
board = HexBoard(8, 8)

@board.register
def on_setup(self):
    self.clear_tiles()
    center = HexTile((4, 4))
    for x in range(self.columns):
        for y in range(self.rows):
            if center.position.distance((x, y)) < 2:
                tile = self.add_tile_to_board((x, y))
                tile.create_token()


board.run()

Create a new board from scratch

Note

This variant is faster, because Tiles are not created twice

from miniworldmaker import *
board = HexBoard(8, 8, empty=True)

@board.register
def on_setup(self):
    center = HexTile((4, 4))
    for x in range(self.columns):
        for y in range(self.rows):
            if center.position.distance((x, y)) < 2:
                tile = self.add_tile_to_board((x, y))
                tile.create_token()


board.run()
detect_token_at_position(position)[source]

Sensing single token at same position

Faster than sensing_tokens, but only the first found token is recognized.

detect_tokens_at_position(position)[source]

Sensing tokens at same position

draw_on_image(image, position)[source]
get_board_position_from_pixel(position)

Gets board position from pixel coordinates

get_corner(position, direction=None)[source]

Gets Corner at Position.

Raises CornerNotFoundError, if Tile does not exists.

Examples

Get corner from token:

corner = board.get_corner(token.position)

Get corner from board-position and direction

from miniworldmaker import *

from miniworldmaker import *
board = TiledBoard(6, 3)
board.grid = True
last_corner = None

corner = Corner((3,1), "nw")
t2 = corner.create_token()
t2.fill_color = (255,0,0)

corner=board.get_corner((3,1),"nw")
assert(corner.get_tokens()[0] == t2)

board.run()
Parameters:
  • position (Position) – Position on Board

  • direction (Optional[str]) – if direction is not None, position is interpreted as tile-board-position

Returns:

Corner on Posiiton, if position exists

get_corner_points()[source]
Return type:

Dict[Tuple, Position]

get_edge(position, direction=None)[source]

Gets Edge at Position.

Raises EdgeNotFoundError, if Tile does not exists.

Examples

Get edge from token:

tile = board.get_edge(token.position)

Get edge from board-position and direction

from miniworldmaker import *
board = TiledBoard(6, 3)
board.grid = True
last_corner = None

t3 = edge.create_token()
t3.fill_color = (0,0,255)
t3.size = (0.2,1)
t3.direction = edge.angle

edge=board.get_edge((5,1),"w")
assert(edge.get_tokens()[0] == t3)

board.run()
Parameters:

position – Position on Board

Returns:

Edge on Posiiton, if position exists

get_edge_points()[source]
Return type:

Dict[Tuple, Position]

get_from_pixel(position)[source]

Gets board position from pixel coordinates

get_tile(position)[source]

Gets Tile at Position.

Raises TileNotFoundError, if Tile does not exists.

Examples

Get tile from token:

tile = board.get_tile(token.position)

Full example:

from miniworldmaker import *

board = TiledBoard(6, 3)
board.grid = True
last_corner = None

tile = Tile((1,1))
t1 = tile.create_token()
t1.fill_color = (255,255,255)

tile=board.get_tile((1,1))
assert(tile.get_tokens()[0] == t1)

board.run()
Parameters:

position (<module 'miniworldmaker.positions.position' from '/home/asiebel/.local/lib/python3.10/site-packages/miniworldmaker/positions/position.py'>) – Position on Board

Returns:

Tile on Posiiton, if position exists

get_tile_from_pixel(position)[source]

Gets nearest Tile from pixel

get_tokens_at_position(position)[source]

Alias for get_tokens_from_pixel

Return type:

list

property grid

Displays grid overlay on background.

is_corner(position)[source]

Returns True, if position is a corner.

is_edge(position)[source]

Returns True, if position is a edge.

is_position_on_the_board(position)[source]

Returns True if a position is on the board.

Return type:

bool

is_tile(position)[source]

Returns True, if position is a tile.

setup_board()[source]

In this method, corners and edges are created.

to_pixel(position, size=(0, 0), origin=(0, 0))[source]

Converts BoardPosition to pixel coordinates