How to draw coordinates in ncurses c++

2019-09-05 04:08发布

Coordinates

Hi Guys, using the following codes i was able to create a coordinate map system. but i an stuck at getting the coordinates marked. now i will get (x,y) from the user and i need to mark it inside the map with " * ". the user would be give several (x,y) coordinates and i need to mark. I am unable to do so. I understand i need to modify the loop but if i modify it gets totally messy. Please advice. i am using the ncurses.

mvaddstr(3 - 2, 3 + 5, "Main Board");
mvaddstr(3 - 1, 3 - 3, numbers); 
for (y = 0; y < 7; ++y) {
    mvaddch(3 + y, 3 - 3, (chtype) (y + '0'));
    attron(COLOR_PAIR(COLOR_RED));
    addch(' ');
    for (x = 0; x < 7; x++) {
       (void) addstr(" . ");            
    }
    (void) attrset(0);
    (void) addch(' ');
    (void) addch((chtype) (y + '0'));
}

标签: c++ ncurses
1条回答
Summer. ? 凉城
2楼-- · 2019-09-05 04:31

How about seperating the model. e.g. Keep the state in a different object or struct and create a function to draw the model. It might be easier to maintain and change. :).

查看更多
登录 后发表回答