initial commit

master
kirbylife 2019-11-01 17:06:13 -06:00
commit 1abdffd7c5
6 changed files with 130 additions and 0 deletions

0
README.rst 100644
View File

View File

@ -0,0 +1,5 @@
__version__ = '0.1.0'
from afutc.game import start
if __name__ == "__main__":
start()

101
afutc/game.py 100644
View File

@ -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 <SPACE>")
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()

19
pyproject.toml 100644
View File

@ -0,0 +1,19 @@
[tool.poetry]
name = "afutc"
version = "0.1.0"
description = ""
authors = ["kirbylife <gabriel13m@gmail.com>"]
[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"

View File

View File

@ -0,0 +1,5 @@
from afutc import __version__
def test_version():
assert __version__ == '0.1.0'