![]() This game like many early classics has its roots in the arcades of the 70s it was first released to the public in 1976 by a company called gremlin under the name of blockade two years later itĮntered the world of computers with there lease of worms for the micro computers 18 from there the game spread to nearly all personal computers andĪdopted its lasting name of google snake as there was no one single owner of the game versions of it were created for nearly all major consoles and that is mainly the reason why it's so You're a google snake and you're crawling around endlessly trying to eat the food while staying away from the walls and staying away from your own ever-expanding tail pretty much all versions of this game and believe me there are plenty have the same principle and the only thing that's advanced is the graphics and the controls nothing else but I'm getting ahead of myself here let's look at where this all began. It's a classic arcade game called google snake unless you've been living under a rock the past 30 years you know what I'm talking about when I say google snake and unless you've lived under a boulder the last 30 years you've probably seen this game even if you don't recognize the name the principal of this game is very simple. The most basic element, we only need private data members as discussed and public methods to set and retrieve them.In the history of gaming this is the most influential game in the video game universe, Now that we are clear with the what and what not of the game, lets start coding! Code A function to keep track of the forthcoming cell.Īfter this we will also define a main function to actually play the game.A function to update the game according to snake's movement.A function to return the direction of snake's motion.A function to set the direction of snake's motion.A function to check if the game is over.A constructor to initialise the game with a snake and a board.So the following functions will be required: > Ability and logic to use the classes we make and conduct a game! Notice how Board already contains instances of Cell. This is the meaty part of the code, our primary logic, the game! A constructor to initialise te board with number of rows and columns. ![]() While food is an attribute of the board, movement is an attribute of the snake! Hence it is wise to let the Snake class contain method pertaining to the Snake's movement. This is answered by the Snake class we described above. Whether it is a part of the snake or not? This is attributed to the board, as the cell doesn't choose whether it shall contain food, the board is acquainted with the cells it contains and hence should empowered to assign a cell to contain food. We need to assign food to some random cell as well. While the cells revert to the questions, being the collection and home of cells, the board needs to ensure the cells get satisfiable answers It is the set of valid points for the game to function on, qualitatively a matrix of cells. A function that specifies its type (contains food etc.).> Whether it is a part of the snake or not? The identify of food is random, but identity of cell is meaningful, so I would rather make a class Cell than food.Ĭells are also important to kep track of position of the snake!Įach cell is thereby contains the information about Our boards, consistes of various cells, A cell at random will be proclaimed as the cell containing food. While food seemed intuitive to me while thinking, cell feels intuitive to me for working! Why so? A function to set the head of the snake.A function that returns the head of the snake.A function to check if the snake has crashed.A function to grow the size of the snake.A constructor to initialise the snake with its head.So it shall contain the following functions: > The ability to control movement of the Snake > Know and maintain the size of the snake. Now that we're clear with what makes a Snake Game, lets look at it with an object oriented approach. So lets get this straight, What do we need in our snake game? The classic game that we are all acquainted with is actually surprisingly simple to implement and understand. Let us start immersing ourselves into it by fueling ourselves with some Nostalgia. In this article, we have explored how to design the classical Snake Game using Object Oriented Programming (OOP) concepts and implement it using Java.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |