This is used for the size of each segment of the snake, as well as for positioning and moving the snake on the board. When we create an instance of our Snake class, we pass in the block_size, which must be an integer with size of each block that makes up our grid. Then, we have the initializer method on the line starting with def _init_. The first few lines are setting up some variables – this is not strictly necessary in Python, but it does make it easier to keep track of the variables, or properties, in our class. We use this to define the allowable directions the snake can move in, and make code that checks and changes directions easy to read and change, compared to just using numbers or strings to define the directions. The first class in this file is an enumeration, which is a nice way to group together a set of related constants. Let's start by creating a new file called snake.py.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |