在 Linux 终端中玩贪吃蛇
贪吃蛇

> 
> 有了这个 20 世纪 70 年代的经典重制游戏，Python 将不再是你在 Linux 终端能发现的唯一的“蛇”。
> 
> 
> 


![](/data/attachment/album/201901/12/104301hucp64f1cj1o47mz.png)


欢迎回到 Linux 命令行玩具日历。如果这是你第一次访问该系列，你可能会问什么是命令行玩具。这很难确切地说，但我的定义是任何可以帮助你在终端玩得开心的东西。


我们这周都在介绍游戏，这很有趣，接着让我们看下今天的游戏，贪吃蛇！


贪吃蛇是一个古老又很好的游戏，这些年一直有各种版本。我记得我第一次玩得版本是 20 世纪 90 年代与 [QBasic](https://en.wikipedia.org/wiki/QBasic) 一起打包发布的 [Nibbles](https://en.wikipedia.org/wiki/Nibbles_(video_game))，它对我理解什么是编程语言起了很重要的作用。我有游戏的源码，我可以修改并查看会发生什么，并学习到一些组成这个编程语言的有趣词汇究竟是什么意思。


今天的[贪吃蛇](https://github.com/DyegoCosta/snake-game)是用 Go 写的，它很简单并且和原版的游戏一样有趣。像大多数简单的老游戏一样，它有很多版本可供选择。这今天的贪吃蛇中，甚至还有一个经典的 [bsdgames](https://github.com/vattam/BSDGames) 形式的包，它的发行版几乎一定有它。


但我喜欢的是用 Docker 打包的贪吃蛇，因为我可以轻松地在命令行中运行，而不用担心发行版相关的问题。这个版本使用 15 个随机的食物 emoji 图案让蛇来吃。我玩得不好。不管怎样，请试一下：



```
$ docker run -ti dyego/snake-game
```

这个贪吃蛇以 MIT 许可证开源，你可在 [Github](https://github.com/DyegoCosta/snake-game) 取得源码。


![](/data/attachment/album/201901/12/104305wewum0p6a5p9b9a6.gif)


你有特别喜欢的命令行小玩具需要我介绍的吗？这个系列要介绍的小玩具大部分已经有了落实，但还预留了几个空位置。请在评论区留言，我会查看的。如果还有空位置，我会考虑介绍它的。如果没有，但如果我得到了一些很好的意见，我会在最后做一些有价值的提及。


请查看昨天的玩具，[数字 2 的力量，Linux 的力量：在命令行中玩 2048](https://opensource.com/article/18/12/linux-toy-2048)，记得明天再来！




---


via: <https://opensource.com/article/18/12/linux-toy-snake>


作者：[Jason Baker](https://opensource.com/users/jason-baker) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
Welcome back to the Linux command-line toys advent calendar. If this is your first visit to the series, you might be asking yourself what a command-line toy even is. It's hard to say exactly, but my definition is anything that helps you have fun at the terminal.

We've been on a roll with games over the weekend, and it was fun, so let's look at one more game today, Snake!

Snake is an oldie but goodie; versions of it have been around seemingly forever. The first version I remember playing was one called [Nibbles](https://en.wikipedia.org/wiki/Nibbles_(video_game)) that came packaged with [QBasic](https://en.wikipedia.org/wiki/QBasic) in the 1990s, and was probably pretty important to my understanding of what a programming language even was. Here I had the source code to a game that I could modify and just see what happens, and maybe learn something about what all of those funny little words that made up a programming language were all about.

Today's [Snake](https://github.com/DyegoCosta/snake-game) is written in Go, and while it's simple, it's just as much fun as the original. Like most simple old games, there are a ton of versions to choose from. In Snake's case, there's even a version in the classic [bsdgames](https://github.com/vattam/BSDGames) package that's almost certainly packaged for your distribution.

But what I like about this version of Snake is that it's packaged for Docker so I can easily run it in one line from my terminal without worrying about anything disto-specific. That, and it makes use of 15 randomized food emojis for the snake to eat. I'm a sucker for food emojis. Anyway, give it a try using:

`$ docker run -ti dyego/snake-game`


This Snake is licensed as open source under an MIT license, and you can check out the source code [on GitHub](https://github.com/DyegoCosta/snake-game).

![Animated snake game Animated snake game](https://opensource.com/sites/default/files/uploads/linux-toy-snake-animated.gif)

Do you have a favorite command-line toy that you think I ought to profile? The calendar for this series is mostly filled out but I've got a few spots left. Let me know in the comments below, and I'll check it out. If there's space, I'll try to include it. If not, but I get some good submissions, I'll do a round-up of honorable mentions at the end.

Check out yesterday's toy, [Powers of two, powers of Linux: 2048 at the command line](https://opensource.com/article/18/12/linux-toy-2048), and check back tomorrow for another!

## Comments are closed.