May 03, 2020 ( last updated : May 04, 2020 )
Python
OOP
https://github.com/cao-weiwei/
šA snake game could contains lots of features, if we want to improve the previous work, we must have clues about how to make progressš¤. Next we will use OOP ideas to make a fancy snake game.
Contrary to procedure-oriented programming where programs are designed as blocks of statements to manipulate data, object-oriented programming organizes the program to combine data and functionality and wrap it inside something called an āObjectāš§.
There is a structured approach for analyzing and designing a software product using OOP concepts. The most important thing is identifying the objects of the product and figuring out the relationships between each other. Iāll explain the process of making the snake game asš„³:
š¤Iāll focus on the following set of requirements while designing the snake game:
The above whole process can be drawn in a figure as:
According to the process, I made mock-up of the interface.
As we knew, the most obvious objects in the game are the snake and the food. How to identify others and develop their relationships are vital points for making this game.
Board: Everything in the game must be drawn or displayed on a board, like painting on canvas. And this board will contain a snake, food, and a score counter. It will initialize a game and end the game according to the conditions.
Snake: A snake, in the game, actually is a list of coordinates. we have to know the start position and its length. For the snake, it can move on the screen and eat food. And sometimes, it may die due to collision with the border or itself.
Food: As the same as the snake, itās also represented by a pair of coordinates on the screen. For the food, we should know whether it is eaten by the snake then we can draw another on the screen.
Button: This is a kind of UI component to receive a start signal and a terminate signal from use.
Finally, based on previous analysis and objects we got, I made some UI of the game.
Next, weāll jump onto the pygame, which is a most famous game development library in Python.
If you like my articles please give me a star or leave comments below, thanks!
Originally published May 03, 2020
Latest update May 04, 2020
Related posts :