Snake in 10 Lines: Learning More by Coding Less
summary
Claims a complete, playable Snake implemented in 10 lines using only the JDK with Kotlin and Swing, solves raw key handling by reading arrow key codes, reduces state by storing snake as a list of integers with a one-dimensional trick (wraps lines visually), movement as “add head remove tail,” eating by regenerating food with generateSequence, fixes opposite-direction and scoring bugs, and leaves a deliberate “kill screen” when no empty cell remains so the minimal game actually runs and is playable.
AI-written summary · about
chapters (21)
- 0:00Introduction to challenge
- 1:09Rules of the 10-line Snake challenge
- 3:14Breaking down Snake into six words
- 6:04Initial Snake game implementation
- 8:33Adding user interaction with Swing
- 13:31Learning by doing in coding
- 15:16Optimizing Snake movement logic
- 19:08Implementing food and growth mechanics
- 21:17Adding game over condition
- 22:22Simplifying to one-dimensional Snake
- 25:31Constraints lead to creative solutions
- 27:15Pushing to meet the 10-line goal
- 31:05Refactoring for conciseness
- 34:13Finalizing the 10-line Snake game
- 36:17Evaluating the 10-line Snake game
- 37:00Fixing bugs and adding score
- 39:46Preventing direction reversal bug
- 42:12Adding kill screen feature
- 43:34Conciseness brings understanding
- 45:18Key lessons from the challenge
- 46:23Q&A and GitHub resources
related talks
41mLive Coding Kotlin/Native Snake
44mLive Coding Kotlin - Native Snake
46mLive Coding Kotlin/Native Snake
01h 23mFrom Start to Published, Create a game with Ruby!
25mGoodbye, World; Hello, Battlesnake!
01h 37mShall We Play A Game
17m10 Kotlin Tricks in 10 ish minutes
53mLet's Have Some Fun with Game Of Life:& Learn to Think Functionally Along the Way
