def __init__(self, root, party=None, dimension=10, file_path="", unusual_mode=False): self.root = root if file_path == "": self.log = log_parser.GameLogParser('log.ck') self.game = game_logic.PlayingField(dimension, None, unusual_mode) self.human = party self.dimension = dimension self.progress = 1 self.log.create_struct_log(party, self.dimension, self.progress) else: self.log = log_parser.GameLogParser(file_path) self.log.dimension = int(self.log.get_dimension()) self.dimension = self.log.dimension self.progress = self.log.get_progress() + 1 self.log.count_write = self.progress + 0 field_save = self.log.get_field() self.game = game_logic.PlayingField(self.dimension, field_save) if self.log.get_is_human() == 'none': self.human = None party = None else: self.human = self.log.get_is_human() party = self.human self.first_player = self.game.first_player self.second_player = self.game.second_player self.root = root self.list_button = [] self.list_save_image = [] for x in range(0, self.game.dimension): new_line = [] for y in range(0, self.game.dimension): new_line.append(AdvancedButton(x, y, self.root)) img = PhotoImage(file='image/white.gif') self.list_save_image.append(img) new_line[y]['image'] = img self.list_button.append(new_line) self.is_with_bot = False if party is not None: self.is_with_bot = True if party == 'first': self.bot = bot.Bot(self.second_player) else: self.bot = bot.Bot(self.first_player) if self.progress % 2 != 0: self.progress += self.bot_do() self.log.change_fild_text(self.dimension, self.game.field) self.draw() for x in range(0, self.game.dimension): for y in range(0, self.game.dimension): self.list_button[x][y].grid(row=x, column=y) menu_bar = Menu(self.root) menu_bar.add_command(label="Save", command=self.save_game) self.root.config(menu=menu_bar) self.root.mainloop()
def test_get_is_human(self): self.init_players() new_parser = log_parser.GameLogParser("log.ck") new_parser.create_struct_log("white", 6, 1) self.assertEqual('white', new_parser.get_is_human()) new_parser.create_struct_log("black", 6, 1) self.assertEqual('black', new_parser.get_is_human())
def test_created_log(self): new_parser = log_parser.GameLogParser("log.ck") new_parser.create_struct_log("white", 10, 1) os.chdir(os.getcwd()) files = [] for file in glob.glob("*.ck"): files.append(file) self.file_for_deleted.append('log.ck') self.assertTrue("log.ck" in files)
def test_get_progress(self): self.init_players() new_parser = log_parser.GameLogParser("log.ck") new_parser.create_struct_log("", 6, 1) self.white.take_chip(1, 4) self.white.make_jump(2, 5, 'white') new_parser.change_fild_text(6, self.new_game.field) self.black.take_chip(4, 1) self.black.make_jump(3, 0, 'black') new_parser.change_fild_text(6, self.new_game.field) self.assertEqual(2, int(new_parser.get_relise()))
def test_save_field(self): expected = ["010101\n", "101010\n", "000000\n", "000000\n", "020202\n", "202020\n", ] new_game = game_logic.PlayingField(6) new_parser = log_parser.GameLogParser("log.ck") new_parser.create_struct_log("", 6, 1) new_parser.change_fild_text(6, new_game.field) with open("log.ck", 'r') as file: all_lines = file.readlines() actual = all_lines[4:] self.assertEqual(expected, actual)
def test_get_field(self): expected = [['0', '1', '0', '1', '0', '1'], ['1', '0', '1', '0', '0', '0'], ['0', '0', '0', '0', '0', '1'], ['2', '0', '0', '0', '0', '0'], ['0', '0', '0', '2', '0', '2'], ['2', '0', '2', '0', '2', '0'], ] self.init_players() new_parser = log_parser.GameLogParser("log.ck") new_parser.create_struct_log("", 6, 1) self.white.take_chip(1, 4) self.white.make_jump(2, 5, 'white') new_parser.change_fild_text(6, self.new_game.field) self.black.take_chip(4, 1) self.black.make_jump(3, 0, 'black') new_parser.change_fild_text(6, self.new_game.field) field = new_parser.get_field() self.assertEqual(expected, field)
def test_save_party(self): name_party = "MY_PARTY" new_parser = log_parser.GameLogParser("log.ck") new_parser.create_struct_log("", 6, 1) new_parser.save_change_party(name_party) self.assertEqual(name_party, new_parser.get_is_human())
def test_get_dimension(self): new_parser = log_parser.GameLogParser("log.ck") new_parser.create_struct_log("", 6, 1) self.assertEqual(6, int(new_parser.get_dimension()))
def init_parser(self): self.parse = log_parser.GameLogParser("log.ck")