简体   繁体   English

我将如何使用Ncurses在屏幕周围制作盒子

[英]How Would I go about making a box around the screen using Ncurses

I am making a simple program for a box to move in an open area. 我正在为盒子在开放区域中移动编写一个简单的程序。 now that's done I would like to make a box around the screen (Not like an Ncurses window but just to make a display). 现在完成了,我想在屏幕周围制作一个框(不像Ncurses窗口,而只是进行显示)。 I just have don't know how to do it. 我只是不知道该怎么做。 I searched google and also SO for the fix to this problem but I can't find it. 我搜索了谷歌,也搜索了此问题的解决方法,但我找不到它。 does anybody know how to make a box like that around the screen. 有人知道如何在屏幕上制作一个类似的盒子吗?

你去

The collision is already there, I just need to make a box around it. 碰撞已经存在,我只需要在其周围打一个盒子即可。 I was thinking about using characters like a normal box in Ncurses but that might not be possible, Is it possible to make a box in a box? 我当时正在考虑使用像Ncurses中的普通盒子这样的字符,但这可能是不可能的,是否可以在盒子中制作盒子?

Here I have an example of a box I made using Ncurses (My formatting sucks though, the points aren't there in the real box) 在这里,我有一个使用Ncurses制作的盒子的示例(尽管我的格式很烂,但实际盒子中没有这些点)

+--------+
|........|
+--------+

This code is the code for the movement and also calculates the collision with the outside of the field (So where the box should be): 此代码是移动代码,还计算与字段外部的碰撞(因此框应位于此处):

while((ch = getch()) != KEY_F(1))
{   switch(ch)
    {   case KEY_LEFT:
        if(win.startx>1){
            create_box(&win, FALSE);
            --win.startx;
            create_box(&win, TRUE);
        }
            break;
        case KEY_RIGHT:
        if(win.startx<122){
            create_box(&win, FALSE);
            ++win.startx;
            create_box(&win, TRUE);
        }
            break;
        case KEY_UP:
        if(win.starty>1){
            create_box(&win, FALSE);
            --win.starty;
            create_box(&win, TRUE);
        }
            break;
        case KEY_DOWN:
        if(win.starty<44){
            create_box(&win, FALSE);
            ++win.starty;
            create_box(&win, TRUE);
        }
            break;  
    }
}
endwin();
return 0;

As you can see the big box is on the first x and y line (So the first column in the terminal and the first line in the terminal) and also on line number 44 and column number 122 (the one most at the bottom and most right line and column in the terminal). 如您所见,大方框位于x和y的第一行(因此,终端的第一列和终端的第一行),以及行号44和列号122(最底端和最顶端的一个)终端中的右行和列)。 The collision already exists, If you want the full code you can click this link to pastebin and you can see how it works. 冲突已经存在,如果您需要完整的代码,则可以单击此链接到pastebin,然后查看它的工作方式。 (remember to compile with -lncurses behind the compiling command) (请记住在编译命令后加上-incurses进行编译)

Have a look at the code, it's right there. 看一下代码,就在这里。 The function is even called create_box . 该功能甚至称为create_box

Hint: the call mvaddch takes 3 arguments: the y position, the x position and the character you want to put on that position. 提示:调用mvaddch 3个参数:y位置,x位置和要放在该位置的字符。 p_win->border.XX are constants that each define a border character, like tl for top-left. p_win->border.XX是常量,每个常量定义一个边框字符,例如tl表示左上角。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM