engine.blocks documentation - wladekpal/The-Lazy-Snek GitHub Wiki
engine.blocks.Block
Block is an abstract class representing any block that can be placed on engine.field.Field type object.
Properties
field- anengine.field.Fieldtype object that block is placed on.is_alive- logical value that implicates whether block should be displayed or destroyed after next request of displaying itself on screen.displayed_texture-pygame.imagetype object that block uses to display itself.displayed_side_length- side length of displayed_texturepane_index- priority of block listed on available blocks to be placed on board by player list. Should beNoneif block can't be moved and represent number otherwise.
Note: displayed_texture and displayed_side_length are used to cache informations about last time that
block was displayed on screen. displayed_texture is a scaled version of a pygame.image object returned by class' static texture() method. If new display request demands same side length as the last one (which is most often the case), block's texture won't be scaled again, thus self_draw() method will execute much faster.
Block(pane_index=None)
Takes one optional argument pane_index with default value of None, and assigns its value to pane_index argument. Sets field, displayed_texture and displayed_side_length as None. Sets is_alive as True.
texture()
Static and abstract method. Implementation should return squared-size pygame.image type object that will be displayed as block representation. Loaded image can be partially transparent.
interact_with_snake(snake)
Abstract method. Implementation should modify snake in a way block's mechanics would interract with snake entering field the block is placed on.
snake-engine.snake.Snaketype object modified by interraction with block.
self_draw(frame, position, side_length)
Draws texture representing block into frame, with the top-left corner placed at position and scales the texture side to side_length.
frame-pygame.Surfacetype objectposition- two integer tuple representing position of displayed block's top-left corner onframeside_length- side length of displayed square-shaped texture
engine.blocks.Flat
Abstract class inheriting from engine.blocks.Block. Represents flat block that can be placed on field. Only one flat block should be placed on a single field at a time. It's possible for convex block or snake to enter field that flat block is placed on. Flat block can't be moved from a field, but can modify its internal state by interraction with snake or convex block that enters the same field.
interract_with_convex(convex)
Abstract method. Implementation should modify convex in a way block's mechanics would interract with any convex block entering field the flat block is placed on.
convex-engine.blocks.Convextype object modified by interraction with flat block.
check_move(direction)
This method is used to check whether a convex block coming from direction direction can enter flat block. Most flat blocks can always be entered by convex, so this returns True.
check_snake_move(snake)
This method is used to check whether a snake can enter flat block. Most flat blocks can always be entered by snake, so this returns True.
engine.blocks.Convex
Abstract class inheriting from engine.blocks.Block. Represents convex block that can be placed on field. Only one convex block should be placed on a single field at a time.
check_move(direction)
Checks if block can be moved by another convex block or snake from given direction.
engine.blocks.Wall
Wall inherits from engine.blocks.Convex class and represents an immovable object. When snake tries to enter a wall it dies. No object can be pushed into the wall.
check_move(direction)- This method allways retrunsFalse, since nothing can enter a wall.move()- This method raisesengine.blocks.WallInteractionErrorsince calling this method means that some object tried to enter a Wall without usingcheck_move()first.interact_with_snake(snake)- This method raisesengine.blocks.WallInteractionErrorsince calling this method means that some snake tried to enter a Wall without usingcheck_snake_move()first.check_snake_move(direction)- This method allways retrunsFalse, since no snake can enter a wall.kill()- This method raisesengine.blocks.WallInteractionErrorsince Wall cannot be destroyed.destroy()- This method raisesengine.blocks.WallInteractionErrorsince Wall cannot be destroyed.
engine.blocks.TurnLeft
TurnLeft class inherits from engine.blocks.Flat it changes the snake direction to make it turn left.
interact_with_snake(snake)- This methods changes snake's direction to the left of the current one.
engine.blocks.TurnRight
TurnRight class inherits from engine.blocks.Flat it changes the snake direction to make it turn right.
interact_with_snake(snake)- This methods changes snake's direction to the right of the current one.
engine.blocks.Box
Box class inherits from engine.blocks.Convex it represents a pushable convex object. Box can be pushed in direction only when there is no convex object in this direction, or there is convex object that can be pushed. If box enters snake the snake is destroyed. If snake tries to psuh box that cannot be pushed it is destroyed.
check_move(direction)- This method check whether box can move in given direction.move(direction)- This method performs move of box in given direction. It informs field it is on, that the box leaves.interact_with_snake(snake)- This method checks whether box can be pushed by given snake. If it can it is moved, else the snake is destroyed.check_snake_move(snake)- This method checks whether snake can push this block in snake's direction.
engine.blocks.Spikes
Spikes class inherits from engine.blocks.Flat it represents a spikes block, that destroys any snake that enters. Spikes have no effect on convex blocks that are pushed on them.
interact_with_snake(snake)- This method is called when Snake enters spikes it callsdestroy()method of snake.
engine.blocks.Skull
Skull inherits from engine.blocks.Convex it represents a consumable item that destroys any snake that consumes it. In this process Skull is destroyed. Skull can be pushed by other convex objects.
check_move(direction)- This method check whether skull can move in given direction.move(direction)- This method performs move of skull in given direction. It informs field it is on, that the skull leaves.interact_with_snake(snake)- This method destroys snake that enters skull and skull itself.check_snake_move(snake)- Snake can always enter skull (although snake will be destroyed by entering), so this method always returnTrue.
engine.blocks.Apple
Apple inherits from engine.blocks.Convex it represents a consumable item that makes snake grow once. In this process Apple is destroyed. Apple can be pushed by other convex objects.
check_move(direction)- This method check whether apple can move in given direction.move(direction)- This method performs move of apple in given direction. It informs field it is on, that the apple leaves.interact_with_snake(snake)- This method destroyes apple itself (snake already is informed about growth from call tocheck_snake_move()).check_snake_move(snake)- This method first informs snake, that it will grow in the next move, by callingsnake.grow(), then since snake can allways enter apple it returns true.
engine.blocks.Infinity_tail
Infinity_tail inhertis from engine.blocks.Convex it represents a consumable item that makes snake grow infinitely. In this process Infinity_tail block is destroyed. Infinity_tail block can be pushed by other convex objects.
check_move(direction)- This method check whether Infinity_tail can move in given direction.move(direction)- This method performs move of Infinity_tail in given direction. It informs field it is on, that the Infinity_tail leaves.interact_with_snake(snake)- This method destroyes Infinity_tail itself (snake already is informed about infinite growth from call tocheck_snake_move()).check_snake_move(snake)- This method first informs snake, that it will grow infinitely in the next move, by callingsnake.enable_infinite_grow(), then since snake can allways enter Infinite_tail it returns true.
engine.blocks.Reverse
Reverse inherits from engine.blocks.Flat it represenets a block that reverses snake and has no effect on other blocks.
interact_with_snake(snake)- This method callssnake.reverse()on snake that enters Reverse block.
engine.blocks.VeniceBlock
Venice block inherits from engine.blocks.Flat it represents a block that can be entered by convex or snake only from one side. In constructor it takes the direction it faces.
check_move(direction)- This method is used to check whether a convex coming fromdirectioncan enter Venice block.check_snake_move(snake)- This methodis used to check whether a snake can enter Venice block.
engine.blocks.Key
Key inherits from engine.blocks.Convex it represents a consumable item that makes snake open doors. In this process Key is destroyed. Key can be pushed by other convex objects.
check_move(direction)- This method check whether convex can enter Key block.move(direction)- This method performs move of key in given direction. It informs field it is on, that the key leaves.interact_with_snake(snake)- This method destroyes keyitself (snake already is informed about having key withget_key()).check_snake_move(snake)- This method first informs snake, that it will have key, by callingsnake.get_key(), then since snake can allways enter key it returns true.
engine.blocks.Door
Door inherits from engine.blocks.Convex it represents a block that can be opened by a key.
check_move(direction)- This method is called before some convex block enters a door. Since no convex can enter block it is always returnsFalse.move(direction)- This method raisesengine.blocks.DoorInteractionError, since door cannot be moved by any means.interact_with_snake(snake)- This method checks if snake has a key. It destroys snake if it has no key. It destroys itself if snake has key.check_snake_move(snake)- This method lets snake enter.
engine.blocks.Finish
Finish block inherits from engine.blocks.Flat it represents a block that, when reached by the snake in it's color makes the snake change it's state to finished. Finishe block has no effects on other entities moving over it.
- constructor - Finish block takes one additional argument in constructor, that is it's color.
interact_with_snake(snake)- If given snake is in the same color as the Finish block it callssnake.finish()method.
engine.blocks.Dye
Dye block is a consumable block that changes the color of a snake that consumes it. It can be moved by other convex blocks. If snake collects the dye in it's color the dye is consumed, but it has no effect on snake.
check_move(direction)- This method checks whether a convex block can move on this block.move(direction)- This method moves Dye in given direction.interact with snake(snake)- This method destroys block itself, since the snake is already informed of color change by callingcheck_snake_entermethod.check_snake_move(snake)- This methods is called, when snake tries to enter dye block. It always returnsTrueand informs snake to check color.
engine.blocks.Timer
Timer class is a consumable block that makes snake miss it's next move. It can be moved by other convex blocks.
check_move(direction)- This method checks whether a convex block can move on this block.move(direction)- This method moves Timer in given direction.interact with snake(snake)- This method destroys block itself, it also informs snake it has to miss it's next turn by callingsnake.wait()method.check_snake_move(snake)- This methods is called, when snake tries to enter timer block. It always returnsTrue.