c - ncurses 新手 - 从 GNU C 开始

标签 c gcc animation ncurses

更简单的生活

我将回到 C 语言以帮助重振我的编程天赋。我上一次学习编程是在大学期间在 MSDOS 上使用 Turbo C。一旦我发现 Borland 的友好 <conio.h>,简单的 ASCII 动画就成了我的痴迷。一个包括离开。 gotoxy 带来了很多乐趣和 textcolor功能,不久之后我就开始编写像 snake 和 pong 这样的游戏。这是一种非常有益的学习语言的方式,随着我的雄心壮志,每场比赛都让我走得更远。

ncurses

我想从类似的游戏类型项目开始。不过今天,我在一台 Mac 电脑上,角落里有一台布满灰尘的 Linux 机器。我可以在 dosbox(一个足够普遍的平台)中启动我心爱的 Turbo C,但我想学习 C 以便我可以开发在任何 BSD 或 unix 平台上自然编译的东西。有人告诉我 ncurses 是前进的方向,但 GNU 站点在很大程度上已经超出了我的理解范围。回到那天我有我的 friend textmode功能,我是一个print远离乒乓球的表情。 ncurses 似乎更强大。

嗖嗖

这种情况想必很多人都遇到过。我正在寻找相关的教程或资源,以帮助我了解什么是 ncurses 以及如何使用它。任何提示或类似的故事也会引起极大的兴趣!

最佳答案

是的,ncurses 就是您要查找的库。例如,这里是 gotoxy 的 (n)curses 等价物:

NAME

move, wmove - move curses window cursor

SYNOPSIS

   #include <curses.h>

   int move(int y, int x);
   int wmove(WINDOW *win, int y, int x);

DESCRIPTION

These routines move the cursor associated with the window to line y and column x. This routine does not move the physical cursor of the terminal until refresh is called. The position specified is relative to the upper left-hand corner of the window, which is (0,0).

附录:

在您的评论中,您询问了有关 curses windows 的问题 - 我认为我无法真正改进 ncurses 手册页对此所说的内容,所以我只引用它:

The ncurses library permits manipulation of data structures, called windows, which can be thought of as two-dimensional arrays of characters representing all or part of a CRT screen. A default window called stdscr, which is the size of the terminal screen, is supplied. Others may be created with newwin.

Note that curses does not handle overlapping windows, that's done by the panel(3CURSES) library. This means that you can either use stdscr or divide the screen into tiled windows and not using stdscr at all. Mixing the two will result in unpredictable, and undesired, effects.

Windows are referred to by variables declared as WINDOW *. These data structures are manipulated with routines described here and elsewhere in the ncurses manual pages. Among those, the most basic routines are move and addch. More general versions of these routines are included with names beginning with w, allowing the user to specify a window. The routines not beginning with w affect stdscr.

After using routines to manipulate a window, refresh is called, telling curses to make the user's CRT screen look like stdscr. The characters in a window are actually of type chtype, (character and attribute data) so that other information about the character may also be stored with each character.

因此,总而言之,您可以放心地忽略整个窗口,而只使用 stdscr 窗口。

关于c - ncurses 新手 - 从 GNU C 开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1632119/

相关文章:

c - 需要从C中的字符串中删除字符

gcc - gcc 如何在特定平台上获得每种类型的对齐方式?

python - 如何在windows ubuntu bash上安装python3.6

gcc - 基于 GCC/LLVM 的语言何时会在 x86 Windows 上支持 SEH 异常?

c - 针对用户定义的函数类型转换错误生成编译器警告

c - 如何判断HTTP数据包中 "Content-Length: "的长度

c++ - C/C++ : Converting hexadecimal value in char to integer

javascript - 如何在 css 中重新启动组动画?

swift - 动画导航栏颜色

javascript - 如何使用 jQuery 在鼠标悬停时制作简单的淡入淡出效果或慢速动画