summaryrefslogtreecommitdiff
path: root/src/miinaharava/tui/ansi_draw.py
blob: ba71fdb6d4e92dee0fb2091126d6544d00cc98af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
""" tui/ansi_draw.py - perustukset ansi tulostelulle """
# pylint: disable = multiple-imports
from .ansi import Ansi
from .static import TileTypes

class AnsiDraw():
    """ AnsiDraw - "piirtelee" näytölle kirjailmilla """
    def __init__(self, height = 9, name = ""):
        print(end='\n'*height+name+": Peli alkaa.")

    def __del__(self):
        print()

    def __tile(self, tile, hilighted):
        """ "piirtää" yhden ruudun """
        for ch, colors in zip(TileTypes[tile].text, TileTypes[tile].colors):
            color, bg = colors
            Ansi.color(Ansi.BLACK if hilighted else color)
            Ansi.bg(Ansi.CYAN if hilighted else bg)
            print(end=ch)
            Ansi.reset()


    def matrix(self, matrix, hx, hy):
        """ "piirtää" ruudukon """
        Ansi.cup(len(matrix[0]))
        # pylint: disable=consider-using-enumerate
        for y in range(len(matrix[0])):
            for x in range(len(matrix)):
                hilight = matrix[x][y] != 9 and x == hx and y == hy
                self.__tile(matrix[x][y], hilight)
            print()


    def status_line(self, text):
        """ draw_status_line - tulostaa pelitietorivin"""
        print(end=text+'\r')

class SuppressDraw():
    """ SuppressDraw - vain status """
    # pylint: disable = unused-argument

    def matrix(self, matrix, hx, hy):
        """ "piirtää" ruudukon """

    def status_line(self, text):
        """ draw_status_line - tulostaa pelitietorivin"""
        print(end=text+'\r')

class NoDraw():
    """ NoDraw - ei mitään """
    # pylint: disable = unused-argument

    def matrix(self, matrix, hx, hy):
        """ "piirtää" ruudukon """

    def status_line(self, text):
        """ draw_status_line - tulostaa pelitietorivin"""