ad88888ba 88
d8" "8b 88
Y8, 88
`Y8aaaaa, 8b,dPPYba, ,adPPYYba, 88 ,d8 ,adPPYba,
`"""""8b, 88P' `"8a "" `Y8 88 ,a8" a8P_____88
`8b 88 88 ,adPPPPP88 8888[ 8PP"""""""
Y8a a8P 88 88 88, ,88 88`"Yba, "8b, ,aa
"Y88888P" 88 88 `"8bbdP"Y8 88 `Y8a `"Ybbd8"'
Copy the code
I remember how happy I was to play Snake on my phone when I was a child.
I’ve been learning Golang lately and testing its limits
It’s exciting to think about recreating a classic game on a terminal
If you like it, share it with your friends and relive the happy time together
How to get:
- Reply to “Snake” on official account
- Or get it from my Github page.
Github.com/Megatron7-c…
Core gameplay:
Up and down around the key control to eat 10 fruits to win
If you hit the wall, you will fail
【 CTRL + C 】 Exit the game
Snake Principle:
The snake moves by placing the tail element on its head.
To eat fruit, you don’t need to move it to the tail, but to add a new node to the head. This is very similar to the list structure, so I use the list to describe snake’s ontology structure. Arrays are used for rendering to facilitate random addressing.
Implementation difficulties:
- Capture of keyboard events
- The control of rendering granularity is related to implementation difficulty
- Snake core gameplay, object structure design
Rely on:
- Jroimartin/GoCUI character graphics library