command
module
Version:
v0.0.0-...-b5afa3f
Opens a new window with list of versions in this module.
Published: Sep 26, 2018
License: MIT
Opens a new window with license information.
Imports: 9
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
用Golang做了一个命令行贪吃蛇游戏
项目介绍
项目链接:https://gitee.com/lwow2025/snake-go
最近看了一本做几个小项目的书,突然就想用Golang做一个命令行贪吃蛇,也没啥特殊原因。
软件架构
- 在后台实现游戏逻辑。渲染层单独实现。
- game包中实现逻辑,draw-by-gocui中实现渲染,fk-snake为构建这两个模块的地方。
- game中一次输出整个场景的信息,因此外边是每次都clear后重新绘制。还有种做法则是给出变化序列,渲染层只改动变化(这种做法没有实现)。

上图是当前的程序结构图,橙色为模块部分,模块之间通过interface解耦,蓝色为组装模块的builder。
项目特色
- 游戏逻辑层与UI层分开,这样做有两个优点:第一,支持多种UI实现,不止gocui,加上通信就可以用js在canvas中绘制,或其它任意能绘图的前端。第二,分离逻辑后就支持CS架构,可扩展为多人线上游戏,在game中已支持了多只蛇,只需加入多玩家操作输入即可。
- 由于使用gocui会直接在命令行中绘制UI,因此log就必须特殊设计一下,本质在于将log输出到文件中,随后新开个命令行tail该文件。可以在main.go中注释掉prodLog(),并打开debugLog()即可。不过该操作还不支持windows,windows上只能用prodLog(),不输出任何log。
安装教程
- go get -v gitee.com/lwow2025/snake-go
- cd ~/go/src/gitee.com/lwow2025/snake-go
- go run main.go
Documentation
¶
There is no documentation for this package.
Source Files
¶
Directories
¶
common
|
|
|
default logger |
|
|
|
|
|
|
|
|
|
|
|
|
Click to show internal directories.
Click to hide internal directories.