gpt4 book ai didi

c - ncurses 新手 - 从 GNU C 开始

转载 作者:太空狗 更新时间:2023-10-29 17:09:43 24 4
gpt4 key购买 nike

更简单的生活

我将回到 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com