def drawBoard( self, stdscr: Optional[curses.window] = None, # type: ignore return_as_str: bool = False, ) -> Optional[str]: return_str: Optional[str] = None for y, row_data in enumerate(self.getBoard()): for x, entities in enumerate(row_data): if len(entities) > 1: raise Exception( "Got to draw step without clearing out multi-entity cells. Should have been cleared by collision handlers" ) entity = entities[0] if len(entities) == 1 else None if entity is not None: if return_as_str: if return_str is None: return_str = "" return_str += entity.symbol elif stdscr is not None: # Redundant but type checking purposes stdscr.addch(y, x, entity.symbol, Colors.getAttr(entity.color)) else: if return_as_str: if return_str is None: return_str = "" return_str += " " elif stdscr is not None: stdscr.addch(y, x, " ") if return_str is not None: return_str += "\n" return return_str