import logging

from collections import namedtuple


log_format = "[%(asctime)s] %(levelname)s: %(message)s"
date_format = "%m/%d/%Y %I:%M:%S %p"


def create_logger(lname, fname, fmode="w", level=logging.DEBUG):
    logging.basicConfig(filename=fname,
                        filemode=fmode,
                        format=log_format,
                        datefmt=date_format,
                        level=level)
    return logging.getLogger(lname)


Event = namedtuple("Event", ["type", "val"])


class Point:
    def __init__(self, x, y):
        self._x = x
        self._y = y

    def __repr__(self):
        return "Point(x={}, y={})".format(self._x, self._y)


    __str__ = __repr__


    def __add__(self, other):
        return Point(x=self.x + other.x, y=self.y + other.y)


    @property
    def x(self):
        return self._x


    @x.setter
    def x(self, val):
        self._x = val


    @property
    def y(self):
        return self._y


    @y.setter
    def y(self, val):
        self._y = val


class Surface(object):
    """image is list of lists of char:
        rocket
        [
         ["^"],     ^
         ["|"],     |
         ["*"] ]    *

        ship
        [
         [" "," ","O"," "," "],           O
         ["<","=","H","=",">"],         <=H=>
         [" ","*"," ","*"," "] ]         * *
    """

    def __init__(self, image, style=None, orientation='up'):
        self._image = image if orientation == 'up' else image[::-1]
        self._width = max([len(l) for l in self._image])
        self._height = len(self._image)
        self._style = style


    @property
    def height(self):
        return self._height

    @property
    def width(self):
        return self._width


    def get_image(self):
        for y, row in enumerate(self._image):
            for x, image in enumerate(row):
                yield (Point(x=x, y=y), image, self._style[y][x] if self._style else None)


class Color:
    #user interface
    ui_norm   = 1
    ui_yellow = 2
    #damage panel
    dp_blank    = 3
    dp_ok       = 4
    dp_middle   = 5
    dp_critical = 6
    sh_ok       = 7
    sh_mid      = 8
    #weapons
    blaster = 9
    laser   = 10
    um      = 11


class Layout(object):
    def __init__(self, config=None):
        self._field = {}
        self._gui = {}


    def init_layout(self):
        self._field["border"] = Point(x=80, y=24)
        self._field["spaceship"] = Point(x=self._field["border"].x // 2,
                                         y=self._field["border"].y - 1)

        self._gui["hbar"] = Point(x=2 , y=self._field["border"].y - 1)
        self._gui["sbar"] = Point(x=22, y=self._field["border"].y - 1)

        return self


    @property
    def field(self):
        return self._field


    @property
    def gui(self):
        return self._gui


class InfList(list):
    """Infinite list container"""

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._index = 0


    def current(self):
        return self[self._index]


    def next(self):
        self._index = (self._index + 1) % len(self)
        return self[self._index]


    def prev(self):
        self._index = (self._index - 1) % len(self)
        return self[self._index]

@@ -7,16 +7,45 @@
  logging
+%0Aimport time%0Aimport threading
 %0A%0Afrom c
@@ -521,24 +521,315 @@
 , %22val%22%5D)%0A%0A%0A
+class Timer(threading.Thread):%0A    def __init__(self, t, func, args=(), kwargs=%7B%7D):%0A        threading.Thread.__init__(self)%0A        self.t = t%0A        self.func = func%0A        self.args = args%0A        self.kwargs = kwargs%0A%0A    def run(self):%0A        time.sleep(self.t)%0A        self.func()%0A%0A%0A
 class Point:
@@ -3558,28 +3558,222 @@
    return self%5Bself._index%5D%0A
+%0A%0Aif __name__ == %22__main__%22:%0A    t1 = Timer(5, lambda : print(%22WOLOLO%22))%0A    t2 = Timer(2, lambda : print(2))%0A    t3 = Timer(4, lambda : print(4))%0A%0A    for t in (t1, t2, t3):%0A        t.start()%0A%0A

add dummy timer class