added colors to the pieces
parent
2e718315a9
commit
bada0fc18e
|
@ -27,7 +27,8 @@ class Afutc:
|
|||
|
||||
def __init__(self, stdscr):
|
||||
self.stdscr = stdscr
|
||||
self.print = stdscr.addstr
|
||||
self.print = lambda x, color=0: stdscr.addstr(x,
|
||||
curses.color_pair(color))
|
||||
self.input = stdscr.getkey
|
||||
self.board = np.zeros(shape=(HEIGHT, WIDTH))
|
||||
self.current_move = np.zeros(shape=(HEIGHT, WIDTH))
|
||||
|
@ -41,7 +42,7 @@ class Afutc:
|
|||
|
||||
def is_valid(self, board):
|
||||
for field in (board + self.board).flat:
|
||||
if field == 2:
|
||||
if field != 0 and field % 2 == 0:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -52,23 +53,26 @@ class Afutc:
|
|||
_, height = self.get_size()
|
||||
height_start = (height // 2) - (WIDTH // 2)
|
||||
try:
|
||||
print = lambda x: self.print((" " * height_start) + x + "\n")
|
||||
print = lambda x, color=0, end="\n": self.print((
|
||||
" " * height_start) + x + end, color)
|
||||
iprint = lambda x, color=0: self.print(x, color)
|
||||
row = str(self.score)
|
||||
row = f"╣ {row} ╠"
|
||||
row = row.center(self.board.shape[1], "═")
|
||||
print("ANOTHER F TETRIS CLONE")
|
||||
print("A F U TETRIS CLONE")
|
||||
print(f"╔{row}╗")
|
||||
for i, row in enumerate(self.board + self.current_move):
|
||||
row_str = ""
|
||||
print("║", end="")
|
||||
for j, field in enumerate(row):
|
||||
if self.ghost[i, j]:
|
||||
row_str += "▢"
|
||||
iprint("▢", 0)
|
||||
elif field:
|
||||
row_str += self.char
|
||||
iprint(self.char, int(field))
|
||||
else:
|
||||
row_str += " "
|
||||
iprint(" ")
|
||||
|
||||
row_str = f"║{row_str}║"
|
||||
row_str += f"║"
|
||||
|
||||
piece = self.next_piece
|
||||
piece_height, piece_width = piece.shape
|
||||
|
@ -84,7 +88,7 @@ class Afutc:
|
|||
if i == (piece_height + 2):
|
||||
row_str += f" ╚{'═' * (piece_width + 2)}╝"
|
||||
|
||||
print(row_str)
|
||||
iprint(row_str + "\n")
|
||||
|
||||
row = "═" * (self.board.shape[1])
|
||||
print(f"╚{row}╝")
|
||||
|
@ -256,6 +260,10 @@ class Afutc:
|
|||
def start():
|
||||
stdscr = curses.initscr()
|
||||
curses.noecho()
|
||||
curses.start_color()
|
||||
curses.use_default_colors()
|
||||
for i in range(0, curses.COLORS):
|
||||
curses.init_pair(i + 1, i, -1)
|
||||
curses.curs_set(False)
|
||||
try:
|
||||
game = Afutc(stdscr)
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
import numpy as np
|
||||
|
||||
PIECES = [[[0, 1], [0, 1], [1, 1]], [[0, 1, 0], [1, 1, 1]], [[1, 1], [1, 1]],
|
||||
[[1, 1, 0], [0, 1, 1]], [[0, 1, 1], [1, 1, 0]], [[1], [1], [1], [1]],
|
||||
[[0, 1, 0], [0, 1, 0], [1, 1, 1]]]
|
||||
|
||||
__colors = [5, 7, 9, 11, 13, 15, 35, 41, 123, 205, 219]
|
||||
|
||||
for n, piece in enumerate(PIECES):
|
||||
piece = np.array(piece)
|
||||
piece *= __colors[n]
|
||||
PIECES[n] = piece.copy()
|
||||
|
|
Loading…
Reference in New Issue