简体   繁体   中英

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). 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?

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)

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

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). The collision already exists, If you want the full code you can click this link to pastebin and you can see how it works. (remember to compile with -lncurses behind the compiling command)

Have a look at the code, it's right there. The function is even called 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. p_win->border.XX are constants that each define a border character, like tl for top-left.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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