class Board(object): def __init__(self, wide, tall): self.__wide__ = wide self.__tall__ = tall self.__area__ = [[None for _ in range(wide)] for _ in range(tall)] self.__validate_wide__(wide) self.__validate_tall__(tall) def __validate_wide__(self, wide): if wide <= 0: raise Exception('Wide must be greater than zero') def __validate_tall__(self, tall): if tall <= 0: raise Exception('Tall must be greather than zero') def __validate_ranges__(self, left, top, right, bottom): if left < 0: raise Exception('Left must be greater than zero') if right >= self.__wide__: raise Exception('Right must be less than {0}'.format(self.__wide__)) if top < 0: raise Exception('Top must be greater than zero') if bottom >= self.__tall__: raise Exception('Bottom must be less than {0}'.format(self.__tall__)) if left > right: raise Exception('Left must be less than right') if top > bottom: raise Exception('Bottom must be less than top') def __validate_position__(self, index_j, index_i): if index_j < 0: raise Exception('X must be greater than zero') if index_j >= self.__wide__: raise Exception('X must be less than {0}'.format(self.__wide__)) if index_i < 0: raise Exception('Y must be greater than zero') if index_i >= self.__tall__: raise Exception('Y must be less than {0}'.format(self.__tall__)) def area(self): return self.__area__ def fill_area(self, char, left, top, right, bottom): self.__validate_ranges__(left, top, right, bottom) # index_j controls left and right # index_i controls top and bottom for index_i in range(top, bottom + 1): for index_j in range(left, right + 1): self.__area__[index_i][index_j] = char def fill_position(self, char, index_j, index_i): self.__validate_position__(index_j, index_i) self.__area__[index_i][index_j] = char def clear_position(self, index_j, index_i): self.__validate_position__(index_j, index_i) self.__area__[index_i][index_j] = None