view package
Subpackages
Submodules
view.base_view module
view.terminal_view module
- class view.terminal_view.TerminalView(controller: ViewController)
Bases:
BaseView
Terminal view for the game. It’s used to display the game map and allow the player to navigate it using ZQSD and the arrow keys. Print the map in the Terminal depending on the player’s position and the size of the viewport. Automatically update each tick.
- __add_coord(line: list[str]) list[str]
Add the top left coordinate on the top left corner of the frame. Add the bottom right coordinate on the bottom right corner of the frame. Append ‘x1’ or ‘x60’ based on the value of self.__isFaster.
- __colored_line(line: str, frame_line: str, y: int) str
Color the map elements: uppercase letters in red and bold, lowercase letters in blue, and hide empty spaces. Include the frame in the colored line.
- __display_loop() None
Display the map in the terminal and update it each tick (depending on the FPS).
- __init__(controller: ViewController) None
Initialize the menu view.
- __input_loop() None
Handle the user input to move the viewport.
ZQSD or WASD or arrow keys are used to move the viewport. MAJ + ZQSD or MAJ + WASD or MAJ + arrow keys are used to move the viewport by 5 cells. P is used to pause the game. TAB is used to pause the game and display the stats menu. ECHAP is used to exit the game. F9 is used to take switch view.
- Returns:
None
- __size() None
Take care of the fact that the first line is always hidden and the last line is the n+1 line.
- __str_frame()
Using “┌”, “┐”, “└”, “┘”, “─” and “│” characters, create a frame with the size of the terminal or the map, whichever is smaller. The frame is used to separate the map from the text.
- __str_map() list[str]
Print the map in the terminal using the string representation of the Map object. Using the __from_coord coordinate and the self.__terminal_width and self.__terminal_height, calculate the from and to coordinates to print the map. Use the method Map.get_from_to(from_coord, to_coord) to get the map part to print. Consider the fact that the map is displayed inside the frame, so the map is shifted by 1 to the left, 1 to the top, 1 to the right and 1 to the bottom.
- exit()
- show() None
Start the display and input threads.
view.tile_manager module
view.view_2_5D module
- class view.view_2_5D.View2_5D(controller: ViewController)
Bases:
BaseView
Main class for 2.5D view.
- __init__(controller: ViewController) None
Initialize the menu view.
- __input_loop() None
Handle the user input to move the viewport.
ZQSD or WASD or arrow keys are used to move the viewport. MAJ + ZQSD or MAJ + WASD or MAJ + arrow keys are used to move the viewport by 5 cells. P is used to pause the game. TAB is used to pause the game and display the stats menu. ECHAP is used to exit the game. F9 is used to take switch view. V is used to toggle speed between 1 and 60.
- Returns:
None
- exit() None
- render_map()
Render only the visible part of the map using the camera.
- render_minimap()
Render a minimap in the bottom-right corner of the screen. It shows the entire map with a rectangle indicating the visible area.
- show() None
Main loop for the 2.5D view.