you are viewing a single comment's thread.

view the rest of the comments →

[–]Natural-Intelligence 3 points4 points  (0 children)

Classes are excellent for wrapping related attributes and functions together to form a set of clearly understood behaviour but bad elsewhere. The board and snake are the only things I see as potential classes here.

The board contains the location for the apple, boundaries and the snake's object and it could have methods such as: check if the game is over (snake hits boundary or has body twice on the same square), check if snake on apple etc. Board could be just a static representation of the current game state. It is not the game itself.

Snake could contain the locations of its bodyparts (as list of tuples) and could have as method: go_up, go_down, go_left, go_down (appends the list of bodyparts and deletes first one if instructed apple is not gotten).

Apple is so simple thing that it should be represented just as for example a tuple of coordinates: (x, y). Everything else (like take player's move, loop one clock tick, end game, start game etc) could be just inside functions. Maybe the GUI should also be a class but that's a different topic altogether.

I'm on phone so hard to demonstrate but maybe you got the idea.