3

Megatron7的个人空间

 3 years ago
source link: https://my.oschina.net/megatron7/blog/5064651
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
周末利用 Golang 复刻童年游戏
 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"' 

> 记得小时候能在手机上玩到贪吃蛇就是一件很开心的事。 > > 最近正好在学 golang ,试试它的能力边界 > > 能在终端上复刻经典游戏,想想就很激动

喜欢的小伙伴就分享给身边的朋友吧,一起重温快乐的时光

如何获取:

核心玩法:

> 上下左右键控制走向,吃到10颗果实赢得胜利

> 撞击墙壁、自身都会失败

>【ctrl + c】退出游戏

贪吃蛇原理:

> 贪吃蛇在移动的时候是将尾部元素放到头部来实现移动。

> 吃到果子不需要挪到尾部,而是在头部新增一个节点。 > 这和 list 结构就很像了,所以 snake 的本体结构我用 list 来描述。 > 渲染部分用的是数组,方便随机寻址。

实现难点:

  • 键盘事件的捕捉
  • 渲染粒度的把控,关系到实现难度
  • 贪吃蛇核心玩法,对象结构设计

"欢迎关注我的公众号「编程感悟」,一起交流讨论"

在这里插入图片描述


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK