MinecraftU / 2021-computer-adventures

Repository for our 2021 Computer Adventures Ruby project!
0 stars 0 forks source link

Detect filled row #31

Closed dealingwith closed 3 years ago

dealingwith commented 3 years ago

@jamespeilunli how do we want to accomplish this?

jamespeilunli commented 3 years ago

How about something like a detect_filled_row method in Game, which contains an unless loop unless [last row of gameboard is filled] which inside calls another method, move_all_down which deletes the last row and moves everything down one line.

My Python code: (it has the general idea although the detectrowfill method isn't the same as it uses recursion)

    def _movealldown(self):
        """Moves all blocks down 1 (so deleted row from detectrowfill() is replaced instantly)"""
        for i in range(2, self.height):
            self.gameboard[-i+1] = self.gameboard[-i]
            self.gameboard[-i] = [0] * self.width

    def detectrowfill(self, rownum = -1):
        row = self.gameboard[rownum]
        if len(list(set(row))) == 1 and row[0] == 1: # Check if all items in list are one (all filled with blocks)
            self.gameboard[rownum] = [0] * self.width
            self._movealldown()
            if rownum != 0:
                self.detectrowfill(rownum-1)
dealingwith commented 3 years ago

@jamespeilunli sounds sane. Let's get #32 done and then we can focus on this.