def test_can_add_actions(action): """ Tests that actions can be added to the queue """ action_queue = ActionQueue() action_queue.push(action) assert action in action_queue.heap
def test_can_pop_empty_queue_for_no_effect(): """ Tests that popping an empty queue does nothing """ action_queue = ActionQueue() action_queue.pop() assert len(action_queue.heap) == 0
def test_pop_order(): """ This tests to see if the queue returns actions in temporal order """ action_queue = ActionQueue() rand_order = list(range(0, 10)) random.shuffle(rand_order) print(rand_order) for i in rand_order: action = Action('test', i) action_queue.push(action) for i in range(0, 10): action = action_queue.pop() assert action.time == i
def test_can_instantiate_action_queue(): """ Tests that Action Queue imports properly and its constructor works. """ assert ActionQueue action_queue = ActionQueue() assert isinstance(action_queue, ActionQueue)
def test_actions_of_different_times_handled_properly(action, long_action): """ This tests to see if this can handle actions of different times """ second_action = Action('action_queue', 1) action_queue = ActionQueue() action_queue.push(second_action) action_queue.push(long_action) action_queue.resolve_actions(1) assert long_action in action_queue.heap assert second_action not in action_queue.heap
def test_multiple_actions_resolve_at_once(action): """ This tests to see if multiple actions can get resolved at once """ action_queue = ActionQueue() action_queue.push(action) second_action = Action('action_queue', 1) action_queue.push(second_action) action_queue.resolve_actions(1) assert action not in action_queue.heap assert second_action not in action_queue.heap
def __init__(self, config: Dict = {}): self.config = config #setup font tcod.console_set_custom_font( "terminal8x12_gs_ro.png", tcod.FONT_LAYOUT_ASCII_INROW | tcod.FONT_TYPE_GREYSCALE, ) tileset = { 0: Entity(-1, -1, -1, '#', (100, 100, 100), { 'blocks_movement': True, 'blocks_vision': True }), 1: Entity(-1, -1, -1, '.', (100, 100, 100)), 2: Entity(-1, -1, -1, '#', (0, 0, 255), { 'blocks_movement': True, 'blocks_vision': True }), 3: Entity(-1, -1, -1, '.', (0, 0, 255)), 4: Entity(-1, -1, -1, '#', (180, 180, 180), { 'blocks_movement': True, 'blocks_vision': True }), 5: Entity(-1, -1, -1, '.', (180, 180, 180)), } self.curr_area: Area = Area(2, 200, 200, tileset=tileset) self.SCREEN_WIDTH: int = 50 self.SCREEN_HEIGHT: int = 50 self.InputHandler: InputHandler = InputHandler() self.player: Player = Player(0, 24, 24, '@', (255, 255, 255)) self.global_queue = ActionQueue() self.global_time = 0 #TODO: Figure out panel heights for this self.bot_ui = UIPanel(0, self.SCREEN_HEIGHT - 5, 5, self.SCREEN_WIDTH) self.top_ui = UIPanel(0, 0, 5, self.SCREEN_WIDTH)
def test_long_actions_remain_after_pop(long_action): """ Tests that actions with sufficient time are not resolved by sending less than their time """ action_queue = ActionQueue() action_queue.push(long_action) action_queue.resolve_actions(1) assert long_action in action_queue.heap
def test_can_resolve_actions(action): """ Tests that an action with time will be removed by resolving time 1 actions """ action_queue = ActionQueue() action_queue.push(action) action_queue.resolve_actions(1) assert action not in action_queue.heap
def test_can_pop_actions(action): """ Tests that after an action is pushed, pop will remove it """ action_queue = ActionQueue() action_queue.push(action) action_queue.pop() assert action not in action_queue.heap
def test_multiple_resolve(): """ This tests to see if the queue handles nonadjacent resolution """ action_queue = ActionQueue() rand_order = list(range(0, 10)) random.shuffle(rand_order) for i in rand_order: action = Action(f'test {i}', i) action_queue.push(action) assert len(action_queue.heap) == 10 for time, length in ((2, 7), (4, 5), (8, 1), (10, 0)): action_queue.resolve_actions(time) assert len(action_queue.heap) == length
class Game: def __init__(self, config: Dict = {}): self.config = config #setup font tcod.console_set_custom_font( "terminal8x12_gs_ro.png", tcod.FONT_LAYOUT_ASCII_INROW | tcod.FONT_TYPE_GREYSCALE, ) tileset = { 0: Entity(-1, -1, -1, '#', (100, 100, 100), { 'blocks_movement': True, 'blocks_vision': True }), 1: Entity(-1, -1, -1, '.', (100, 100, 100)), 2: Entity(-1, -1, -1, '#', (0, 0, 255), { 'blocks_movement': True, 'blocks_vision': True }), 3: Entity(-1, -1, -1, '.', (0, 0, 255)), 4: Entity(-1, -1, -1, '#', (180, 180, 180), { 'blocks_movement': True, 'blocks_vision': True }), 5: Entity(-1, -1, -1, '.', (180, 180, 180)), } self.curr_area: Area = Area(2, 200, 200, tileset=tileset) self.SCREEN_WIDTH: int = 50 self.SCREEN_HEIGHT: int = 50 self.InputHandler: InputHandler = InputHandler() self.player: Player = Player(0, 24, 24, '@', (255, 255, 255)) self.global_queue = ActionQueue() self.global_time = 0 #TODO: Figure out panel heights for this self.bot_ui = UIPanel(0, self.SCREEN_HEIGHT - 5, 5, self.SCREEN_WIDTH) self.top_ui = UIPanel(0, 0, 5, self.SCREEN_WIDTH) def generate_school(self) -> None: """ This function will randomly generate the school """ rooms = SchoolGenerator.generate_school(self.curr_area) self.player.x = random.randint(rooms[0].x1 + 1, rooms[0].x2) self.player.y = random.randint(rooms[0].y1 + 1, rooms[0].y2) self.curr_area.add_object(self.player) def render(self) -> None: self.curr_area.draw(self.player.z, self.player.x, self.player.y, self.SCREEN_WIDTH, self.SCREEN_HEIGHT, self.player.vision_radius, **self.config) self.bot_ui.draw() self.bot_ui.print_string( 1, 1, f"({self.player.z}, {self.player.x}, {self.curr_area.y_length - self.player.y})" ) self.top_ui.draw() self.top_ui.print_string(1, 1, f"{self.global_time}") tcod.console_flush() # Show the console. def game_loop(self) -> None: with tcod.console_init_root(self.SCREEN_HEIGHT, self.SCREEN_WIDTH, order="F", vsync=False) as root_console: root_console.clear() self.render() while not tcod.console_is_window_closed(): if self.global_queue.player_actions_count > 0: self.global_queue.resolve_actions(self.global_time) self.global_time += 1 root_console.clear() self.render() else: for event in tcod.event.wait(): if event.type == "KEYDOWN": result = self.InputHandler.handle_keypress(event) if (result["type"] == "move"): self.player.move_action( result["value"][0], result["value"][1], result["value"][2], self.curr_area, self.global_queue) if event.type == "QUIT": raise SystemExit()