commit 1abdffd7c5500be990f9e890866baa6dcb30931e Author: kirbylife Date: Fri Nov 1 17:06:13 2019 -0600 initial commit diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..e69de29 diff --git a/afutc/__init__.py b/afutc/__init__.py new file mode 100644 index 0000000..00ce0f8 --- /dev/null +++ b/afutc/__init__.py @@ -0,0 +1,5 @@ +__version__ = '0.1.0' +from afutc.game import start + +if __name__ == "__main__": + start() diff --git a/afutc/game.py b/afutc/game.py new file mode 100644 index 0000000..22a4f19 --- /dev/null +++ b/afutc/game.py @@ -0,0 +1,101 @@ +import curses +from _curses import error as CursesException + +import numpy as np + + +def catch(func, default=..., args=[], kwargs={}): + try: + return func(*args, **kwargs) + except Exception as e: + if default == ...: + return e + else: + return default + + +class Afutc: + running = True + pause = False + pivot = [0, 0] + + def __init__(self, stdscr): + self.stdscr = stdscr + self.print = stdscr.addstr + self.input = stdscr.getkey + self.board = np.zeros(shape=(20, 10)) + self.current_move = np.zeros(shape=(20, 10)) + + def get_size(self): + return self.stdscr.getmaxyx() + + def draw_board(self): + _, heigth = self.get_size() + heigth_start = (heigth // 2) - (self.board.shape[1] // 2) + print = lambda x: self.print((" " * heigth_start) + x + "\n") + + try: + row = "═" * (self.board.shape[1]) + print(f"╔{row}╗") + for n, row in enumerate(self.board): + row = "".join("▣" if field else " " for field in row) + print(f"║{row}║") + row = "═" * (self.board.shape[1]) + print(f"╚{row}╝") + except CursesException: + self.pause() + + def move(self): + pass + + def start(self): + scr = self.stdscr + input = self.input + + scr.timeout(1000) + + while self.running: + scr.refresh() + char = catch(input, "") + scr.clear() + + if not char: + self.pivot[0] += 1 + elif char == "q": + self.running = False + elif char == "C": # Left + self.pivot[1] += 1 + elif char == "D": # Rigth + self.pivot[1] -= 1 + elif char == "B": # Down + self.pivot[0] += 1 + elif char == "A": # Rotate + pass + elif char == " ": # Rotate + self.pause() + + self.draw_board() + + def pause(self): + self.print("PAUSE\n") + self.print("Press ") + while True: + char = catch(self.input, "") + if char == " ": + break + elif char == "q": + self.running = False + break + + +def start(): + stdscr = curses.initscr() + curses.noecho() + curses.curs_set(False) + try: + game = Afutc(stdscr) + game.start() + except BaseException as e: + curses.endwin() + raise e + curses.endwin() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..530eada --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,19 @@ +[tool.poetry] +name = "afutc" +version = "0.1.0" +description = "" +authors = ["kirbylife "] + +[tool.poetry.dependencies] +python = "^3.6" +numpy = "^1.17" + +[tool.poetry.dev-dependencies] +pytest = "^3.0" + +[build-system] +requires = ["poetry>=0.12"] +build-backend = "poetry.masonry.api" + +[tool.poetry.scripts] +start = "afutc:start" diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_afutc.py b/tests/test_afutc.py new file mode 100644 index 0000000..04d086a --- /dev/null +++ b/tests/test_afutc.py @@ -0,0 +1,5 @@ +from afutc import __version__ + + +def test_version(): + assert __version__ == '0.1.0'