def test_field_move_wall(): left_top = Path(0, 0) right_top = Wall(1, 0) left_bottom = Path(0, 1) right_bottom = Path(1, 1) blocks = [[left_top, right_top], [left_bottom, right_bottom]] field = Field(blocks, left_top) player = Player() field.enter(player) field.move(player, Direction.right) assert player.block == left_top
def load_maze(self): os.system('cls' if os.name == 'nt' else 'clear') file_name = input("Enter file name (without extension): ") try: csv_file = open(f'{file_name}.csv') csv_reader = csv.reader(csv_file, delimiter=',') csv_data = list(csv_reader) blocks = [[] for _ in range(sum(1 for row in csv_data))] start_block = None is_invalid = False csv_file.close() for i, row in enumerate(csv_data): for ii, col in enumerate(row): block = (Wall(ii, i) if col == 'X' else Portal(ii, i) if col == 'B' else Path(ii, i) if col == 'A' or col == 'O' else True) blocks[i].append(block) if col == 'A': start_block = block if block == True: is_invalid = True break if is_invalid: print( "Invalid file type/content, please ensure that the file is proper." ) input("Press Enter to continue...") return if start_block is None: print( "Maze does not contain a start point, please verify the maze file!" ) input("Press Enter to continue...") return print(f'Processed {len(blocks)} lines.') self.field = Field(blocks, start_block) self.player = Player() self.field.enter(self.player) print("\n" + self.field.render() + '\n') print("Successfully loaded maze!") input("Press Enter to continue...") except IOError: print("File does not exist.") input("Press Enter to continue...")
def create_wall(self): os.system('cls' if os.name == 'nt' else 'clear') player = Player() self.field.enter(player) print(self.field.render()) print() selection = input( "Enter the coordinate of the item (e.g row, col)\n'B' to return to configure menu.\n'M' to return to main menu. " ).lower() if not (selection == 'm' or selection == 'b'): try: split = selection.split(',') row = int(split[0]) col = int(split[1]) block = self.field.blocks[row - 1][col - 1] if not isinstance(block, Path): print(f"Walls can only be placed over paths") input("Press Enter to continue...") return self.field.blocks[row - 1][col - 1] = Wall(col - 1, row - 1) self.field.enter(player) os.system('cls' if os.name == 'nt' else 'clear') self.field.enter(Player()) print(self.field.render()) print() print(f"Wall block placed at {row}, {col}") input("Press Enter to continue...") except: print("Invalid block coordinates!") input("Press Enter to continue...") elif selection == 'm': self.end()
def test_block_render(): assert Path(0, 0).render() == 'O' assert Wall(0, 0).render() == 'X' assert Portal(0, 0).render() == 'B'
def test_block_is_wall(): assert Block(0, 0).is_wall() == None assert Wall(0, 0).is_wall() == True