pygame is
Python
Simple DirectMedia Layer
 
 
pygame.org is
Site Swing
Snake in 35 lines

Snake in 35 lines - 1.0

Samuel Backman (pyscripter)

Tags:

Description

A snake game in 35 lines of code. I wrote it only to check how many lines i needed to write a snake game.

Links

Home Page: http://pyscripter94.googlepages.com/snake.py
Source: http://pyscripter94.googlepages.com/snake.py

Screenshot


click to view original size

Releases

Snake in 35 lines - 1.0 - Jul 25, 2008

Pygame.org account Comments

If you wish to leave a comment with your pygame.org account, please sign in first.

July 31, 2008 12:37am - Jordan Trudgett - nickname: (tgfcoder)
or 521 :S
July 29, 2008 11:24pm - Jordan Trudgett - nickname: (tgfcoder)
roebros: "What I would put more stock in would be file size, like snake game in 6kbs or whatever ;)"

How about 664 bytes? ;)
July 26, 2008 9:53am - Vitor Bosshard - nickname: (algorias)
I agree. number of lines is not a good indicator of compactness. All those luxuriously long variable names (more than 3 chars) need to go. 8 spaces of indentation? Make that 1.

i = len(xs)-1
while i >= 2:

why are you defining i? should be:

while len(xs)>2

There are lots of other such optimizations to be done here.
July 26, 2008 1:01am - RB[0] - nickname: (roebros)
Technically, no, he is still using 35 lines.
It is perfectly legitimate sometimes to use one line for multiple statements.
While that is the exception and not the rule generally, his code is being un-Pythonic.
But he can rightly claim to be only using 35 lines of code ;)

What I would put more stock in would be file size, like snake game in 6kbs or whatever ;)
July 25, 2008 1:17pm - Emanuel Berg - nickname: (metabaron)
The point is, if you have two statements in one line, they both count, i.e. you use more than 35 "lines".
July 25, 2008 11:36am - Samuel Backman - nickname: (pyscripter)
ghostcoder: It's because the meening with the game was to be as small as possible.
I just wanted to check how many lines i needed to write a snake game.
July 25, 2008 8:50am - Jonathan Lindell - nickname: (ghostcoder)
Nice and simple implementation, but the code is quite messy and there are multiple statements packed in a single line.

spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Apr 21, 2014


Apr 19, 2014

Apr 16, 2014

Apr 13, 2014

Apr 9, 2014

Mar 18, 2014


Mar 15, 2014


Mar 14, 2014

Mar 13, 2014

... more!
 
for pygame related questions, comments, and suggestions, please see help (lists, irc)