2014-07-10 101 views
0

夥計們,我不知道爲什麼窗口邊框/打印沒有出現。我哪裏錯了?它正在工作之前。我添加了評論括號中的部分。儘管我刪除了這些零件,但它仍然停止工作。您打印C-窗口/打印不出現

#include <ncurses.h> 
#include <stdio.h> 
#include <stdlib.h> 

int main() 
{ 
    int y = 2; 
    int x = 2; 
    int oldy = 2; 
    int oldx = 2; 
    char m = 'l'; 

    initscr(); 
    WINDOW* win; 
    win = newwin(41,40, 0 ,0); 
    /*WINDOW* win2 = newwin(10,10, 40 ,0);*/ 
    box(win, ACS_VLINE, ACS_HLINE); 
    /*box(win2, ACS_VLINE, ACS_HLINE);*/ 
    mvwprintw(win,1, 1, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); 
    mvwprintw(win,2, 1, "X X X  X X   X  X X"); 
    mvwprintw(win,3, 1, "X X X X XXX X X X XXXXXXXX X XXXXX X X"); 
    mvwprintw(win,4, 1, "X X X  X X X X   X  X X"); 
    mvwprintw(win,5, 1, "X XXXXXXX XXXXX X X XXXXXXXXXX XXXXX X"); 
    mvwprintw(win,6, 1, "X  X X  X X   X  X"); 
    mvwprintw(win,7, 1, "XXXXXXX X XXXXXXX XXXXXXXXXX XXXXXXXXX"); 
    mvwprintw(win,8, 1, "X  X X  X  X X  X"); 
    mvwprintw(win,9, 1, "X XXXXXXX X XXXXXXX XXXXXX X XXXXX X"); 
    mvwprintw(win,10, 1, "X X  X X    XXXX X X X"); 
    mvwprintw(win,11, 1, "X X XXXXX X XXXX XXXXXXXX  X X XXX"); 
    mvwprintw(win,12, 1, "X X X  X XXXX X  XXXXXXX X X X"); 
    mvwprintw(win,13, 1, "X X XXX X X X XXXXX X X X X X"); 
    mvwprintw(win,14, 1, "XXXXX X X XXXX X X X X X X XXXXX X"); 
    mvwprintw(win,15, 1, "X  X X X XXXXX X X X X X  X X"); 
    mvwprintw(win,16, 1, "X XXXXX X X XXXX  X X X X XXXXX X X"); 
    mvwprintw(win,17, 1, "X X  X X X XXXXX  X   X"); 
    mvwprintw(win,18, 1, "X X XXXXX XXXX X X XXXXXXXXXXXXXXXXX"); 
    mvwprintw(win,19, 1, "X X   X X     O"); 
    mvwprintw(win,20, 1, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); 
    wmove(win,2,2); 
    wrefresh(win); 
    /*wrefresh(win2);*/ 


    while(m != 'q') 
    { 
      /*mvwprintw(win2,41,0,"22");*/ 
      /*wrefresh(win2);*/ 
      m=getch(); 
      /*mvwprintw(win2,40,0,"Please use the following keys to navigate through the maze.(W) Up (S) Down (D) Right (A) Left");*/ 
      wrefresh(win); 

    switch(m) 
     { 
      case 'S': if(mvwinch(win,(oldy+1),x)=='X') 
         { 
         mvwprintw(win,40,0,"Sorry, you cant move there."); 
         wrefresh(win); 
         wmove(win,oldy,oldx); 
         wrefresh(win); 
         } 

         else 
         { 
         wmove(win,(y=oldy+1),x); 
         wrefresh(win); 
         oldy = y; 
         } 
       break; 

      case 'D': if(mvwinch(win,y,(oldx+1))=='X') 
         { 
         mvwprintw(win,40,0,"Sorry, you cant move there."); 
         wrefresh(win); 
         wmove(win,oldy,oldx); 
         wrefresh(win); 
         } 

         else 
         { 
         wmove(win,y,x=(oldx+1)); 
         wrefresh(win); 
         oldx = x; 
         } 
       break; 

      case 'A': if(mvwinch(win,y,(oldx-1))=='X') 
         { 
         mvwprintw(win,40,0,"Sorry, you cant move there."); 
         wrefresh(win); 
         wmove(win,oldy,oldx); 
         wrefresh(win); 
         } 

         else 
         { 
         wmove(win,y,x=(oldx-1)); 
         wrefresh(win); 
         oldx = x; 
         } 
       break; 

      case 'W': if(mvwinch(win,(oldy-1),x)=='X') 
         { 
         mvwprintw(win,40,0,"Sorry, you cant move there."); 
         wrefresh(win); 
         wmove(win,oldy,oldx); 
         wrefresh(win); 
         } 

         else 
         { 
         wmove(win,y=(oldy-1),x); 
         wrefresh(win); 
         oldy = y; 
         } 
       break; 

      default: m = 'q'; 

     } 

    } 

    delwin(win); 
    /*delwin(win2);*/ 
    endwin(); 

    return 0; 
} 
+0

感謝上帝,你有備份。你呢,是嗎? –

+0

Nooooo:((Did not expect it happen。 – user3753834

+0

我相信這是諷刺。 –

回答

0

一切都在win,但getch()stdscr(默認全屏窗口)的讀取。從stdscr中讀數會導致它跳到窗口堆棧頂部,從而模糊了您的win。使用wgetch(win)

+0

這與movment有關,我對光標的修飾沒有任何問題。唯一的問題是,迷宮沒有被打印。 – user3753834

+0

你試過嗎?我沒有猜測。'getch()'描繪了stdscr',因爲'stdscr'是空白的。如果你仍然不相信我,在你的'getch()'之前加一個'sleep(3)',這個迷宮出現3秒鐘然後消失 –

+0

你也可以指出哪個getch ?最後一個? – user3753834