I have recently been developing an ASCII animation package (https://github.com/peterbrittain/asciimatics) which faced similar issues. While it doesn't have everything you need to write a game, it should give you most of what you want.
The Sprite class in particular will help you handle redrawing issues. There are plenty of samples to help you get to grips with various ways to use them and other effects in the package. Here's a little demo I put together as a tribute to one of my favourite games of yesteryear...
虽然我没有在 Python 中使用过它们中的任何一个,并且似乎对 Curses 的支持更好,但在 C 中,由于这些问题,至少我将我的代码切换到 S-Lang,并且因为在内心深处,我从来没有真正喜欢过 Curses API 。
There are actually two libraries that solve this, the older curses and the newer S-Lang. Curses has a tendency to make buggy line art, especially on Windows and on unicode consoles (it's unicode support is shit). S-Lang's screen management functions are better.
While I haven't used either of them in Python, and it seems curses is better supported, in C at least I'm switching my code to S-Lang because of those issues, and because deep down I never really liked the curses API.
Try urwid. One of the examples bundled with urwid is a simulator for animated bar graphs. The bar graphs clear the screen well, without leaving artifacts of the old "frame".
发布评论
评论(6)
你可以使用诅咒。
它有一个 Windows 端口 和 Unix Port,以及大量 文档。
您还可以使用一些帮助程序库。
You can use curses.
It has a Windows Port and Unix Port, and plenty of documentation.
You can also use some helper libs.
我最近正在开发一个 ASCII 动画包(https://github.com/peterbrittain/asciimatics)面临类似的问题。 虽然它没有提供编写游戏所需的一切,但它应该可以满足您的大部分需求。
Sprite 类尤其可以帮助您处理重绘问题。 有大量示例可以帮助您掌握使用它们的各种方法以及包中的其他效果。 这是我整理的一个小演示,作为对过去我最喜欢的游戏之一的致敬...
I have recently been developing an ASCII animation package (https://github.com/peterbrittain/asciimatics) which faced similar issues. While it doesn't have everything you need to write a game, it should give you most of what you want.
The Sprite class in particular will help you handle redrawing issues. There are plenty of samples to help you get to grips with various ways to use them and other effects in the package. Here's a little demo I put together as a tribute to one of my favourite games of yesteryear...
看起来有一个用于 Python 的 curses 端口/库:
https://docs.python.org/library/curses.html
It looks like there is a curses port/library for Python:
https://docs.python.org/library/curses.html
实际上有两个库可以解决这个问题,较旧的curses 和较新的 S-Lang。 Curses 倾向于制作有缺陷的线条艺术,尤其是在 Windows 和 unicode 控制台上(它的 unicode 支持很糟糕)。 S-Lang的屏幕管理功能更好。
虽然我没有在 Python 中使用过它们中的任何一个,并且似乎对 Curses 的支持更好,但在 C 中,由于这些问题,至少我将我的代码切换到 S-Lang,并且因为在内心深处,我从来没有真正喜欢过 Curses API 。
There are actually two libraries that solve this, the older curses and the newer S-Lang. Curses has a tendency to make buggy line art, especially on Windows and on unicode consoles (it's unicode support is shit). S-Lang's screen management functions are better.
While I haven't used either of them in Python, and it seems curses is better supported, in C at least I'm switching my code to S-Lang because of those issues, and because deep down I never really liked the curses API.
尝试 urwid。 与 urwid 捆绑在一起的示例之一是动画条形图模拟器。 条形图可以很好地清除屏幕,不会留下旧“框架”的痕迹。
Try urwid. One of the examples bundled with urwid is a simulator for animated bar graphs. The bar graphs clear the screen well, without leaving artifacts of the old "frame".
我将使用 curses 模块进行调查。 它将处理很多细节,让你专注于更高层次的事情。
I would investigate using the curses module. It will take care of a lot of the details and let you focus on the higher level stuff.