def start_new_game(self): """ Method to reset the GUI and start a new GUI """ self.mode = Modes.MODE_PLAY self.mode_text.set("PLAY") self.next_move.set("Press <c> to cancel") if self.label_grid_mat: del self.label_grid_mat self.label_grid_mat = list() self.mode_label.configure(bg="blue") grid = Grid(self.nb_rows) self.game = Game(grid, init_grid_with_two_tiles=True) self.grid = grid self.score_text.set("Score: 0") self.turn_text.set("Round 0") self.display_grid() self.window.mainloop()
def load_game(log_file_path, display_grid=True): """ Static method to load a 2048 game log to visualize it through the GUI @param log_file_path: the path of the log to load @type log_file_path: str @param display_grid: whether or not to print the initial state of the 2048 game @type display_grid: bool @return: a Game object that contains all the game history (tile positions, directions and score) @rtype: Game """ with open(log_file_path, 'r') as f: nb_rows_columns = int(f.readline().strip().split(' ')[0]) grid = Grid(nb_rows_columns) game = Game(grid, init_grid_with_two_tiles=False, display_grid=display_grid) line = f.readline() while line: l_split = line.strip().split(' ') if len(l_split) > 3: game.history.score_history.append(int(l_split[1])) game.history.grid_history.append(' '.join(l_split[2:-2])) if l_split[-2] != "WIN" and l_split[-2] != "LOOSE": game.history.direction_state_history.append( Constants.Directions(l_split[-2])) else: game.history.direction_state_history.append( Constants.States(l_split[-2])) m = re.search( r"\[([-0-9]+)\]", l_split[-1]) # Regex to extract index from brackets game.history.direction_index_history.append(int( m.group(1))) line = f.readline() return game
def setUp(self): self.grid = Grid() self.grid.writeCell("cell content", (0, 0)) self.grid.writeCell("one on one", (1, 1))
def main(): grid = Grid(10, 10, 10) run(grid)
def setUp(cls): cls.grid = Grid(10, 20) cls.DEFAULT_COLOR = (0, 0, 0)