{"id":598,"date":"2010-01-19T22:59:04","date_gmt":"2010-01-20T04:59:04","guid":{"rendered":"http:\/\/handyvandal.com\/?p=598"},"modified":"2010-02-23T22:13:28","modified_gmt":"2010-02-24T04:13:28","slug":"snake-game-design-question","status":"publish","type":"post","link":"https:\/\/handyvandal.com\/wphv\/2010\/01\/snake-game-design-question\/","title":{"rendered":"Snake Game Design Question"},"content":{"rendered":"<p><em>Stack Overflow<\/em> is a useful resource for programmers &#8212; a repository of individual questions and collective responses, by and for programmers.<\/p>\n<p>Someone recently asked a <a href=\"http:\/\/stackoverflow.com\/questions\/2014995\/snake-game-design-question\">Snake Game Design Question<\/a>:<\/p>\n<blockquote><p>I&#8217;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<\/p>\n<p>For designing diff. food i&#8217;m making a food interface. And all types of food implement it. So that using only Food&#8217;s ref. i can create any type of food.<\/p>\n<p>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??\n<\/p><\/blockquote>\n<p>Snake is a classic game &#8212; one of my favorites.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/handyvandal.com\/wphv\/wp-content\/uploads\/2010\/01\/snake-150x150.gif\" alt=\"Snake\" title=\"Snake\" width=\"150\" height=\"150\" class=\"alignright size-thumbnail wp-image-599\" \/><br \/>\nWikipedia states:  &#8220;<a href=\"http:\/\/en.wikipedia.org\/wiki\/Snake_%28video_game%29\">Snake<\/a> 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.&#8221;<\/p>\n<p>The <em>Stack Overflow<\/em> responses include:<\/p>\n<blockquote><p>\nYou might want to take a look at the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Template_method_pattern\">Template Pattern<\/a> or the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Decorator_pattern\">Decorator Pattern<\/a>.<\/p>\n<p>The basic idea would be that your &#8220;Snake&#8221; 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 &#8220;powers&#8221;) 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.\n<\/p><\/blockquote>\n<p>And:<\/p>\n<blockquote><p>You could create a base powerclass of which every food holds a reference. Every food this way can have a certain power.<\/p>\n<p>For every power, you inherit form this base powerclass.<\/p>\n<p>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).<\/p><\/blockquote>\n<p>And:<\/p>\n<blockquote><p>Yes, per snake is more flexible. If you were to make it a multiplayer game then each snake would have its power.<\/p>\n<p>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.<\/p>\n<p>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<br \/>\nSuperPower.onNomNom(FoodEaten)<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Stack Overflow is a useful resource for programmers &#8212; a repository of individual questions and collective responses, by and for programmers. Someone recently asked a Snake Game Design Question: I&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102,16,94,103],"tags":[],"class_list":["post-598","post","type-post","status-publish","format-standard","hentry","category-design-patterns","category-game-design","category-programming","category-snake"],"_links":{"self":[{"href":"https:\/\/handyvandal.com\/wphv\/wp-json\/wp\/v2\/posts\/598","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/handyvandal.com\/wphv\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/handyvandal.com\/wphv\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/handyvandal.com\/wphv\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/handyvandal.com\/wphv\/wp-json\/wp\/v2\/comments?post=598"}],"version-history":[{"count":7,"href":"https:\/\/handyvandal.com\/wphv\/wp-json\/wp\/v2\/posts\/598\/revisions"}],"predecessor-version":[{"id":686,"href":"https:\/\/handyvandal.com\/wphv\/wp-json\/wp\/v2\/posts\/598\/revisions\/686"}],"wp:attachment":[{"href":"https:\/\/handyvandal.com\/wphv\/wp-json\/wp\/v2\/media?parent=598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/handyvandal.com\/wphv\/wp-json\/wp\/v2\/categories?post=598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/handyvandal.com\/wphv\/wp-json\/wp\/v2\/tags?post=598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}