def test_neq_2x2(): frame1 = GridFrameBuffer(2, 2) frame1.set(0, 0, "a") frame1.set(1, 0, "b") frame1.set(0, 1, "c") frame1.set(1, 1, "d") frame2 = GridFrameBuffer(2, 2) frame2.set(0, 0, "d") frame2.set(1, 0, "b") frame2.set(0, 1, "c") frame2.set(1, 1, "d") assert frame1 != frame2
def test_str_2x2(): frame = GridFrameBuffer(2, 2) frame.set(0, 0, "a") frame.set(1, 0, "b") frame.set(0, 1, "c") frame.set(1, 1, "d") assert str(frame) == "ab\ncd"
def test_from_string_array(): frame1 = GridFrameBuffer(2, 2) frame1.set(0, 0, "a") frame1.set(1, 0, "b") frame1.set(0, 1, "c") frame1.set(1, 1, "d") frame2 = GridFrameBuffer.from_string_array(["ab", "cd"]) assert frame1 == frame2
def test_edges_2(): panel = Panel(0, 0, 1, 1, border=PanelBorder.create("2", "7", "5", "4", "3", "1", "8", "6")) frame = GridFrameBuffer(5, 5, init_value=" ") with pytest.raises(IndexError): panel.redraw(frame)
def test_edges(): panel = MapPanel(1, 1, 2, 2) frame = GridFrameBuffer(5, 5, init_value=" ") panel.add("1", (0, 0)) panel.add("2", (1, 0)) panel.add("3", (0, 1)) panel.add("4", (1, 1)) panel.redraw(frame) exp = [" ", " 12 ", " 34 ", " ", " "] exp_frame = GridFrameBuffer.from_string_array(exp) assert frame == exp_frame
def test_edges(): panel = Panel(1, 1, 1, 1, border=PanelBorder.create("2", "7", "5", "4", "3", "1", "8", "6")) frame = GridFrameBuffer(5, 5, init_value=" ") panel.redraw(frame) exp = ["123 ", "4 5 ", "678 ", " ", " "] exp_frame = GridFrameBuffer.from_string_array(exp) assert frame == exp_frame
def run_with_local_display(self, seed=None): """Will run the game for a user. Returns: """ # This import statement is here so pygame is only imported if needed. from CYLGame import Display game = self.game_class(random.Random(seed)) charset = Display.CharSet(self.game_class.CHAR_SET, self.game_class.CHAR_WIDTH, self.game_class.CHAR_HEIGHT) display = Display.PyGameDisplay(*charset.char_size_to_pix( (game.SCREEN_WIDTH, game.SCREEN_HEIGHT)), title=game.GAME_TITLE) clock = Display.get_clock() frame_buffer = GridFrameBuffer(*charset.pix_size_to_char( display.get_size()), charset=charset) frame_updated = True game.init_board() players = [] if game.MULTIPLAYER: computer_bot_class = game.default_prog_for_computer() for _ in range(game.get_number_of_players() - 1): players += [game.create_new_player(computer_bot_class())] player = game.create_new_player(UserProg()) game.start_game() while game.is_running(): clock.tick(FPS) for key in display.get_keys(): # TODO: fix player.prog.key = key player.run_turn(game.random) for comp_player in players: comp_player.run_turn(game.random) game.do_turn() frame_updated = True if frame_updated: game.draw_screen(frame_buffer) display.update(frame_buffer) frame_updated = False
def test_str_1x1(): frame = GridFrameBuffer(1, 1) frame.set(0, 0, "a") assert str(frame) == "a"
def test_neq_1x1(): frame1 = GridFrameBuffer(1, 1) frame1.set(0, 0, "a") frame2 = GridFrameBuffer(1, 1) frame2.set(0, 0, "b") assert frame1 != frame2
def get_frame(self): if self.__frame_buffer is None: self.__frame_buffer = GridFrameBuffer(self.SCREEN_WIDTH, self.SCREEN_HEIGHT) self.draw_screen(self.__frame_buffer) return self.__frame_buffer.dump()