Почему мое окно не перезаписывает себя каждый раз, когда оно движется? - PullRequest
0 голосов
/ 04 декабря 2018

Итак, я пытаюсь использовать «блокиратор» в городской оборонительной игре

void *defense( void *maxBuildingHeight ){
    // the height to put the defense; 2 above the highest building
    int *defense_row = ((int *)maxBuildingHeight);
    int MAXX, MAXY;
    getmaxyx(stdscr,MAXY,MAXX); // screen rows and cols
    WINDOW *inputwin = newwin(1,5,(MAXY - (*defense_row + 2)),MAXX/2); //create the window for the defense
    char blocker[] = "#####";
    wprintw(inputwin, blocker); //the defense
    wrefresh(inputwin);
    keypad(inputwin, true); // collect the user input
    int newX = MAXX/2-2; // the left most position of the defense
    BlockerYSpot = (MAXY - (*defense_row + 2));

    while ( 1 ){
        int input = wgetch(inputwin);
        if (input == KEY_LEFT && (newX - 1) >= 0){
            newX--;
            pthread_mutex_lock(&mutex);
            mvwin(inputwin, BlockerYSpot, newX);
            wrefresh(inputwin);
            pthread_mutex_unlock(&mutex);
        }
        else if (input == KEY_RIGHT && (newX + 5) < MAXX){ // its +5 due to the length of the blocker
            newX++;
            pthread_mutex_lock(&mutex);
            mvwin(inputwin, BlockerYSpot, newX);
            wrefresh(inputwin);
            pthread_mutex_unlock(&mutex);
        } else if (input == 'q'){
            delwin(inputwin);
            endwin();
            exit( EXIT_FAILURE );
        }
        CurrentBlockerXSpot = newX;
    }//while
}

мой текущий результат без перемещения влево или вправо enter image description here

Мой вывод, когда я перемещаю блокиратор влево, вы можете видеть, что он не стирает предыдущий блокировщик.enter image description here

1 Ответ

0 голосов
/ 04 декабря 2018

Вы явно обновляете inputwin, но не окно под ним.Не видя остальную часть вашего кода, я предполагаю, что это stdscr.refresh() (или wrefresh()) окно под «защитой» для перекраски областей, где был inputwin.

...