Snake Game Design Question

Stack Overflow is a useful resource for programmers — a repository of individual questions and collective responses, by and for programmers.

Someone recently asked a Snake Game Design Question:

I’m trying to make a snake game with additional functionality where snake can eat different types of food some of the foods will give it special powers for some time. like that

For designing diff. food i’m making a food interface. And all types of food implement it. So that using only Food’s ref. i can create any type of food.

The only power is representing a power. I can represent it either on board or in the snake. Snake is the best option as it seems to be more logical. Can any one tell me how am i suppose to represent it??

Snake is a classic game — one of my favorites.
Wikipedia states: “Snake is a video game first released during the mid 1970s in arcades and has maintained popularity since then, becoming somewhat of a classic. After it became the standard pre-loaded game on Nokia phones in 1998, Snake found a massive audience.”

The Stack Overflow responses include:

You might want to take a look at the Template Pattern or the Decorator Pattern.

The basic idea would be that your “Snake” would have its operations exported into a module tree which are called. So for instance Snake.Move() would really just check to see if there was a move modifier (as provided from your “powers”) otherwise it would default to its own internal move object. Depending on how you implement it the power could replace, temporarily override, or cascade its effects.


You could create a base powerclass of which every food holds a reference. Every food this way can have a certain power.

For every power, you inherit form this base powerclass.

the moment you eat the food, the power class is transferred to the snake. The snake could hold one reference (to the last eaten power), or even a list of powers (if multiple powers can be active at the same time).


Yes, per snake is more flexible. If you were to make it a multiplayer game then each snake would have its power.

What you seem to be missing is Power->Food mapping. But that really depends on whether or not one Food gives many Powers or one Power can have different powers.

Well there are many ways how you can do this. Most basic I can think of is having a static method that will produce a different powers when passed different type of food. Whenever your snake eats something you call

Game Design Patterns

What are design patterns?

“A design pattern in architecture and computer science is a formal way of documenting a solution to a design problem in a particular field of expertise. The idea was introduced by the architect Christopher Alexander in the field of architecture and has been adapted for various other disciplines, including computer science. An organized collection of design patterns that relate to a particular field is called a pattern language.”

What are game design patterns? A similar language of design principles which game designers can use to think about and express their work.

Game Design Patterns by Staffan Björk, Sus Lundgren, Jussi Holopainen:

We present a model to support the design, analysis, and comparison of games through the use of game design patterns, descriptions of reoccurring interaction relevant to game play. The model consists of a structural framework to describe the components of games, and patterns of interaction that describes how components are used by players (or a computer) to affect various aspects of the game play. Focusing on the patterns and identified methods for using them, we describe the development of the model and how we are currently working to enlarge and validate the collection of patterns.

Game Design, Patterns, Taxonomies, Game Models

Game Design Patterns (PDF)

To me, a pattern is a short name for a definition of “how you do something.”

The “something” can be very specific — example, the “Spawnpoint Pattern” makes the player spawn at a particular place in the game (with variations for randomness, delay time, etc.)

Or the something can be very general — the “Player Happiness Pattern” discusses player psychology and game goals.

I’m inventing freely here for purposes of example — “Spawnpoint Pattern” and “Player Happiness Pattern” may be useful to you or not.

Patterns can be as arbitrary as you need them to be — I could speak of the “Handy Vandal Pattern” if I found it useful.

As it happens, “Handy Vandal” doesn’t impress me as a useful pattern, although the fact that it doesn’t impress me as a pattern does imply something about useful patterns.

Good patterns are good because they reflect the deep inner nature of the subject matter.

The pattern is a reflection, a double. Think of pattern in the sense of graphic design, as an image that repeats itself. Now think of the world itself — creation, reality — as the first image, and the game design pattern as a symbolic repetition of the world.

The proper subject matter of game design comprises patterns such as: “game rules” … “player” … “game start” … “game score” … “competition” … “cooperation” … or any other short descriptive phrase that you found useful as a category of information. The pattern name is shorthand for a big topic: the name encapsulates the many complex details of the big topic, giving you a way to talk about high-level patterns without spelling out the details; meanwhile, the details are in there, memorable because of their place in the pattern, ready to be conveniently referenced when needed.
Christopher Alexander
Last word goes to the Patriarch of design patterns:

“The elements of this language are entities called patterns. Each pattern describes a problem that occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice.”

—- Christopher Alexander