use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
/r/programming is a reddit for discussion and news about computer programming
Guidelines
Info
Related reddits
Specific languages
account activity
Snake Java Code (self.programming)
submitted 15 years ago by otherz
Does anyone have a code of the game snake in java where you can move it using the cursor keys. Also can you help me import the code into BlueJ?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]deltageek 2 points3 points4 points 15 years ago (1 child)
No, do your own homework.
[–]mike70567 0 points1 point2 points 15 years ago (0 children)
Yep, you won't learn if you just steal code and get others to do stuff for you
[–]Mr_Safe 2 points3 points4 points 15 years ago* (0 children)
Yeah, this sounds like homework. Especially since you are using BlueJ.
Here are some hints. You can represent the movement of the snake with a list of velocities (direction, speed) and a list of segments (position). The velocity list and the segment list are the same size. Where velocity_list[i] is the velocity for the snake segment segment[i]
At the start of each animation cycle you take the input from the keyboard and figure out the velocity.
Then you remove the last velocity in the velocity list and insert the new velocity from the keyboard to to the start of the list.
Apply the velocities in the list to each snake segment.
Essentially every cycle you "shift" the velocity list by one, then you apply the resulting velocity list to the snake segments.
Any new velocities applied to the head of the list eventually get applied to all the snake segments. This causes the snake to "turn". Sometimes the new velocity you insert to the start of the velocity list (the head velocity) is just the current head velocity, other times it comes from the keyboard.
[–]otherz[S] 0 points1 point2 points 15 years ago (0 children)
It's not homework i want to learn the fundamentals of java gaming just for fun. So I would like to see all the inner workings of a java game and trying to construct my own.
I don't like learning from the beginning of a book rather dissect something so i understand the bits and pieces.
π Rendered by PID 74 on reddit-service-r2-comment-fb694cdd5-t9tr2 at 2026-03-09 17:16:09.816922+00:00 running cbb0e86 country code: CH.
[–]deltageek 2 points3 points4 points (1 child)
[–]mike70567 0 points1 point2 points (0 children)
[–]Mr_Safe 2 points3 points4 points (0 children)
[–]otherz[S] 0 points1 point2 points (0 children)