From 2e14bf377d32a86fd5c56c820b478b103e0a0424 Mon Sep 17 00:00:00 2001 From: kirbylife Date: Thu, 7 Nov 2019 19:56:30 -0600 Subject: [PATCH] added ghost guide --- afutc/game.py | 48 ++++++++++++++++++++++++++++++++++++++++++------ pyproject.toml | 2 +- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/afutc/game.py b/afutc/game.py index 4000d04..d3ff7f4 100644 --- a/afutc/game.py +++ b/afutc/game.py @@ -31,6 +31,7 @@ class Afutc: self.input = stdscr.getkey self.board = np.zeros(shape=(HEIGHT, WIDTH)) self.current_move = np.zeros(shape=(HEIGHT, WIDTH)) + self.ghost = np.zeros(shape=(HEIGHT, WIDTH)) self.board_center = WIDTH // 2 self.current_piece = None self.score = 0 @@ -54,16 +55,37 @@ class Afutc: row = str(self.score).center(self.board.shape[1], "═") print("ANOTHER F TETRIS CLONE") print(f"╔{row}╗") - for n, row in enumerate(self.board + self.current_move): - # row = "".join("" if field else " " for field in row) - row = "".join(self.char if field else " " for field in row) - print(f"║{row}║") + for i, row in enumerate(self.board + self.current_move): + row_str = "" + for j, field in enumerate(row): + if self.ghost[i, j]: + row_str += "▢" + elif field: + row_str += self.char + else: + row_str += " " + print(f"║{row_str}║") row = "═" * (self.board.shape[1]) - print(f"╚{row}╝") - # print(str(self.pivot) + "\t" + self.debug) + # print(f"╚{row}╝") + print(str(self.pivot) + "\t" + self.debug) except CursesException: self.pause() + def recalculate_ghost(self): + pivot = self.pivot[:] + current_piece = self.current_piece.copy() + self.ghost.fill(0.) + count = 0 + while True: + result = self.fuse_matrix( + self.ghost, current_piece, + (pivot[1], HEIGHT - current_piece.shape[0] - count)) + if self.is_valid(result): + self.ghost = result.copy() + break + else: + count += 1 + def new_random_piece(self): # Clear rows completed count = 0 @@ -86,6 +108,7 @@ class Afutc: if not self.is_valid(self.current_move): self.running = False self.pivot = [0, position] + catch(self.recalculate_ghost) def move(self, direction): if direction == "down": @@ -112,6 +135,7 @@ class Afutc: return self.current_move = temp_board self.pivot[1] -= 1 + self.recalculate_ghost() elif direction == "right" and self.pivot[1] < ( WIDTH - self.current_piece.shape[1]): temp_board = self.current_move.copy() @@ -122,6 +146,7 @@ class Afutc: return self.current_move = temp_board self.pivot[1] += 1 + self.recalculate_ghost() def rotate(self): temp_board = self.current_move.copy() @@ -145,6 +170,7 @@ class Afutc: if self.is_valid(temp_board): self.current_move = temp_board.copy() self.current_piece = temp_piece.copy() + self.recalculate_ghost() def start(self): scr = self.stdscr @@ -187,6 +213,16 @@ class Afutc: self.running = False break + @classmethod + def fuse_matrix(self, mat1, mat2, xypos=(0, 0)): + mat1 = mat1.copy() + mat2 = mat2.copy() + x, y = xypos + ysize, xsize = mat2.shape + xmax, ymax = (x + xsize), (y + ysize) + mat1[y:ymax, x:xmax] += mat2 + return mat1 + def start(): stdscr = curses.initscr() diff --git a/pyproject.toml b/pyproject.toml index 10fddc7..86936e8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "afutc" -version = "1.0.0" +version = "1.1.0" description = "Another Fucking Ugly Tetris Clone" authors = ["kirbylife "]