engine.level documentation - wladekpal/The-Lazy-Snek GitHub Wiki
engine.level.Level
Level class that holds current level state. It provides function that simulates one tick, and function that restarts level.
Properties:
level_name
- string holding level name.level_creator
- string holding level creator's name.block_placement
- matrix containing id's of blocks located on boardsnake_data
- list of dictionaries, each describing one snake.available_blocks
- list of pairs, each containing block id and number of times player can use them.snake_pointer
- integer pointing to snakes list, informing which snake is going to move next tick.board
-engine.board.Board
object, current board statesnakes
- list ofengine.snake.Snake
objects, snakes located on board.
Constructor
Takes file_name
. Constructor method, loads dictionary which represents level and sets class attributes. Creates initial board
and snakes
.
reload_level()
Method used to reload level to state given in file.
reload_simulation()
Method used to reload level to state before starting last simulation. If simulation is inactive, nothing happens.
backup_board()
Mehtod used to make current board
state backup. Backup includes only block placement.
reload_board()
Mehtod used to restore board
to state stored in board_backup.
convert_board()
Method used to set board
to board that is represented by block_placement
.
convert_snakes()
Method used to set snakes
to list of snakes that are represented by snake_data
.
convert_available_blocks()
Method used to set self_available_blocks
to list of engine.Block
objects. Those are blocks that player can use.
is_any_alive()
Method used to check if any snake is alive. Returns True if so, False otherwise.
tick()
Method used to simulate one tick. It moves snake, updates snake_pointer
. Returns -1 if all snakes are dead, 0 otherwise.
update_snake_pointer()
Method used to update snake_pointer
attribute to next snake who is alive.
self_draw(frame)
Method used to draw board
in frame
.
get_board()
Getter for 'board' attribute