问题描述
我最近问了一个关于我在下面的代码中遇到的几个问题(现已解决)的问题。程序本身很简单,有一个角色会根据用户在游戏循环中使用 wgetch()
函数捕获的输入在框出的窗口中移动。
继续编码虽然我发现了一个新问题:
我创建的窗口(我称之为 stage
)必须和屏幕一样大(stdscr
),否则角色的移动会留下“轨迹”,重新创建这里提到的问题 {{3} }.
因此,如果我执行 createstage()
函数将窗口设置为小于屏幕(这是它应该工作的方式),则会出现这些图形工件。
有没有一种方法可以解决这个问题,而不必自己绘制/实现框/窗口或仅使用 stdscr
?
#include "curses.h"
#include <windows.h>
void disableselection(){
HANDLE hInput;
DWORD prev_mode;
hInput = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(hInput,&prev_mode);
SetConsoleMode(hInput,prev_mode & ENABLE_EXTENDED_FLAGS);
}
void disableresizing(){
HWND consoleWindow = GetConsoleWindow();
SetwindowLong(consoleWindow,GWL_STYLE,getwindowlong(consoleWindow,GWL_STYLE) & ~WS_MAXIMIZEBox & ~WS_SIZEBox);
}
void initialize(){
initscr();
curs_set(0);
disableselection();
disableresizing();
noecho();
}
WINDOW* createstage(int starty=0,int startx=0,int height=LInes,int width=COLS){
WINDOW* win=newwin(height-starty,width-startx,starty,startx);
nodelay(win,TRUE);
refresh();
return win;
}
void end(WINDOW* stage){
clear();
refresh();
nodelay(stdscr,FALSE);
printw("press something to exit");
getch();
endwin();
}
int main(){
initialize();
WINDOW* stage= createstage();
int ywindow,xwindow,heightwindow,widthwindow;
getbegyx(stage,ywindow,xwindow);
getmaxyx(stage,widthwindow);
heightwindow--;
widthwindow--;
int x = xwindow+1,y = ywindow+1;
char c = '@';
while(TRUE){
Box(stage,0);
wmove(stage,y,x);
waddch(stage,'@');
c=wgetch(stage);
if(c=='w' && y-1>ywindow){
y--;
}
if (c=='s' && y+1<heightwindow){
y++;
}
if(c=='d' && x+1<widthwindow){
x++;
}
if(c=='a' && x-1>xwindow){
x--;
}
wrefresh(stage);
napms(16);
wclear(stage);
}
end(stage);
}
在 Windows 上使用 C++ 和 PDCurses3.8
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)