void printValue(struct tile ** board, int size, int pos_rel) { // int pos_rel = SHIFT_RIGHT; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (board[i][j].value != 0) { //convert from int to char char buf[1000]; snprintf(buf, 1000, "%d", board[i][j].value); if (board[i][j].value >= 1024) { //number takes 4 positions or more mvprintw((tile_size + 1) * i + 3, (tile_size + 1) * j + 1 + pos_rel, buf); } if (board[i][j].value >= 16 && board[i][j].value < 1024) { //number take from 2 to 3 positions if (board[i][j].value == 16) { attron(COLOR_PAIR(5)); mvprintw((tile_size + 1) * i + 3, (tile_size + 1) * j + 2 + pos_rel, buf); attroff(COLOR_PAIR(5)); } if (board[i][j].value == 32) { attron(COLOR_PAIR(6)); mvprintw((tile_size + 1) * i + 3, (tile_size + 1) * j + 2 + pos_rel, buf); attroff(COLOR_PAIR(6)); } if (board[i][j].value == 64) { attron(COLOR_PAIR(7)); mvprintw((tile_size + 1) * i + 3, (tile_size + 1) * j + 2 + pos_rel, buf); attroff(COLOR_PAIR(7)); } if (board[i][j].value == 128) { attron(COLOR_PAIR(8)); mvprintw((tile_size + 1) * i + 3, (tile_size + 1) * j + 2 + pos_rel, buf); attroff(COLOR_PAIR(8)); } if (board[i][j].value == 256) { attron(COLOR_PAIR(9)); mvprintw((tile_size + 1) * i + 3, (tile_size + 1) * j + 2 + pos_rel, buf); attroff(COLOR_PAIR(9)); } if (board[i][j].value == 512) { attron(COLOR_PAIR(10)); mvprintw((tile_size + 1) * i + 3, (tile_size + 1) * j + 2 + pos_rel, buf); attroff(COLOR_PAIR(10)); } } if (board[i][j].value <= 8) { //number takes 1 position if (board[i][j].value == 2) { attron(COLOR_PAIR(2)); mvprintw((tile_size + 1) * i + 3, (tile_size + 1) * j + 3 + pos_rel, buf); attroff(COLOR_PAIR(2)); } if (board[i][j].value == 4) { attron(COLOR_PAIR(3)); mvprintw((tile_size + 1) * i + 3, (tile_size + 1) * j + 3 + pos_rel, buf); attroff(COLOR_PAIR(3)); } if (board[i][j].value == 8) { attron(COLOR_PAIR(4)); mvprintw((tile_size + 1) * i + 3, (tile_size + 1) * j + 3 + pos_rel, buf); attroff(COLOR_PAIR(4)); } } } } } }
/*Prints quick choice menu*/ int twoChoices(int line, char* choice1, char* choice2) { silenceOn(); int posAct = 1; int input = 0; const short int posMin = 1; const short int posMax = 2; clearLine(line); cutAndPrint(line, 2, 1, choice1); cutAndPrint(line, 2, 2, choice2); wrefresh(stdscr); /*Repeating menu loop*/ while (1 == 1) { silenceOn(); input = 0; /*Text appearance loop*/ while (1 == 1) { if (input == KEY_RIGHT) { posAct++; } else if (input == KEY_LEFT) { posAct--; } /*If ENTER is pressed, exit the loop*/ else if (input == 10) { break; } /*In case if moved outside the min and max boundary*/ if (posAct > posMax) { posAct = posMax; } else if (posAct < posMin) { posAct = posMin; } /*Change the text appearance*/ switch(posAct) { case 1: attron(A_REVERSE); cutAndPrint(line, 2, 1, choice1); attroff(A_REVERSE); cutAndPrint(line, 2, 2, choice2); wrefresh(stdscr); break; case 2: cutAndPrint(line, 2, 1, choice1); attron(A_REVERSE); cutAndPrint(line, 2, 2, choice2); attroff(A_REVERSE); wrefresh(stdscr); break; } /*Wait for input*/ flushinp(); input = getch(); } switch (posAct) { case 1: clearLine(line); return TRUE; break; case 2: clearLine(line); return FALSE; break; } } return FALSE; silenceOff(); }
void Laberinto(int **mat,int filas,int columnas,int f,int c){ if (f<filas){ if(f>0){ if(c>0){ if(mat[f-1][c-1]==0){ printw(" >>> (%i;%i)=%i",(f-1),(c-1),mat[f-1][c-1]);refresh(); mat[f-1][c-1]=2; Laberinto(mat,filas,columnas,(f-1),(c-1)); mat[f-1][c-1]=0; } } if (mat[f-1][c]==0){ printw(" >>> (%i;%i)=%i",(f-1),c,mat[f-1][c]);refresh(); mat[f-1][c]=2; Laberinto(mat,filas,columnas,(f-1),c); mat[f-1][c]=0; } if((c+1)<columnas){ if(mat[f-1][c+1]==0){ printw(" >>> (%i;%i)=%i",(f-1),(c+1),mat[f-1][c+1]);refresh(); mat[f-1][c+1]=2; Laberinto(mat,filas,columnas,(f-1),(c+1)); mat[f-1][c+1]=0; } } } if(c>0){ if(mat[f][c-1]==0){ printw(" >>> (%i;%i)=%i",f,(c-1),mat[f][c-1]);refresh(); mat[f][c-1]=2; Laberinto(mat,filas,columnas,f,(c-1)); mat[f][c-1]=0; } } if((c+1)<columnas){ if(mat[f][c+1]==0){ printw(" >>> (%i;%i)=%i",f,(c+1),mat[f][c+1]);refresh(); mat[f][c+1]=2; Laberinto(mat,filas,columnas,f,(c+1)); mat[f][c+1]=0; } } if((f+1)<filas){ if(c>0){ if(mat[f+1][c-1]==0){ printw(" >>> (%i;%i)=%i",(f+1),(c-1),mat[f+1][c-1]);refresh(); mat[f+1][c-1]=2; Laberinto(mat,filas,columnas,(f+1),(c-1)); mat[f+1][c-1]=0; } } if(mat[f+1][c]==0){ printw(" >>> (%i;%i)=%i",(f+1),c,mat[f+1][c]);refresh(); mat[f+1][c]=2; Laberinto(mat,filas,columnas,(f+1),c); mat[f+1][c]=0; } if((c+1)<columnas){ if(mat[f+1][c+1]==0){ printw(" >>> (%i;%i)=%i",(f+1),(c+1),mat[f+1][c+1]);refresh(); mat[f+1][c+1]=2; Laberinto(mat,filas,columnas,(f+1),(c+1)); mat[f+1][c+1]=0; } } } sleep(2); printw("\n<<<(%i,%i)<<<Backtrack!! ==> ",f,c);refresh(); Mostrar(mat,filas,columnas,f,c); sleep(1); if(f==(filas-1)){ attron(COLOR_PAIR(5)); printw("\nSalida >>>(%i;%i)",f,c);refresh(); sleep(1); attroff(COLOR_PAIR(5)); } } }
int main(int argc, char *argv[]) { char *user_config_dir = get_user_config_dir(); int config_err = 0; f_loadfromfile = 1; int f_flag = 0; int i = 0; for (i = 0; i < argc; ++i) { if (argv[i] == NULL) break; else if (argv[i][0] == '-') { if (argv[i][1] == 'f') { if (argv[i + 1] != NULL) DATA_FILE = strdup(argv[i + 1]); else f_flag = -1; } else if (argv[i][1] == 'n') { f_loadfromfile = 0; } } } config_err = create_user_config_dir(user_config_dir); if (DATA_FILE == NULL ) { if (config_err) { DATA_FILE = strdup("data"); } else { DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1); if (DATA_FILE != NULL) { strcpy(DATA_FILE, user_config_dir); strcat(DATA_FILE, CONFIGDIR); strcat(DATA_FILE, "data"); } else { endwin(); fprintf(stderr, "malloc() failed. Aborting...\n"); exit(EXIT_FAILURE); } } } if (config_err) { SRVLIST_FILE = strdup(PACKAGE_DATADIR "/DHTservers"); } else { SRVLIST_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("DHTservers") + 1); if (SRVLIST_FILE != NULL) { strcpy(SRVLIST_FILE, user_config_dir); strcat(SRVLIST_FILE, CONFIGDIR); strcat(SRVLIST_FILE, "DHTservers"); } else { endwin(); fprintf(stderr, "malloc() failed. Aborting...\n"); exit(EXIT_FAILURE); } } free(user_config_dir); init_term(); Tox *m = init_tox(); if (m == NULL) { endwin(); fprintf(stderr, "Failed to initialize network. Aborting...\n"); exit(EXIT_FAILURE); } prompt = init_windows(m); if (f_loadfromfile) load_data(m, DATA_FILE); if (f_flag == -1) { attron(COLOR_PAIR(RED) | A_BOLD); wprintw(prompt->window, "You passed '-f' without giving an argument.\n" "defaulting to 'data' for a keyfile...\n"); attroff(COLOR_PAIR(RED) | A_BOLD); } if (config_err) { attron(COLOR_PAIR(RED) | A_BOLD); wprintw(prompt->window, "Unable to determine configuration directory.\n" "defaulting to 'data' for a keyfile...\n"); attroff(COLOR_PAIR(RED) | A_BOLD); } prompt_init_statusbar(prompt, m); while (true) { do_tox(m, prompt); do_file_senders(m); draw_active_window(m); } exit_toxic(m); return 0; }
int draw_item_list(select_menu *menu) { select_item *it; int i=0,j=0,k=0,d,sc=0; int c,curopt=0; char buf[40]; select_item *current=NULL; int should_scroll,max_display; int len,max_len=0; int disp_start=0,actual_pos=0; again: i=0;j=0;k=0; max_display=max_y/2-2; should_scroll=menu->item_no>max_display?1:0; wclear(menu_window); /* print title in colour */ attron(COLOR_PAIR(1)); mvprintw(HIGH_NOTICE_Y,max_x/2-20,menu->name); attroff(COLOR_PAIR(1)); if (should_scroll) { for (it=menu->item_list,sc=0;it;it=it->next,sc++) { /* only draw visible part of menu */ if (sc>=disp_start && i < max_display) { wmove(menu_window, max_y/4+j++, max_x / 2 - 20); i++; snprintf(buf, sizeof(buf), "[%s] %s", it->enabled ? "*" : " ", it->name); waddstr(menu_window, buf); len=strlen(it->name); if (len > max_len) max_len=len; } } } else { for (it=menu->item_list,sc=0;it;it=it->next,sc++) { /* draw everything */ wmove(menu_window, max_y/4+j++, max_x / 2 - 20); i++; snprintf(buf, sizeof(buf), "[%s] %s", it->enabled ? "*" : " ", it->name); waddstr(menu_window, buf); len=strlen(it->name); if (len > max_len) max_len=len; } /* marker is always in par with the selected option */ actual_pos=curopt; } for(it=menu->item_list;it;it=it->next) if (k++ == curopt) { current=it; break; } /* print current item description */ if (current->description) { attron(COLOR_PAIR(1)); print_notice(NOTICE_Y,NOTICE_X,0,current->description); attroff(COLOR_PAIR(1)); } move(max_y/4+actual_pos,max_x/2-19); /* draw box */ wattron(menu_window,COLOR_PAIR(2)); for (d=-1;d<i+1;d++) { wmove(menu_window,max_y/4+d,max_x/2-26); wprintw(menu_window,"|"); wmove(menu_window,max_y/4+d,max_x/2-10+max_len); wprintw(menu_window,"|"); } for (d=0;d<max_len+15;d++) { wmove(menu_window,max_y/4-2,max_x/2-25+d); wprintw(menu_window,"_"); wmove(menu_window,max_y/4+i,max_x/2-25+d); wprintw(menu_window,"_"); } /* show scrolling notifications if it's the case */ if (should_scroll && disp_start > 0) { wmove(menu_window,max_y/4,max_x/2-5+max_len); wprintw(menu_window,"Scroll up for more"); } if (should_scroll && disp_start + max_display < menu->item_no) { wmove(menu_window,max_y/4+max_display-1,max_x/2-5+max_len); wprintw(menu_window,"Scroll down for more"); } wattroff(menu_window,COLOR_PAIR(2)); wrefresh(menu_window); k=0; while ((c = getch())) { switch (c) { case KEY_UP: if (should_scroll && curopt != 0) { if (curopt == disp_start) { disp_start--; actual_pos=0; } else actual_pos--; curopt--; } else if (curopt!=0) { curopt--; } break; case KEY_DOWN: if (should_scroll && curopt < menu->item_no-1) { if (curopt == (disp_start+max_display-1)) { disp_start++; actual_pos=i-1; } else actual_pos++; curopt++; } else if (curopt < i-1) { curopt++; } break; case ' ': for (it=menu->item_list;it;it=it->next) { if (k++ == curopt) { it->enabled=it->enabled?0:1; menu->child_changed=CHILD_CHANGED; } } break; case KEY_LEFT: case 'q': case 'Q': wclear(menu_window); return 0; } goto again; } return 0; }
/* takes in an int i (current position in list), a list, the count of how many items are in the list(cnt), an integer to check if the user has won the level (win), and the level counter. Moves the unit, applies any damage dealt, removes dead units from the list and checks if the user wins the level. */ int MoveUnit(int i, List * L, int * cnt, int * direction, int * win, int levelCount) { /*ch holds the farmer avatar value*/ char ch; /*check is set if the unit is travelling vertically (code to check for damage is the same travelling up or down, eliminates redundant code)*/ int check = 0; mvwprintw(stdscr, 0, 0, "Level %d", levelCount); /*Checks which direction to head when travelling vertically, so the unit doesn't jump between the path behind it and in front of it. 1 = up, 0 = down*/ if(mvinch(L->items[i].y, (L->items[i].x + 1)) != '.' && mvinch(L->items[i].y, (L->items[i].x + 1)) != 'B' && mvinch(L->items[i].y, (L->items[i].x + 1)) != 'Y' && mvinch(L->items[i].y, (L->items[i].x + 1)) != 'S' && mvinch((L->items[i].y - 1), L->items[i].x) == '+') L->items[i].direction = 1; else if(mvinch(L->items[i].y, (L->items[i].x + 1)) != '.' && mvinch(L->items[i].y, (L->items[i].x + 1)) != 'B' && mvinch(L->items[i].y, (L->items[i].x + 1)) != 'Y' && mvinch(L->items[i].y, (L->items[i].x + 1)) != 'S' && mvinch((L->items[i].y + 1), L->items[i].x) == '+') L->items[i].direction = 0; /*check if the unit should move to the left*/ if(mvinch(L->items[i].y, (L->items[i].x - 1)) == '+') { /*move avatar to the left, replace its old spot with a '+', alter the unit's coordinates.*/ mvaddch(L->items[i].y, (L->items[i].x - 1), L->items[i].avatar); mvaddch(L->items[i].y, L->items[i].x, '+'); L->items[i].x = L->items[i].x - 1; /*damage calculations*/ ch = (char)mvinch((L->items[i].y - 1), (L->items[i].x - 1)); if(ch == 'B') { L->items[i].hp = L->items[i].hp - BDAM; /*if damage is taken, replace the character, but in red*/ attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'Y') { L->items[i].hp = L->items[i].hp - YDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'S') { L->items[i].hp = L->items[i].hp - SDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); } ch = (char)mvinch((L->items[i].y - 1), (L->items[i].x)); if(ch == 'B') { L->items[i].hp = L->items[i].hp - BDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'Y') { L->items[i].hp = L->items[i].hp - YDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'S') { L->items[i].hp = L->items[i].hp - SDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); } ch = (char)mvinch((L->items[i].y - 1), (L->items[i].x + 1)); if(ch == 'B') { L->items[i].hp = L->items[i].hp - BDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'Y') { L->items[i].hp = L->items[i].hp - YDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'S') { L->items[i].hp = L->items[i].hp - SDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); } ch = (char)mvinch((L->items[i].y + 1), (L->items[i].x - 1)); if(ch == 'B') { L->items[i].hp = L->items[i].hp - BDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'Y') { L->items[i].hp = L->items[i].hp - YDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'S') { L->items[i].hp = L->items[i].hp - SDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); } ch = (char)mvinch((L->items[i].y + 1), (L->items[i].x)); if(ch == 'B') { L->items[i].hp = L->items[i].hp - BDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'Y') { L->items[i].hp = L->items[i].hp - YDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'S') { L->items[i].hp = L->items[i].hp - SDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); } ch = (char)mvinch((L->items[i].y + 1), (L->items[i].x + 1)); if(ch == 'B') { L->items[i].hp = L->items[i].hp - BDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'Y') { L->items[i].hp = L->items[i].hp - YDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'S') { L->items[i].hp = L->items[i].hp - SDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); } /*check if unit moves up.*/ }else if(mvinch((L->items[i].y - 1), L->items[i].x) == '+' && L->items[i].direction == 1) { mvaddch((L->items[i].y - 1), L->items[i].x, L->items[i].avatar); mvaddch(L->items[i].y, L->items[i].x, '+'); L->items[i].y = L->items[i].y - 1; check = 1; /*check if unit moves down.*/ } else if(mvinch((L->items[i].y + 1), L->items[i].x) == '+' && L->items[i].direction == 0) { mvaddch((L->items[i].y + 1), L->items[i].x, L->items[i].avatar); mvaddch(L->items[i].y, L->items[i].x, '+'); L->items[i].y = L->items[i].y + 1; check = 1; /*following code blocks check if the unit has reached the end of the map. If so, removes unit from the map (not the list!), sets win condition to 1, and subtracts 1 from the count of units on the board.*/ }else if(mvinch(L->items[i].y, (L->items[i].x - 1)) == 'O') { mvaddch(L->items[i].y, L->items[i].x, '+'); if(*cnt != 0) *cnt = *cnt - 1; *win = 1; } else if(mvinch((L->items[i].y - 1), L->items[i].x) == 'O') { mvaddch(L->items[i].y, L->items[i].x, '+'); if(*cnt != 0) *cnt = *cnt - 1; *win = 1; } else if(mvinch((L->items[i].y + 1), L->items[i].x) == 'O') { mvaddch(L->items[i].y, L->items[i].x, '+'); if(*cnt != 0) *cnt = *cnt - 1; *win = 1; } /*if the unit is travellint vertically, check for damage*/ if(check == 1) { /*damage calculations*/ ch = (char)mvinch((L->items[i].y - 1), (L->items[i].x - 1)); if(ch == 'B') { L->items[i].hp = L->items[i].hp - BDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'Y') { L->items[i].hp = L->items[i].hp - YDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'S') { L->items[i].hp = L->items[i].hp - SDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); } ch = (char)mvinch((L->items[i].y), (L->items[i].x - 1)); if(ch == 'B') { L->items[i].hp = L->items[i].hp - BDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'Y') { L->items[i].hp = L->items[i].hp - YDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'S') { L->items[i].hp = L->items[i].hp - SDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); } ch = (char)mvinch((L->items[i].y + 1), (L->items[i].x - 1)); if(ch == 'B') { L->items[i].hp = L->items[i].hp - BDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'Y') { L->items[i].hp = L->items[i].hp - YDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'S') { L->items[i].hp = L->items[i].hp - SDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); } ch = (char)mvinch((L->items[i].y - 1), (L->items[i].x + 1)); if(ch == 'B') { L->items[i].hp = L->items[i].hp - BDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'Y') { L->items[i].hp = L->items[i].hp - YDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'S') { L->items[i].hp = L->items[i].hp - SDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); } ch = (char)mvinch((L->items[i].y), (L->items[i].x + 1)); if(ch == 'B') { L->items[i].hp = L->items[i].hp - BDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'Y') { L->items[i].hp = L->items[i].hp - YDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'S') { L->items[i].hp = L->items[i].hp - SDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); } ch = (char)mvinch((L->items[i].y + 1), (L->items[i].x + 1)); if(ch == 'B') { L->items[i].hp = L->items[i].hp - BDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'Y') { L->items[i].hp = L->items[i].hp - YDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); }else if(ch == 'S') { L->items[i].hp = L->items[i].hp - SDAM; attron(COLOR_PAIR(1)); mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar); attroff(COLOR_PAIR(1)); } } /*remove the unit from the map and the list if it has no hp left*/ if(L->items[i].hp <= 0) { mvaddch(L->items[i].y, L->items[i].x, '+'); Remove(i, L); *cnt = *cnt - 1; } refresh(); if(*cnt == 0) return 0; return 1; }
static void draw_help(void) { #define HW 46 #define HH 19 int i, y = (rows/2) - (HH/2); int x = (cols/2) - (HW/2); char pad[HW+1]; memset(pad, ' ', sizeof(pad)); pad[sizeof(pad) - 1] = '\0'; attron(A_STANDOUT); for (i = 0; i < HH; i++) mvaddnstr(y + i, x, pad, -1); mvaddch(y - 1, x - 1, ACS_ULCORNER); mvaddch(y + HH, x - 1, ACS_LLCORNER); mvaddch(y - 1, x + HW, ACS_URCORNER); mvaddch(y + HH, x + HW, ACS_LRCORNER); for (i = 0; i < HH; i++) { mvaddch(y + i, x - 1, ACS_VLINE); mvaddch(y + i, x + HW, ACS_VLINE); } for (i = 0; i < HW; i++) { mvaddch(y - 1, x + i, ACS_HLINE); mvaddch(y + HH, x + i, ACS_HLINE); } attron(A_BOLD); mvaddnstr(y- 1, x+15, "QUICK REFERENCE", -1); attron(A_UNDERLINE); mvaddnstr(y+ 0, x+3, "Navigation", -1); attroff(A_BOLD | A_UNDERLINE); mvaddnstr(y+ 1, x+5, "UP Previous interface", -1); mvaddnstr(y+ 2, x+5, "DOWN Next interface", -1); mvaddnstr(y+ 3, x+5, "LEFT Previous node", -1); mvaddnstr(y+ 4, x+5, "RIGHT Next node", -1); mvaddnstr(y+ 5, x+5, "? Toggle quick reference", -1); mvaddnstr(y+ 6, x+5, "q Quit bmon", -1); attron(A_BOLD | A_UNDERLINE); mvaddnstr(y+ 7, x+3, "Display Settings", -1); attroff(A_BOLD | A_UNDERLINE); mvaddnstr(y+ 8, x+5, "g Toggle graphical statistics", -1); mvaddnstr(y+ 9, x+5, "d Toggle detailed statistics", -1); mvaddnstr(y+10, x+5, "c Toggle combined node list", -1); mvaddnstr(y+11, x+5, "l Toggle interface list", -1); mvaddnstr(y+12, x+5, "f (Un)fold sub interfaces", -1); attron(A_BOLD | A_UNDERLINE); mvaddnstr(y+13, x+3, "Measurement Units", -1); attroff(A_BOLD | A_UNDERLINE); mvaddnstr(y+14, x+5, "R Read Interval", -1); mvaddnstr(y+15, x+5, "S Seconds", -1); mvaddnstr(y+16, x+5, "M Minutes", -1); mvaddnstr(y+17, x+5, "H Hours", -1); mvaddnstr(y+18, x+5, "D Days", -1); attroff(A_STANDOUT); }
void play_menu ( uint8_t height , uint8_t width , uint8_t alignWinSize , uint8_t alignWinTotal , uint8_t AI_prof ) { // play game menu int32_t Key; uint8_t row , col; uint8_t selected ( 1 ); while ( true ) { getmaxyx ( stdscr , row , col ); if ( selected < 1 ) selected = 1; if ( selected > 3 ) selected = 3; clear (); attron ( A_BOLD ); mvprintw ( row / 4 , ( col - STR_PLAY_MENU.length () + 1 ) / 2 , STR_PLAY_MENU.c_str () ); mvprintw ( ( row / 2 ) + ( ( selected - 1 ) * 2 ) , 5 * col / 20 , STR_ARROW_RIGHT.c_str () ); mvprintw ( ( row / 2 ) + ( ( selected - 1 ) * 2 ) , 15 * col / 20 , STR_ARROW_LEFT.c_str () ); mvprintw ( 2 , 2 , STR_HELP.c_str () ); attroff ( A_BOLD ); mvprintw ( row / 2 , ( col - STR_1N1.length () + 1 ) / 2 , STR_1N1.c_str () ); mvprintw ( ( row / 2 ) + 2 , ( col - STR_1NAI.length () + 1 ) / 2 , STR_1NAI.c_str () ); mvprintw ( ( row / 2 ) + 4 , ( col - STR_LOAD.length () + 1 ) / 2 , STR_LOAD.c_str () ); refresh(); Key = getch (); if ( Key == KEY_DOWN ) selected += 1; if ( Key == KEY_UP ) selected -= 1; if ( Key == ENTER ) { if ( selected == 1 ) { grid *G = new grid (); play ( G , height , width , alignWinSize , alignWinTotal , false , AI_prof ); } if ( selected == 2 ) { grid *G = new grid (); play ( G, height , width , alignWinSize , alignWinTotal , true , AI_prof ); } if ( selected == 3 ) load_menu (); break; } if ( Key == KEY_V ) { grid *G = new grid (); play ( G , height , width , alignWinSize , alignWinTotal , false , AI_prof ); } if ( Key == KEY_A ) { grid *G = new grid (); play ( G , height , width , alignWinSize , alignWinTotal , true , AI_prof ); } if ( Key == KEY_L ) load_menu (); if ( Key == ESC ) return; } }
void ui ( void ) { // main menu uint8_t selected ( 1 ); uint8_t defaultHeight ( 5 ); uint8_t defaultWidth ( 5 ); uint8_t defaultAlignWinSize ( 5 ); uint8_t defaultAlignWinTotal ( 1 ); uint8_t defaultAI_prof ( 3 ); int32_t Key; uint8_t row , col; while ( true ) { clear (); getmaxyx ( stdscr , row , col ); if ( selected < 1 ) selected = 1; if ( selected > 3 ) selected = 3; attron ( A_BOLD ); mvprintw ( row / 4 , ( col - STR_TITLE_GAME.length () + 1 ) / 2 , STR_TITLE_GAME.c_str () ); mvprintw ( ( row / 2 ) + ( ( selected - 1 ) * 2 ) , 5 * col / 20 , STR_ARROW_RIGHT.c_str () ); mvprintw ( ( row / 2 ) + ( ( selected - 1 ) * 2 ) , 15 * col / 20 , STR_ARROW_LEFT.c_str () ); mvprintw ( 2 , 2 , STR_HELP.c_str () ); attroff ( A_BOLD ); mvprintw ( row / 2 , ( col - STR_PLAY.length () + 1 ) / 2 , STR_PLAY.c_str () ); mvprintw ( ( row / 2 ) + 2 , ( col - STR_OPTIONS.length () + 1 ) / 2 , STR_OPTIONS.c_str () ); mvprintw ( ( row / 2 ) + 4 , ( col - STR_EXIT.length () + 1 ) / 2 , STR_EXIT.c_str () ); refresh(); Key = getch (); if ( Key == KEY_DOWN ) selected += 1; if ( Key == KEY_UP ) selected -= 1; if ( Key == ENTER ) { if ( selected == 1 ) { play_menu ( defaultHeight , defaultWidth , defaultAlignWinSize , defaultAlignWinTotal , defaultAI_prof ); } if ( selected == 2 ) options ( defaultHeight , defaultWidth , defaultAlignWinSize , defaultAlignWinTotal , defaultAI_prof ); if ( selected == 3 ) { if ( warnExit () ) { endwin (); return; } } } if ( Key == KEY_P ) { play_menu ( defaultHeight , defaultWidth , defaultAlignWinSize , defaultAlignWinTotal , defaultAI_prof ); } if ( Key == KEY_O ) options ( defaultHeight , defaultWidth , defaultAlignWinSize , defaultAlignWinTotal , defaultAI_prof ); if ( Key == ESC || Key == KEY_E ) { if ( warnExit () ) { endwin (); return; } } if ( Key == KEY_F ( 5 ) ) ui_help (); } }
void play ( grid *G , uint8_t height , uint8_t width , uint8_t alignWinSize , uint8_t alignWinTotal , bool vsAI , uint8_t AI_prof ) { // play menu if ( !grid::initXO ) { // if no game is loaded, create new one G = new grid ( height , width , alignWinSize , alignWinTotal , vsAI , AI_prof ); } uint8_t win; int32_t Key; uint8_t row , col; while ( true ) { clear (); getmaxyx ( stdscr , row , col ); attron ( A_BOLD ); mvprintw ( 2 , 2 , STR_SAVE.c_str () ); // beginning of P1 turn, ask if wants to save mvprintw ( 2 , 5 + STR_SAVE.length () , STR_SAVE_QUIT.c_str() ); // or save & quit attroff ( A_BOLD ); mvprintw ( row / 3 , ( col - STR_P1.length () + 1 ) / 2 , STR_P1.c_str () ); mvprintw ( 2 * row / 3 , ( col - STR_CONTINUE.length () + 1 ) / 2 , STR_CONTINUE.c_str () ); refresh (); Key = getch (); if ( Key == ESC || Key == KEY_E ) break; if ( Key == KEY_F ( 6 ) ) G->save (); if ( Key == KEY_F ( 7 ) ) { G->save (); break; } G->play ( 1 ); G->gravitate ( false ); win = G->checkWin (); clear (); if ( win == 1 ) { mvprintw ( row / 2 , ( col - STR_WIN_P1.length () + 1 ) / 2 , STR_WIN_P1.c_str () ); refresh (); wait ( 2000 ); break; } if ( win == 2 ) { mvprintw ( row / 2 , ( col - STR_WIN_P2.length () + 1 ) / 2 , STR_WIN_P2.c_str () ); refresh (); wait ( 2000 ); break; } if ( win == 3 ) { // in case of rotation, possibility of tie mvprintw ( row / 2 , ( col - STR_DRAW.length () + 1 ) / 2 , STR_DRAW.c_str () ); refresh (); wait ( 2000 ); break; } if ( !G->AI ) { mvprintw ( row / 3 , ( col - STR_P2.length () + 1 ) / 2 , STR_P2.c_str () ); mvprintw ( 2 * row / 3 , ( col - STR_CONTINUE.length () + 1 ) / 2 , STR_CONTINUE.c_str () ); refresh (); Key = getch (); if ( Key == ESC || Key == KEY_E ) break; G->play ( 0 ); } else G->AI_play(); G->gravitate ( false ); win = G->checkWin (); clear (); if ( win == 1 ) { mvprintw ( row / 2 , ( col - STR_WIN_P1.length () + 1 ) / 2 , STR_WIN_P1.c_str () ); refresh (); wait ( 2000 ); break; } if ( win == 2 ) { mvprintw ( row / 2 , ( col - STR_WIN_P2.length () + 1 ) / 2 , STR_WIN_P2.c_str () ); refresh (); wait ( 2000 ); break; } if ( win == 3 || G->full() ) { mvprintw ( row / 2 , ( col - STR_DRAW.length () + 1 ) / 2 , STR_DRAW.c_str () ); refresh (); wait ( 2000 ); break; } } }
void load_menu () { // load game menu int32_t Key; uint8_t i; uint8_t row , col; uint16_t top ( 0 ); uint8_t selected ( 1 ); std::string currentID; std::list<std::string> listID; std::list<std::string>::reverse_iterator it; std::vector<std::string> vectorID; std::ifstream input ( "saves/index.sav" ); if ( !input ) { getmaxyx ( stdscr , row , col ); clear (); mvprintw ( row / 2 , ( col - STR_NO_SAVE.length () + 1 ) / 2 , STR_NO_SAVE.c_str() ); refresh (); wait ( 2000 ); return; } std::string buff; while ( !input.eof() ) { input >> buff; if ( buff != "" ) listID.push_back(buff); } if ( listID.empty () ) { getmaxyx ( stdscr , row , col ); clear (); mvprintw ( row / 2 , ( col - STR_SAVE_EMPTY.length () + 1 ) / 2 , STR_SAVE_EMPTY.c_str () ); refresh (); wait ( 2000 ); return; } while ( true ) { i = 0; if ( !vectorID.empty() ) vectorID.clear(); if ( selected < 1 ) { if ( top > 0 ) top--; selected = 1; } if ( selected > 10 ) { if ( top < listID.size() ) top++; selected = 10; } for ( it = listID.rbegin() ; it != listID.rend() ; ++it ) { currentID = (*it); if ( i > top + 10 ) break; if ( i >= top ) { if ( std::find ( vectorID.rbegin () , vectorID.rend () , currentID ) == vectorID.rend () ) vectorID.push_back( currentID ); } ++i; } if ( selected > vectorID.size() ) { selected = vectorID.size(); } getmaxyx ( stdscr , row , col ); clear (); attron ( A_BOLD ); mvprintw ( row / 5 , ( col - STR_LOAD_MENU.length () + 1 ) / 2 , STR_LOAD_MENU.c_str () ); mvprintw ( ( row / 3 ) + selected*2 - 2 , 5 * col / 20 , STR_ARROW_RIGHT.c_str () ); mvprintw ( ( row / 3 ) + selected*2 - 2 , 15 * col / 20 , STR_ARROW_LEFT.c_str () ); mvprintw ( 2 , 2 , STR_HELP.c_str () ); attroff ( A_BOLD ); for ( i = 0 ; i < vectorID.size () ; ++i ) { mvprintw ( ( row / 3 ) + ( i * 2 ) , ( col - 13 ) / 2 , vectorID[i].c_str() ); } uint8_t current = selected - 1; currentID = vectorID[current]; refresh (); Key = getch (); if ( Key == ENTER ) { grid *G = new grid ( currentID.c_str() ); if ( grid::initXO ) { play ( G , 5 , 5 , 5 , 1 , G->AI , G->getAI_prof() ); return; } } if ( Key == KEY_DOWN ) selected++; if ( Key == KEY_UP ) selected--; if ( Key == ESC ) return; } return; }
bool warnExit ( void ) { // exit warning menu uint8_t selected ( 1 ); std::string STR_SELECTED; uint8_t TAB; int32_t Key; uint8_t row , col; while ( true ) { if ( selected < 1 ) selected = 1; if ( selected > 2 ) selected = 2; switch ( selected ) { case 1: STR_SELECTED = STR_WARN_YES; TAB = 1; break; case 2: STR_SELECTED = STR_WARN_NO; TAB = 2; break; } getmaxyx ( stdscr , row , col ); // get number of rows and columns in terminal clear (); // clears screen attron ( A_BOLD ); // enable bold style mvprintw ( row / 3 , ( col - STR_WARN_EXIT.length () + 1 ) / 2 , STR_WARN_EXIT.c_str () ); // prints text on desired position mvprintw ( 2 * row / 3 , ( TAB * col / 3 ) - STR_SELECTED.length () - 2 , STR_ARROW_RIGHT.c_str () ); mvprintw ( 2 * row / 3 , ( TAB * col / 3 ) + STR_SELECTED.length () , STR_ARROW_LEFT.c_str () ); attroff ( A_BOLD ); // disable bold style mvprintw ( 2 * row / 3 , ( col / 3 ) - ( STR_WARN_YES.length () / 2 ) , STR_WARN_YES.c_str () ); mvprintw ( 2 * row / 3 , ( 2 * col / 3 ) - ( STR_WARN_NO.length () / 2 ) , STR_WARN_NO.c_str () ); refresh (); // prints the text placed with mvprintw on screen Key = getch (); if ( Key == KEY_RIGHT ) selected++; if ( Key == KEY_LEFT ) selected--; if ( Key == ENTER ) { if ( selected == 1 ) return true; if ( selected == 2 ) return false; } if ( Key == KEY_Y ) return true; if ( Key == KEY_N || Key == ESC ) return false; } }
int useradd() { noecho(); keypad(stdscr, TRUE); while(1) { DrawAddUserScreen(); AddUserKey = getch(); switch(AddUserKey) { /* Help */ case KEY_F(1): break; /* Reset Fields */ case KEY_F(2): sprintf(ui.username, "_"); sprintf(ui.gecos, "_"); sprintf(ui.user_id, "_"); sprintf(ui.group_id, "_"); sprintf(ui.shell, "_"); sprintf(ui.homedir, "_"); break; /* Username */ case KEY_F(3): echo(); attron(A_REVERSE); mvprintw(8,35, "[_______________________]"); mvwgetnstr(stdscr, 8,36, userinfobuf, 15); strcpy(ui.username, userinfobuf); attroff(A_REVERSE); noecho(); unamefield = 1; break; /* User Comment/Gecos */ case KEY_F(4): echo(); attron(A_REVERSE); mvprintw(9,35, "[_______________________]"); mvwgetnstr(stdscr, 9,36, userinfobuf, 20); strcpy(ui.gecos, userinfobuf); attroff(A_REVERSE); noecho(); break; /* User ID*/ case KEY_F(5): echo(); attron(A_REVERSE); mvprintw(10,35, "[_______________________]"); mvwgetnstr(stdscr, 10,36, userinfobuf, 20); strcpy(ui.user_id, userinfobuf); attroff(A_REVERSE); noecho(); uidfield = 1; break; /* Group ID*/ case KEY_F(6): echo(); attron(A_REVERSE); mvprintw(11,35, "[_______________________]"); mvwgetnstr(stdscr, 11,36, userinfobuf, 20); strcpy(ui.group_id, userinfobuf); attroff(A_REVERSE); noecho(); gidfield = 1; break; /* Login Shell */ case KEY_F(7): echo(); attron(A_REVERSE); mvprintw(12,35, "[_______________________]"); mvwgetnstr(stdscr, 12,36, userinfobuf, 23); strcpy(ui.shell, userinfobuf); attroff(A_REVERSE); noecho(); break; /* Home Dir */ case KEY_F(8): echo(); attron(A_REVERSE); mvprintw(13,35, "[_______________________]"); mvwgetnstr(stdscr, 13,36, userinfobuf, 23); strcpy(ui.homedir, userinfobuf); attroff(A_REVERSE); noecho(); break; case KEY_F(9): execute_default_shell(); break; /* Quit */ case KEY_F(10): return 0; break; /* Commence Add */ case KEY_F(11): add_user(); break; }; }; return 0; }
void CBoard::show(void) const { int row = 0; int col = 0; mvprintw(row++, col, "/=====================================\\"); mvprintw(row++, col, "| a b c d e f g h i j k l m n o |"); mvprintw(row++, col, "| _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |\\=================\\"); mvprintw(row++, col, "|00 |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| 00| |"); mvprintw(row++, col, "|01 |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| 01| Controls: |"); mvprintw(row++, col, "|02 |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| 02| |"); mvprintw(row++, col, "|03 |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| 03| w or ' ' = write |"); mvprintw(row++, col, "|04 |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| 04| q = surrender |"); mvprintw(row++, col, "|05 |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| 05| arrows = move |"); mvprintw(row++, col, "|06 |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| 06| |"); mvprintw(row++, col, "|07 |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| 07|/=================/"); mvprintw(row++, col, "|08 |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| 08|"); mvprintw(row++, col, "|09 |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| 09|"); mvprintw(row++, col, "|10 |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| 10|"); mvprintw(row++, col, "|11 |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| 11|"); mvprintw(row++, col, "|12 |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| 12|"); mvprintw(row++, col, "|13 |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| 13|"); mvprintw(row++, col, "|14 |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| 14|"); mvprintw(row++, col, "| a b c d e f g h i j k l m n o |"); mvprintw(row++, col, "| 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 |"); mvprintw(row++, col, "| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 |"); mvprintw(row++, col, "\\=====================================/"); mvprintw(row++, col + 1, "\\=[ ]=/"); mvprintw(row++, col + 2, "\\=================================/"); for (int i = 0; i < BOARD_WIDTH; i++) { for (int j = 0; j < BOARD_HEIGHT; j++) { if (m_Stones[i][j] == CGame::PLAYER_0_CHAR) { if (m_LastStone.m_X == i && m_LastStone.m_Y == j) { attron(COLOR_PAIR(4)); mvprintw(CURSOR_MIN + i, CURSOR_START + j * 2, "%c", CGame::PLAYER_0_CHAR_BIG); attroff(COLOR_PAIR(4)); } else { attron(COLOR_PAIR(2)); mvprintw(CURSOR_MIN + i, CURSOR_START + j * 2, "%c", m_Stones[i][j]); attroff(COLOR_PAIR(2)); } } else if (m_Stones[i][j] == CGame::PLAYER_1_CHAR) { if (m_LastStone.m_X == i && m_LastStone.m_Y == j) { attron(COLOR_PAIR(5)); mvprintw(CURSOR_MIN + i, CURSOR_START + j * 2, "%c", CGame::PLAYER_1_CHAR_BIG); attroff(COLOR_PAIR(5)); } else { attron(COLOR_PAIR(3)); mvprintw(CURSOR_MIN + i, CURSOR_START + j * 2, "%c", m_Stones[i][j]); attroff(COLOR_PAIR(3)); } } } } mvprintw(22, 4, "%s", m_Message); move(m_Cursor.m_Y, m_Cursor.m_Y * 2 - 1); }
static void color_edit(void) /* display the color test pattern, without trying to edit colors */ { int i, c, value = 0, current = 0, field = 0, usebase = 0; refresh(); for (i = 0; i < COLORS; i++) init_pair(i, COLOR_WHITE, i); do { short red, green, blue; attron(A_BOLD); mvaddstr(0, 20, "Color RGB Value Editing"); attroff(A_BOLD); for (i = 0; i < COLORS; i++) { mvprintw(2 + i, 0, "%c %-8s:", (i == current ? '>' : ' '), (i < sizeof(colors)/sizeof(colors[0]) ? colors[i] : "")); attrset(COLOR_PAIR(i)); addstr(" "); attrset(A_NORMAL); /* * Note: this refresh should *not* be necessary! It works around * a bug in attribute handling that apparently causes the A_NORMAL * attribute sets to interfere with the actual emission of the * color setting somehow. This needs to be fixed. */ refresh(); color_content(i, &red, &green, &blue); addstr(" R = "); if (current == i && field == 0) attron(A_STANDOUT); printw("%04d", red); if (current == i && field == 0) attrset(A_NORMAL); addstr(", G = "); if (current == i && field == 1) attron(A_STANDOUT); printw("%04d", green); if (current == i && field == 1) attrset(A_NORMAL); addstr(", B = "); if (current == i && field == 2) attron(A_STANDOUT); printw("%04d", blue); if (current == i && field == 2) attrset(A_NORMAL); attrset(A_NORMAL); addstr(")"); } mvaddstr(COLORS + 3, 0, "Use up/down to select a color, left/right to change fields."); mvaddstr(COLORS + 4, 0, "Modify field by typing nnn=, nnn-, or nnn+. ? for help."); move(2 + current, 0); switch (c = getch()) { case KEY_UP: current = (current == 0 ? (COLORS - 1) : current - 1); value = 0; break; case KEY_DOWN: current = (current == (COLORS - 1) ? 0 : current + 1); value = 0; break; case KEY_RIGHT: field = (field == 2 ? 0 : field + 1); value = 0; break; case KEY_LEFT: field = (field == 0 ? 2 : field - 1); value = 0; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': do { value = value * 10 + (c - '0'); c = getch(); } while (isdigit(c)); if (c != '+' && c != '-' && c != '=') beep(); else ungetch(c); break; case '+': usebase = 1; goto changeit; case '-': value = -value; usebase = 1; goto changeit; case '=': usebase = 0; changeit: color_content(current, &red, &green, &blue); if (field == 0) red = red * usebase + value; else if (field == 1) green = green * usebase + value; else if (field == 2) blue = blue * usebase + value; init_color(current, red, green, blue); break; case '?': erase(); P(" RGB Value Editing Help"); P(""); P("You are in the RGB value editor. Use the arrow keys to select one of"); P("the fields in one of the RGB triples of the current colors; the one"); P("currently selected will be reverse-video highlighted."); P(""); P("To change a field, enter the digits of the new value; they won't be"); P("echoed. Finish by typing `='; the change will take effect instantly."); P("To increment or decrement a value, use the same procedure, but finish"); P("with a `+' or `-'."); P(""); P("To quit, do `x' or 'q'"); move(LINES - 1, 0); addstr("Press any key to continue... "); (void) getch(); erase(); break; case 'x': case 'q': break; default: beep(); break; } } while (c != 'x' && c != 'q'); erase(); endwin(); }
void options ( uint8_t &defaultHeight , uint8_t &defaultWidth , uint8_t &defaultAlignWinSize , uint8_t &defaultAlignWinTotal , uint8_t &defaultAI_prof ) { // options menu uint8_t selected ( 1 ); uint8_t i; uint8_t row , col; uint8_t backupHeight ( defaultHeight ); uint8_t backupWidth ( defaultWidth ); uint8_t backupAlignWinSize ( defaultAlignWinSize ); uint8_t backupAlignWinTotal ( defaultAlignWinTotal ); uint8_t backupAI_prof ( defaultAI_prof ); int32_t Key; std::string STR_SELECTED; while ( true ) { getmaxyx ( stdscr , row , col ); if ( selected < 1 ) selected = 1; if ( selected > 5 ) selected = 5; if ( defaultHeight < 3 ) defaultHeight = 3; if ( defaultHeight > 20 ) defaultHeight = 20; if ( defaultWidth < 3 ) defaultWidth = 3; if ( defaultWidth > 20 ) defaultWidth = 20; if ( defaultAlignWinSize > defaultWidth ) defaultAlignWinSize = defaultWidth; if ( defaultAlignWinSize > defaultHeight ) defaultAlignWinSize = defaultHeight; if ( defaultAlignWinSize < 3 ) defaultAlignWinSize = 3; if ( defaultAlignWinTotal < 1 ) defaultAlignWinTotal = 1; if ( defaultAlignWinTotal > 10 ) defaultAlignWinTotal = 10; if ( defaultAI_prof < 3 ) defaultAI_prof = 9; if ( defaultAI_prof > 9 ) defaultAI_prof = 3; switch ( selected ) { case 1: STR_SELECTED = STR_HEIGHT; break; case 2: STR_SELECTED = STR_WIDTH; break; case 3: STR_SELECTED = STR_ALIGN_SIZE; break; case 4: STR_SELECTED = STR_ALIGN_TOTAL; break; case 5: STR_SELECTED = STR_AI_PROF; break; } clear (); attron ( A_BOLD ); mvprintw ( row / 4 , ( col - STR_TITLE_OPTIONS.length () + 1 ) / 2 , STR_TITLE_OPTIONS.c_str () ); mvprintw ( ( row / 2 ) + ( ( selected - 1 ) * 2 ) , col / 20 , STR_ARROW_RIGHT.c_str () ); mvprintw ( ( row / 2 ) + ( ( selected - 1 ) * 2 ) , 19 * col / 20 , STR_ARROW_LEFT.c_str () ); mvprintw ( 2 , 2 , STR_HELP.c_str () ); attroff ( A_BOLD ); mvprintw ( ( row / 2 ) , ( col - STR_HEIGHT.length() + 1 ) / 3 , STR_HEIGHT.c_str() ); mvprintw ( ( row / 2 ) + 2 , ( col - STR_WIDTH.length() + 1 ) / 3 , STR_WIDTH.c_str() ); mvprintw ( ( row / 2 ) + 4 , ( col - STR_ALIGN_SIZE.length() + 1 ) / 3 , STR_ALIGN_SIZE.c_str() ); mvprintw ( ( row / 2 ) + 6 , ( col - STR_ALIGN_TOTAL.length() + 1 ) / 3 , STR_ALIGN_TOTAL.c_str() ); mvprintw ( ( row / 2 ) + 8 , ( col - STR_AI_PROF.length () + 1 ) / 3 , STR_AI_PROF.c_str () ); mvprintw ( ( row / 2 ) , ( col / 2 ) , "%d" , defaultHeight ); mvprintw ( ( row / 2 ) , ( col / 2 ) + ( col / 20 ) , "[" ); for ( i = 0 ; i < defaultHeight ; ++i ) printw ( "-" ); for ( i = 20 ; i > defaultHeight ; --i ) printw ( " " ); printw ( "]" ); mvprintw ( ( row / 2 ) + 2 , ( col / 2 ) , "%d" , defaultWidth ); mvprintw ( ( row / 2 ) + 2 , ( col / 2 ) + ( col / 20 ) , "[" ); for ( i = 0 ; i < defaultWidth ; ++i ) printw ( "-" ); for ( i = 20 ; i > defaultWidth ; --i ) printw ( " " ); printw ( "]" ); mvprintw ( ( row / 2 ) + 4 , ( col / 2 ) , "%d" , defaultAlignWinSize ); mvprintw ( ( row / 2 ) + 4 , ( col / 2 ) + ( col / 20 ) , "[" ); for ( i = 0 ; i < defaultAlignWinSize ; ++i ) printw ( "-" ); for ( i = 20 ; i > defaultAlignWinSize ; --i ) printw ( " " ); printw ( "]" ); mvprintw ( ( row / 2 ) + 6 , ( col / 2 ) , "%d" , defaultAlignWinTotal ); mvprintw ( ( row / 2 ) + 6 , ( col / 2 ) + ( col / 20 ) , "[" ); for ( i = 0 ; i < defaultAlignWinTotal ; ++i ) printw ( "--" ); for ( i = 10 ; i > defaultAlignWinTotal ; --i ) printw ( " " ); printw ( "]" ); switch ( defaultAI_prof ) { case 3: mvprintw ( ( row / 2 ) + 8 , ( col / 2 ) + ( col / 20 ) + 9 , "EASY" ); break; case 6: mvprintw ( ( row / 2 ) + 8 , ( col / 2 ) + ( col / 20 ) + 8 , "MEDIUM" ); break; case 9: mvprintw ( ( row / 2 ) + 8 , ( col / 2 ) + ( col / 20 ) + 9 , "HARD" ); break; } mvprintw ( row - 2 , ( col - STR_OK.length () + 1 ) / 4 , STR_OK.c_str () ); mvprintw ( row - 2 , 3 * ( col - STR_CANCEL.length () + 1 ) / 4 , STR_CANCEL.c_str () ); refresh (); Key = getch (); if ( Key == KEY_LEFT ) { switch ( selected ) { case 1: defaultHeight--; break; case 2: defaultWidth--; break; case 3: defaultAlignWinSize--; break; case 4: defaultAlignWinTotal--; break; case 5: defaultAI_prof -= 3; break; } } if ( Key == KEY_RIGHT ) { switch ( selected ) { case 1: defaultHeight++; break; case 2: defaultWidth++; break; case 3: defaultAlignWinSize++; break; case 4: defaultAlignWinTotal++; break; case 5: defaultAI_prof += 3; break; } } if ( Key == KEY_DOWN ) selected++; if ( Key == KEY_UP ) selected--; if ( Key == ENTER || Key == KEY_O ) break; if ( Key == ESC || Key == KEY_C ) { defaultHeight = backupHeight; defaultWidth = backupWidth; defaultAlignWinSize = backupAlignWinSize; defaultAlignWinTotal = backupAlignWinTotal; defaultAI_prof = backupAI_prof; break; } if ( Key == KEY_F ( 5 ) ) options_help (); } }
static void slk_test(void) /* exercise the soft keys */ { int c, fmt = 1; char buf[9]; c = CTRL('l'); do { switch(c) { case CTRL('l'): erase(); attron(A_BOLD); mvaddstr(0, 20, "Soft Key Exerciser"); attroff(A_BOLD); move(2, 0); P("Available commands are:"); P(""); P("^L -- refresh screen"); P("a -- activate or restore soft keys"); P("d -- disable soft keys"); P("c -- set centered format for labels"); P("l -- set left-justified format for labels"); P("r -- set right-justified format for labels"); P("[12345678] -- set label; labels are numbered 1 through 8"); P("e -- erase stdscr (should not erase labels)"); P("s -- test scrolling of shortened screen"); P("x, q -- return to main menu"); P(""); P("Note: if activating the soft keys causes your terminal to"); P("scroll up one line, your terminal auto-scrolls when anything"); P("is written to the last screen position. The ncurses code"); P("does not yet handle this gracefully."); refresh(); /* fall through */ case 'a': slk_restore(); break; case 'e': wclear(stdscr); break; case 's': move(20, 0); while ((c = getch()) != 'Q') addch(c); break; case 'd': slk_clear(); break; case 'l': fmt = 0; break; case 'c': fmt = 1; break; case 'r': fmt = 2; break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': (void) mvaddstr(20, 0, "Please enter the label value: "); wgetnstr(stdscr, buf, 8); slk_set((c - '0'), buf, fmt); slk_refresh(); break; case 'x': case 'q': goto done; default: beep(); } } while ((c = getch()) != EOF); done: erase(); endwin(); }
/* Print a string with the given attributes set. */ static void attr_addstr(int attr, const char *str) { attron(attr); addstr(str); attroff(attr); }
Status db_login(MYSQL *conn_ptr){ char user[50]="", password[50]="", password_verify[100]=""; // start_color(); // init_color(COLOR_BLACK, 0, 0, 0); // init_pair(1, COLOR_GREEN, COLOR_BLACK); printw("mysql user:\t"); scanw("%s",user); printw("mysql password:\t"); noecho(); scanw("%s",password); echo(); printw("\n"); refresh(); conn_ptr=mysql_init(NULL); conn_ptr = mysql_real_connect(conn_ptr, "localhost", user, password, NULL, 0, NULL, 0); char input_ch; if(conn_ptr){ attron(A_BOLD); printw("[ info @%s] Connect successfully!\n",user); attroff(A_BOLD); refresh(); }else{ attron(A_BOLD); printw("[ info @%s] F****d~\n",user); attroff(A_BOLD); refresh(); return Status_Forbidden; } if(mysql_query(conn_ptr, "use HNotes")){ printw("[ query @%s] Create database? [Y/n] : ",user);refresh(); scanw("%c",&input_ch); if(input_ch=='Y' || input_ch=='y' ){ if(!mysql_query(conn_ptr, "create DATABASE HNotes;")){ //mysql_query(conn_ptr, "create table ;") printw("["); attron(COLOR_PAIR(1)); attron(A_BOLD); printw(" OK"); attroff(COLOR_PAIR(1)); attroff(A_BOLD); printw(" @%s] Create database already.\n",user); mysql_query(conn_ptr, "use HNotes"); printw("[ info @%s] Enter database already.\n ",user); } } if(input_ch=='N' || input_ch=='n' ){ printw("["); attron(COLOR_PAIR(2)); attron(A_BOLD); printw(" NO"); attroff(COLOR_PAIR(2)); attroff(A_BOLD); printw(" @%s] Refuse to create database.\n",user); } refresh(); }else{ attron(A_BOLD); printw("[ info @%s] Enter database already.\n ",user); attroff(A_BOLD); } refresh(); //ShowQueryResult_Select(conn_ptr,"show databases;"); mysql_query(conn_ptr,"use HNotes;"); ShowQueryResult_Select(stdscr,conn_ptr,"select * from demo1;"); return Status_OK; }
void showPorts(void) { int i,j; int x=XINIT, y=YINIT; attron(COLOR_PAIR(1)); mvprintw(17,10,"Salir:"); attroff(COLOR_PAIR(1)); attron(COLOR_PAIR(2)); mvprintw(17,17,"S"); attroff(COLOR_PAIR(2)); uint8_t *PA = (void*)(&PORTA); uint8_t *PB = (void*)(&PORTB); showFrame(x,y,23,9); showFrame(x+30,y,23,9); showFrame(x,y+9,23,3); showFrame(x+30,y+9,23,3); attron(COLOR_PAIR(WHITEBLACK)); mvprintw(y+1, x+8, "7 6 5 4 3 2 1 0 "); mvprintw(y+3, x+2, " DDRA "); mvprintw(y+5, x+2, "PORTA "); mvprintw(y+7, x+2, " PINA "); mvprintw(y+10, x+2, "Pins "); mvprintw(y+1, x+38, "7 6 5 4 3 2 1 0 "); mvprintw(y+3, x+32, " DDRB "); mvprintw(y+5, x+32, "PORTB "); mvprintw(y+7, x+32, " PINB "); mvprintw(y+10, x+32, "Pins "); for(i=0; i<8; i++) { for(j=0; j<4; j++) { if(j==3) move(y+(j<<1)+4, x+(i<<1)+8); else move(y+(j<<1)+3, x+(i<<1)+8); if( PA[j] & 0x80>>i ) { attron(COLOR_PAIR(REDBLACK)); addch(ACS_CKBOARD); attroff(COLOR_PAIR(REDBLACK)); }else{ attron(COLOR_PAIR(BLUEBLACK)); addch(ACS_CKBOARD); attroff(COLOR_PAIR(BLUEBLACK)); } } for(j=0; j<4; j++) { if(j==3) move(y+(j<<1)+4, x+(i<<1)+38); else move(y+(j<<1)+3, x+(i<<1)+38); if( PB[j] & 0x80>>i ) { attron(COLOR_PAIR(REDBLACK)); addch(ACS_CKBOARD); attroff(COLOR_PAIR(REDBLACK)); }else{ attron(COLOR_PAIR(BLUEBLACK)); addch(ACS_CKBOARD); attroff(COLOR_PAIR(BLUEBLACK)); } }
static void curses_draw(void) { if (NULL == get_current_node()) { first_node(); first_intf(); } row = 0; move(0,0); getmaxyx(stdscr, rows, cols); if (cols < 80) { clear(); putl("Screen must be at least 80 columns wide"); refresh(); return; } if (c_use_colors) attrset(COLOR_PAIR(LAYOUT_STATUSBAR) | layout[LAYOUT_STATUSBAR].attr); else attrset(A_REVERSE); if (get_current_node() && get_current_intf()) { putl(" interface: %s at %s", get_current_intf()->i_name, get_current_node()->n_name); } move(row, COLS - strlen(PACKAGE_STRING) - 1); putl("%s", PACKAGE_STRING); move(row, 0); if (c_use_colors) attrset(COLOR_PAIR(LAYOUT_DEFAULT) | layout[LAYOUT_DEFAULT].attr); else attroff(A_REVERSE); print_content(); if (quit_mode) print_quit(); else if (print_help) draw_help(); for (; row < rows-2;) { move(++row, 0); putl(""); } row = rows-1; move(row, 0); if (c_use_colors) attrset(COLOR_PAIR(LAYOUT_STATUSBAR) | layout[LAYOUT_STATUSBAR].attr); else attrset(A_REVERSE); putl(" ^ prev interface, v next interface, <- prev node, -> next node, ? help"); attrset(0); refresh(); }
void print_menu(Window & win) { int input = 0; int i = 0; while (getch() != ERR); start_color(); init_pair(1,COLOR_BLUE,COLOR_BLACK); init_pair(2,COLOR_GREEN,COLOR_BLACK); init_pair(3,COLOR_GREEN,COLOR_RED); while(input != KEY_ECHAP) { nodelay(stdscr, FALSE); clear(); print_logo(win); attron(COLOR_PAIR(2)); if (i == 0) { attron(COLOR_PAIR(3)); mvprintw(win.getY() / 4 + 9, win.getX() / 2 - (win.getX() / 5), " ______ _______ __"); mvprintw(win.getY() / 4 + 10, win.getX() / 2 - (win.getX() / 5), "| ____| /\\ / ____\\ \\ / /"); mvprintw(win.getY() /4 + 11, win.getX() / 2 - (win.getX() / 5), "| |__ / \\ | (___ \\ \\_/ / "); mvprintw(win.getY() /4 + 12, win.getX() / 2 - (win.getX() / 5), "| __| / /\\ \\ \\___ \\ \\ / "); mvprintw(win.getY() /4 + 13, win.getX() / 2 - (win.getX() / 5), "| |____ / ____ \\ ____) | | | "); mvprintw(win.getY() / 4 + 14, win.getX() / 2 - (win.getX() / 5), "|______/_/ \\_\\_____/ |_| "); attroff(COLOR_PAIR(3)); attron(COLOR_PAIR(2)); } else { mvprintw(win.getY() / 4 + 9, win.getX() / 2 - (win.getX() / 5), " ______ _______ __"); mvprintw(win.getY() / 4 + 10, win.getX() / 2 - (win.getX() / 5), "| ____| /\\ / ____\\ \\ / /"); mvprintw(win.getY() /4 + 11, win.getX() / 2 - (win.getX() / 5), "| |__ / \\ | (___ \\ \\_/ / "); mvprintw(win.getY() /4 + 12, win.getX() / 2 - (win.getX() / 5), "| __| / /\\ \\ \\___ \\ \\ / "); mvprintw(win.getY() /4 + 13, win.getX() / 2 - (win.getX() / 5), "| |____ / ____ \\ ____) | | | "); mvprintw(win.getY() / 4 + 14, win.getX() / 2 - (win.getX() / 5), "|______/_/ \\_\\_____/ |_| "); } if (i == 1) { attron(COLOR_PAIR(3)); mvprintw(win.getY() / 4 + 16, win.getX() / 2 - (win.getX() / 5), " __ __ ______ _____ _____ _ _ __ __ "); mvprintw(win.getY() / 4 + 17, win.getX() / 2 - (win.getX() / 5), "| \\/ | ____| __ \\_ _| | | | \\/ |"); mvprintw(win.getY() / 4 + 18, win.getX() / 2 - (win.getX() / 5), "| \\ / | |__ | | | || | | | | | \\ / |"); mvprintw(win.getY() / 4 + 19, win.getX() / 2 - (win.getX() / 5), "| |\\/| | __| | | | || | | | | | |\\/| |"); mvprintw(win.getY() / 4 + 20, win.getX() / 2 - (win.getX() / 5), "| | | | |____| |__| || |_| |__| | | | |"); mvprintw(win.getY() / 4 + 21, win.getX() / 2 - (win.getX() / 5), "|_| |_|______|_____/_____|\\____/|_| |_|"); attroff(COLOR_PAIR(3)); attron(COLOR_PAIR(2)); } else { mvprintw(win.getY() / 4 + 16, win.getX() / 2 - (win.getX() / 5), " __ __ ______ _____ _____ _ _ __ __ "); mvprintw(win.getY() / 4 + 17, win.getX() / 2 - (win.getX() / 5), "| \\/ | ____| __ \\_ _| | | | \\/ |"); mvprintw(win.getY() / 4 + 18, win.getX() / 2 - (win.getX() / 5), "| \\ / | |__ | | | || | | | | | \\ / |"); mvprintw(win.getY() / 4 + 19, win.getX() / 2 - (win.getX() / 5), "| |\\/| | __| | | | || | | | | | |\\/| |"); mvprintw(win.getY() / 4 + 20, win.getX() / 2 - (win.getX() / 5), "| | | | |____| |__| || |_| |__| | | | |"); mvprintw(win.getY() / 4 + 21, win.getX() / 2 - (win.getX() / 5), "|_| |_|______|_____/_____|\\____/|_| |_|"); } if (i == 2) { attron(COLOR_PAIR(3)); mvprintw(win.getY() / 4 + 23, win.getX() / 2 - (win.getX() / 5), " _ _ _____ _____ "); mvprintw(win.getY() / 4 + 24, win.getX() / 2 - (win.getX() / 5), "| | | | /\\ | __ \\| __ \\ "); mvprintw(win.getY() / 4 + 25, win.getX() / 2 - (win.getX() / 5), "| |__| | / \\ | |__) | | | |"); mvprintw(win.getY() / 4 + 26, win.getX() / 2 - (win.getX() / 5), "| __ | / /\\ \\ | _ /| | | |"); mvprintw(win.getY() / 4 + 27, win.getX() / 2 - (win.getX() / 5), "| | | |/ ____ \\| | \\ \\| |__| |"); mvprintw(win.getY() / 4 + 28, win.getX() / 2 - (win.getX() / 5), "|_| |_/_/ \\_\\_| \\_\\_____/ "); attroff(COLOR_PAIR(3)); attron(COLOR_PAIR(2)); } else { mvprintw(win.getY() / 4 + 23, win.getX() / 2 - (win.getX() / 5), " _ _ _____ _____ "); mvprintw(win.getY() / 4 + 24, win.getX() / 2 - (win.getX() / 5), "| | | | /\\ | __ \\| __ \\ "); mvprintw(win.getY() / 4 + 25, win.getX() / 2 - (win.getX() / 5), "| |__| | / \\ | |__) | | | |"); mvprintw(win.getY() / 4 + 26, win.getX() / 2 - (win.getX() / 5), "| __ | / /\\ \\ | _ /| | | |"); mvprintw(win.getY() / 4 + 27, win.getX() / 2 - (win.getX() / 5), "| | | |/ ____ \\| | \\ \\| |__| |"); mvprintw(win.getY() / 4 + 28, win.getX() / 2 - (win.getX() / 5), "|_| |_/_/ \\_\\_| \\_\\_____/ "); } if (i == 3) { attron(COLOR_PAIR(3)); mvprintw(win.getY() / 4 + 30, win.getX() / 2 - (win.getX() / 5), " ________ _______ _______ "); mvprintw(win.getY() / 4 + 31, win.getX() / 2 - (win.getX() / 5), "| ____\\ \\ / /_ _|__ __|"); mvprintw(win.getY() / 4 + 32, win.getX() / 2 - (win.getX() / 5), "| |__ \\ V / | | | | "); mvprintw(win.getY() / 4 + 33, win.getX() / 2 - (win.getX() / 5), "| __| > < | | | | "); mvprintw(win.getY() / 4 + 34, win.getX() / 2 - (win.getX() / 5), "| |____ / . \\ _| |_ | | "); mvprintw(win.getY() / 4 + 35, win.getX() / 2 - (win.getX() / 5), "|______/_/ \\_\\_____| |_| "); attroff(COLOR_PAIR(3)); attron(COLOR_PAIR(2)); } else { mvprintw(win.getY() / 4 + 30, win.getX() / 2 - (win.getX() / 5), " ________ _______ _______ "); mvprintw(win.getY() / 4 + 31, win.getX() / 2 - (win.getX() / 5), "| ____\\ \\ / /_ _|__ __|"); mvprintw(win.getY() / 4 + 32, win.getX() / 2 - (win.getX() / 5), "| |__ \\ V / | | | | "); mvprintw(win.getY() / 4 + 33, win.getX() / 2 - (win.getX() / 5), "| __| > < | | | | "); mvprintw(win.getY() / 4 + 34, win.getX() / 2 - (win.getX() / 5), "| |____ / . \\ _| |_ | | "); mvprintw(win.getY() / 4 + 35, win.getX() / 2 - (win.getX() / 5), "|______/_/ \\_\\_____| |_| "); } print_score(win); attroff(COLOR_PAIR(2)); input = getch(); if (input == 259) { i--; if (i == -1) i = 3; } else if (input == 258) { i++; if (i == 4) i = 0; } else if (input == 10) { if (i >=0 && i < 3) play(i, win); else return; } refresh(); } }
/* Among other things, 'newtest' demonstrates how to make a Win32a PDCurses app that is a for-real, "pure Windows" version (instead of a console application). Doing this is quite easy, and has certain advantages. If the app is invoked from a command prompt, the only difference you'll see is that the app runs separately (that is, you can continue to use the command prompt, switching between it, your PDCurses/Win32a app, and other processes). Which is the main reason I did it; it meant that I could invoke a PDCurses-based text editor, for example, and still have use of the command line. (NOTE that, for reasons I don't actually understand, this happens when the Visual C++ compiler is used. With MinGW or OpenWatcom, it's still "really" a console app.) To do it, we ensure that the usual main() function has an alternative dummy_main() form, taking the same arguments as main(). We add a WinMain() function, whose sole purpose is to reformulate lpszCmdLine into argc/argv form, and pass it on to dummy_main(). And, of course, we can switch back to a "normal" console app by removing the above #define PURE_WINDOWS_VERSION line. */ #ifdef PURE_WINDOWS_VERSION #undef MOUSE_MOVED #include <windows.h> int dummy_main( int argc, char **argv); int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { char *argv[30]; int i, argc = 1; argv[0] = "newtest"; for( i = 0; lpszCmdLine[i]; i++) if( lpszCmdLine[i] != ' ' && (!i || lpszCmdLine[i - 1] == ' ')) argv[argc++] = lpszCmdLine + i; for( i = 0; lpszCmdLine[i]; i++) if( lpszCmdLine[i] == ' ') lpszCmdLine[i] = '\0'; return dummy_main( argc, (char **)argv); } int dummy_main( int argc, char **argv) #else /* "usual", console-app version: */ int main( int argc, char **argv) #endif { int quit = 0, i, use_slk = 1; int fmt = 0xa; bool blink_state = FALSE; int cursor_state_1 = 2, cursor_state_2 = 3; int show_slk_index_line = 0; int redraw = 1; unsigned extra_character_to_show = 0; #ifdef PDC_WIDE unsigned unicode_offset = 0x80; #endif /* setlocale(LC_ALL, ".utf8"); */ ttytype[0] = 25; ttytype[1] = 90; /* Allow 25 to 90 lines... */ ttytype[2] = 80; ttytype[3] = (char)200; /* ...and 80 to 200 columns */ /* (This program gets weird artifacts when smaller than 25x80.) */ for( i = 1; i < argc; i++) if( argv[i][0] == '-') switch( argv[i][1]) { case 's': use_slk = 0; break; case 'l': setlocale( LC_ALL, argv[i] + 2); break; case 'e': sscanf( argv[i] + 2, "%x", &extra_character_to_show); break; case 'f': sscanf( argv[i] + 2, "%x", (unsigned *)&fmt); break; case 'i': show_slk_index_line = 1; break; case 'r': /* allow user-resizable windows */ { int min_lines, max_lines, min_cols, max_cols; if( sscanf( argv[i] + 2, "%d,%d,%d,%d", &min_lines, &max_lines, &min_cols, &max_cols) == 4) { ttytype[0] = min_lines; ttytype[1] = max_lines; ttytype[2] = min_cols; ttytype[3] = max_cols; } } break; case 'd': /* set window size before initscr */ { int n_lines, n_cols; if( sscanf( argv[i] + 2, "%d,%d", &n_lines, &n_cols) == 2) resize_term( n_lines, n_cols); } break; #ifdef PDC_WIDE case 'u': sscanf( argv[i] + 2, "%x", &unicode_offset); break; #endif default: printf( "Option '%s' unrecognized\n", argv[i]); break; } if( use_slk) slk_init( show_slk_index_line ? 3 : 0); Xinitscr(argc, argv); if( use_slk) slk_setup( show_slk_index_line ? -fmt : fmt); start_color(); # if defined(NCURSES_VERSION) || (defined(PDC_BUILD) && PDC_BUILD > 3000) use_default_colors(); # endif cbreak(); noecho(); clear(); refresh(); #ifdef __PDCURSES__ PDC_set_title( "NewTest: tests various PDCurses features"); #endif keypad( stdscr, TRUE); init_pair( 1, 15, COLOR_BLACK); init_pair( 2, COLOR_BLACK, COLOR_YELLOW); mousemask( ALL_MOUSE_EVENTS, NULL); attrset( COLOR_PAIR( 1)); while( !quit) { char buff[80]; const int xmax = getmaxx( stdscr); const int ymax = getmaxy( stdscr); int color_block_start = 54, c; int color_block_cols = (xmax - color_block_start) / 2; const int color_block_lines = 19; const char *cursor_state_text[N_CURSORS] = { "Invisible (click to change) ", "Underscore (click to change)", "Block (click to change) ", "Outline (click to change) ", "Caret (click to change) ", "Half-block (click to change)", "Central (click to change) ", "Cross (click to change) ", "Heavy box (click to change) " }; if( color_block_cols < 0) color_block_cols = 0; if( redraw) { mvaddstr( 1, COL1, "'Normal' white-on-black"); mvaddstr( 2, COL1, longname( )); #if(CHTYPE_LONG >= 2) /* "non-standard" 64-bit chtypes */ attron( A_DIM); mvaddstr( 15, 41, "Dimmed text"); attroff( A_DIM); #endif #ifdef PDC_WIDE mvaddwstr( 3, COL1, L"'Normal' text, but wide"); #endif attron( A_BLINK); mvaddstr( 6, 40, "Blinking"); attron( A_BOLD); mvaddstr( 8, 40, "BlinkBold"); attron( A_ITALIC); mvaddstr( 0, COL2, "BlinkBoldItalic"); attrset( COLOR_PAIR( 3)); attron( A_UNDERLINE); #ifdef PDC_WIDE mvaddstr( 1, COL2, "Underlined"); addwstr( L"WideUnder"); #endif attrset( COLOR_PAIR( 1)); attron( A_UNDERLINE | A_ITALIC); mvaddstr( 2, COL2, "UnderlinedItalic"); attrset( COLOR_PAIR( 2)); attron( A_BLINK); mvaddstr( 4, COL1, "Black-on-yellow blinking"); attrset( COLOR_PAIR( 1)); move( 4, COL2); text_in_a_box( "Text in a box"); #ifdef CHTYPE_LONG attrset( COLOR_PAIR( 6)); attron( A_STRIKEOUT); mvaddstr( 10, 40, "Strikeout"); attrset( COLOR_PAIR( 1)); #endif #ifdef PDC_WIDE move( 11, 40); text_in_a_box( "Next Ucode pg"); if( unicode_offset) { move( 12, 40); text_in_a_box( "Prev Ucode pg"); } mvprintw( 13, 40, "U+%04x ", unicode_offset); #endif for( i = 0; i < 128; i++) { /* Show extended characters: */ #ifdef PDC_WIDE wchar_t buff[20]; swprintf( buff, 20, L"%02x ", (unsigned)( i + unicode_offset) & 0xff); mvaddwstr( 5 + i % 16, (i / 16) * 5, buff); if( i + unicode_offset > ' ') addch( (chtype)( i + unicode_offset)); else addch( ' '); addch( ' '); #else char buff[6]; sprintf( buff, "%02x %c", i + 128, (char)(i + 128)); mvaddstr( 5 + i % 16, (i / 16) * 5, buff); #endif } #if(CHTYPE_LONG >= 2) /* "non-standard" 64-bit chtypes */ for( i = 0; i < 3 && i + 21 < ymax; i++) { /* Demonstrate full RGB color control: */ int j; const char *output_text[3] = { "Red on green to white on black | (you can get full RGB colors when desired,", "Blue on yellow to black on red | with palette coloring still being available)", "White on red to green on blue, underlined and italic" }; const int len = (int)strlen( output_text[i]); move( 21 + i, 1); for( j = 0; j < len && j + 1 < xmax; j++) { attr_t output_color; const int oval = j * 31 / len; const int reverse = 31 - oval; if( !i) output_color = A_RGB( 31, oval, oval, 0, reverse, 0); else if( i == 1) output_color = A_RGB( 0, 0, reverse, 31, reverse, 0); else { output_color = A_RGB( reverse, 31, reverse, reverse, 0, oval); output_color |= A_UNDERLINE | A_ITALIC; } attrset( output_color); addch( output_text[i][j]); } } #endif /* #if(CHTYPE_LONG >= 2) */ redraw = 0; attrset( COLOR_PAIR( 1)); if( extra_character_to_show && ymax > 23) mvaddch( 23, 63, (chtype)extra_character_to_show); #ifdef PDC_WIDE for( i = 0; i < 6; i++) { static const wchar_t spanish[] = L"Espa\xf1ol"; const int line = 24 + i / 3; const int col = 5 + 25 * (i % 3); static const wchar_t russian[] = {0x0420, 0x0443, 0x0441, 0x0441, 0x043a, 0x0438, 0x0439, L' ', 0x044f, 0x0437, 0x044b, 0x043a, 0}; static const wchar_t greek[] = {0x0395, 0x03bb, 0x03bb, 0x03b7, 0x03bd, 0x03b9, 0x03ba, 0x03ac, 0}; static const wchar_t georgian[] = {0x10e5, 0x10d0, 0x10e0, 0x10d7, 0x10e3, 0x10da, 0x10d8, L' ', 0x10d4, 0x10dc, 0x10d0, 0}; static const wchar_t fullwidth[] = { 0xff26, 0xff55, 0xff4c, 0xff4c, 0xff57, 0xff49, 0xff44, 0xff54, 0xff48, 0 }; /* "Fullwidth" */ static const wchar_t combining_marks[] = { L'C', L'o', 0x35c, L'm', L'b', 0x30a, L'i', L'n', L'i', 0x304, L'n', 0x30b, 0x329, L'g', 0x310, L' ', L'C', 0x338, L'h', 0x306, L'a', 0x361, L'r', L's', 0x30e, 0x348, 0 }; static const wchar_t *texts[6] = { spanish, russian, greek, georgian, fullwidth, combining_marks}; if( line < ymax && col < xmax) mvaddnwstr( line, 5 + 25 * (i % 3), texts[i], xmax - col); } #endif #ifdef MAYBE_TRY_THIS_SOMEWHERE_ELSE mvaddstr( 1, COL3, "Click on cursor descriptions to"); mvaddstr( 2, COL3, "cycle through possible cursors"); mvaddstr( 3, COL3, "Click on colors at left to change"); mvaddstr( 4, COL3, "colors used for under/over/outlining"); mvaddstr( 5, COL3, "Click 'Blink' at bottom to toggle"); mvaddstr( 6, COL3, "'real' blinking vs. 'highlit' blink"); #endif } mvaddnstr( 19, color_block_start, cursor_state_text[cursor_state_1], xmax - color_block_start); mvaddnstr( 20, color_block_start, cursor_state_text[cursor_state_2], xmax - color_block_start); curs_set( (cursor_state_1 << 8) | cursor_state_2); for( i = 0; i < color_block_cols * color_block_lines; i++) { const int n_color_blocks = (COLOR_PAIRS < 256 ? COLOR_PAIRS : 256); attrset( COLOR_PAIR( i >= n_color_blocks ? 2 : i)); if( i > 2 && i < n_color_blocks) init_pair((short)i, (short)i, COLOR_BLACK); if( !(i % color_block_cols)) move( i / color_block_cols, color_block_start); attron( A_REVERSE); addstr( " "); } move( 19, color_block_start - 3); refresh(); c = getch( ); attrset( COLOR_PAIR( 1)); if( c == KEY_RESIZE) { redraw = 1; resize_term( 0, 0); } else if( c == KEY_F(1) || c == 27) quit = 1; else if( c == KEY_F(2)) { blink_state ^= 1; PDC_set_blink( blink_state); } else if( c == KEY_F(3)) /* toggle SLKs */ { use_slk ^= 1; if( use_slk) slk_restore( ); else slk_clear( ); } else if( c >= KEY_F(4) && c < KEY_F(12)) { sscanf( labels[c - KEY_F(1)], "%x", (unsigned *)&fmt); if( use_slk) slk_setup( show_slk_index_line ? -fmt : fmt); } if( c != KEY_MOUSE) { sprintf( buff, "Key %s", keyname( c)); if( !memcmp( buff + 4, "UNKNOWN", 7)) sprintf( buff + 11, " (%x)", c); strcat( buff, " hit "); buff[COL2 - COL1] = '\0'; mvaddstr( 0, COL1, buff); } else { MEVENT mouse_event; #ifdef __PDCURSES__ nc_getmouse( &mouse_event); #else getmouse( &mouse_event); #endif sprintf( buff, "Mouse at %d x %d: %x ", mouse_event.x, mouse_event.y, (unsigned)mouse_event.bstate); mvaddstr( 0, COL1, buff); if( mouse_event.x >= color_block_start && mouse_event.y < color_block_lines) { int new_color = (mouse_event.x - color_block_start) / 2 + mouse_event.y * color_block_cols; if( new_color >= 256) new_color = -1; PDC_set_line_color( (short)new_color); } else if( mouse_event.x >= color_block_start) { int shift = ((mouse_event.bstate & BUTTON_MODIFIER_SHIFT) ? N_CURSORS - 1 : 1); if( mouse_event.y == 19) /* blink/non-blink toggle */ cursor_state_1 = (cursor_state_1 + shift) % N_CURSORS; else if( mouse_event.y == 20) /* cycle cursor state */ cursor_state_2 = (cursor_state_2 + shift) % N_CURSORS; } #ifdef PDC_WIDE else if( mouse_event.x >= 40 && mouse_event.x < 40 + 10) { if( mouse_event.y == 11) { redraw = 1; unicode_offset += 0x80; } else if( mouse_event.y == 12 && unicode_offset) { redraw = 1; unicode_offset -= 0x80; } } #endif } } endwin(); return 0; }
void mostrar_registros(uint32_t* regs, uint32_t* bands) { attron(COLOR_PAIR(1)); int i,j,k; j=0; k=0; for(i=6;i<17;i=i+2){ if((j==5)||(j==9)){ k=k+22; i=6; } move(i, k); /** Mueve el cursor a la posición i,k*/ printw("R%d=",j); refresh(); /** Imprime en la pantalla Sin esto el printw no es mostrado */ if(j==12){ i=100; } j++; } move(6,66); printw("N="); refresh(); move(8,66); printw("Z="); refresh(); move(10,66); printw("C="); refresh(); move(12,66); printw("V="); refresh(); attroff(COLOR_PAIR(1)); /** DEshabilita los colores Pair 1 */ attron(COLOR_PAIR(2)); j=0; k=0; for(i=6;i<17;i=i+2){ if((j==5)||(j==9)){ k=k+22; i=6; } move(i, k+3); /** Mueve el cursor a la posición i,k*/ if(j>9){ move(i, k+4); /** Mueve el cursor a la posición i,k*/ } printw("%x ",regs[j]); refresh(); /** Imprime en la pantalla Sin esto el printw no es mostrado */ if(j==12){ i=100; } j++; } move(6,68); printw("%d",bands[0]); refresh(); move(8, 68); printw("%d",bands[1]); refresh(); move(10, 68); printw("%d",bands[2]); refresh(); move(12, 68); printw("%d",bands[3]); refresh(); attroff(COLOR_PAIR(2)); }
int draw_sibling_menu(select_menu *menu) { int i,c,maxopt,d; char buf[40]; select_menu *it; int cur_index=0; int skip=0; int max_len=0,len; again: wclear(menu_window); /* print title in colour */ attron(COLOR_PAIR(1)); mvprintw(HIGH_NOTICE_Y,max_x/2-20,menu->parent?menu->parent->name:"OpenSIPS Main Configuration Menu"); /* print footer */ print_notice(NOTICE_Y,NOTICE_X,0,"Press h for navigation help."); attroff(COLOR_PAIR(1)); /* draw actual menu */ i=0; for (it=menu;it;it=it->next_sibling) { wmove(menu_window, max_y/4+i++, max_x / 2 - 20); snprintf(buf, sizeof(buf), " %s", it->name); waddstr(menu_window, buf); len = strlen(it->name) +6; if (len > max_len) max_len = len; } /* draw selection marker */ wmove(menu_window, max_y/4+cur_index, (max_x / 2) - 25); waddstr(menu_window, "--->"); /* print box with color */ wattron(menu_window,COLOR_PAIR(2)); for (d=-1;d<i+1;d++) { wmove(menu_window,max_y/4+d,max_x/2-30); wprintw(menu_window,"|"); wmove(menu_window,max_y/4+d,max_x/2-20+max_len); wprintw(menu_window,"|"); } for (d=0;d<max_len+9;d++) { wmove(menu_window,max_y/4-2,max_x/2-29+d); wprintw(menu_window,"_"); wmove(menu_window,max_y/4+i,max_x/2-29+d); wprintw(menu_window,"_"); } wattroff(menu_window,COLOR_PAIR(2)); wmove(menu_window, 0, 0); wrefresh(menu_window); maxopt = i-1; c = getch(); switch (c) { case KEY_UP: if (cur_index > 0) cur_index--; break; case KEY_DOWN: if (cur_index < maxopt) cur_index++; break; case KEY_RIGHT: case KEY_ENTER: case '\n': for (i=0,it=menu;i<cur_index;i++,it=it->next_sibling) ; c = exec_menu_action(it); break; case 'h': case 'H': clear(); print_notice(max_y/2,20,0,"Use UP and DOWN arrow keys to navigate."); print_notice(max_y/2+1,20,0,"Use RIGHT arrow or ENTER key to enter a certain menu."); print_notice(max_y/2+2,20,0,"Use LEFT arror or Q key to go back."); print_notice(max_y/2+3,20,0,"Use SPACE to toggle an entry ON/OFF.\n"); print_notice(max_y/2+4,20,1,"Press any key to return to menuconfig."); refresh(); break; case KEY_LEFT: case 'q': case 'Q': for (it=menu;it;it=it->next_sibling) { if (it->child_changed == CHILD_CHANGED) { if (skip == 0) { /* have we asked before and got negative response ? */ print_notice(NOTICE_Y,NOTICE_X,0,"You have not saved changes. Go back anyway ? [y/n] "); c = getch(); if (c == 'n' || c == 'N') goto again; else { it->child_changed = CHILD_CHANGE_IGNORED; skip=1; return 0; } } else it->child_changed = CHILD_CHANGE_IGNORED; } } if (skip == 1) return 0; return 0; } goto again; }
void Monde::deplacement(int decalageX, int decalageY) { if(getPlayerMap()->getElements(playerActuel->getPosX()+decalageX,playerActuel->getPosY()+decalageY)==' ') { getPlayerMap()->modifierElements(playerActuel->getPosX(),playerActuel->getPosY(),' '); attron(COLOR_PAIR(2)|A_INVIS); mvaddch(playerActuel->getPosX()+decalageX,playerActuel->getPosY()+decalageY,playerActuel->getChar()); attroff(COLOR_PAIR(2)); attron(COLOR_PAIR(3)); mvaddch(playerActuel->getPosX(),playerActuel->getPosY(),' '); playerActuel->setPosYX(playerActuel->getPosY()+decalageY,playerActuel->getPosX()+decalageX); attroff(COLOR_PAIR(3)|A_INVIS); } else if(getPlayerMap()->getElements(playerActuel->getPosX()+decalageX,playerActuel->getPosY()+decalageY)=='A') { clear(); printw("AFFICHE!"); while(tolower(getch())!='e') { } clear(); //afficherMap(); afficherMap2(); attron(COLOR_PAIR(2)); mvaddch(playerActuel->getPosX(),playerActuel->getPosY(),playerActuel->getChar()); attroff(COLOR_PAIR(2)); } else if(getPlayerMap()->getElements(playerActuel->getPosX()+decalageX,playerActuel->getPosY()+decalageY)=='X') { clear(); combat(new Monstre); clear(); //getPlayerMap()->afficherMap(); afficherMap2(); attron(COLOR_PAIR(2)); mvaddch(playerActuel->getPosX(),playerActuel->getPosY(),playerActuel->getChar()); attroff(COLOR_PAIR(2)); } else if(getPlayerMap()->getElements(playerActuel->getPosX()+decalageX,playerActuel->getPosY()+decalageY)=='P') { attron(COLOR_PAIR(2)); mvaddch(playerActuel->getPosX()+decalageX,playerActuel->getPosY()+decalageY,playerActuel->getChar()); attroff(COLOR_PAIR(2)); attron(COLOR_PAIR(3)); mvaddch(playerActuel->getPosX(),playerActuel->getPosY(),' '); playerActuel->setPosYX(playerActuel->getPosY()+decalageY,playerActuel->getPosX()+decalageX); attroff(COLOR_PAIR(3)); } else if(getPlayerMap()->getElements(playerActuel->getPosX()+decalageX,playerActuel->getPosY()+decalageY)=='O') { positionY+=1; insererPlayer(positionX,positionY,39,37); clear(); afficherMap2(); } else if(getPlayerMap()->getElements(playerActuel->getPosX()+decalageX,playerActuel->getPosY()+decalageY)=='B') { positionY-=1; insererPlayer(positionX,positionY,21,39); clear(); afficherMap2(); } }
/** * Funzione di rendering e gestione delle iterazioni tra gli oggetti della scena */ void control_task() { int i; /* System V: inizializzazione */ // Queue id per i messaggi int qid; // Chiave del progetto per individuare la coda dei messaggi key_t msgkey; // Genero la chiave ipc msgkey = ftok(FTOK_PATH, FTOK_PROJ_ID); // Apro (o creo) la coda if((qid = msgget(msgkey, 0666 | IPC_CREAT)) == -1) { perror("Impossibile creare la coda"); exit(1); } /* Inoltre creo una queue per ogni alieno, per trasmettere le comunicazioni * relative alle collisioni */ int qid_coll[ALIEN_NUM]; key_t msgkey_coll[ALIEN_NUM]; // Struttura per memorizzare lo stato delle collisioni ed inviarlo coem messaggio all'alieno collision_msg_t coll_m; coll_m.mtype = 1; /* Genero le chiavi e creo le code */ for(i = 0; i < ALIEN_NUM; i++) { msgkey_coll[i] = ftok(FTOK_PATH, FTOK_PROJ_ID_COLL_BASE + i); // Apro (o creo) la coda if((qid_coll[i] = msgget(msgkey_coll[i], 0666 | IPC_CREAT)) == -1) { perror("Impossibile creare la coda"); exit(1); } } int last_alien_hit = -1;// Id dell'ultimo alieno colpito int obj_n = 1; // Numero di oggetti nella scena int scores = 0; // Punteggio char buffer[512]; // Buffer per stampare le stats unsigned long iterations = 0; // Numero di iterazioni int aliens = ALIEN_NUM; // Buffer di ricezione object_data_t recv_data; // Informazioni degli oggetti; la navicella e' in posizione 0. // L'elemento corrente e' puntato dal puntatore current object_data_t objects[OBJECTS_MAX]; // Oggetto corrente e suo id; spaceship = -1; object_data_t *current; int current_id; // Variabile che indica se il loop deve essere eseguito int playing = 1; // Variabile temporanea per lo stato delle collisioni dell'oggetto corrente int col; // Inizializzo le ncurses initscr(); // Inizializzo i colori delle ncurses #ifdef COLORS start_color(); init_pair(1, COLOR_WHITE, COLOR_BLACK); attron(COLOR_PAIR(1)); #endif // Non visualizzo i tasti premuti noecho(); // Inizializzo il generatore random srand((int)time(0)); // Nascondo il cursore curs_set(0); // Inizializzo la navicella objects[0].type = OT_SPACESHIP; // Inizializzo gli oggetti come non utilizzati for(i = 0; i < OBJECTS_MAX; i++) objects[i].x = -1; // Finche' il gioco non finisce, eseguo do { // Ricevo i dati di un oggetto dalla coda messaggi msgrcv(qid, &recv_data, sizeof(recv_data) - sizeof(recv_data.mtype), 1, 0); // Se non e' la navicella, ricerco nella lista l'oggetto ricevuto current = NULL; if(recv_data.type != OT_SPACESHIP) { for(i = 1; i < OBJECTS_MAX; i++) { if(recv_data.pid == objects[i].pid) { current = &objects[i]; current_id = i; i = OBJECTS_MAX; } } // Non l'ho trovato, cerco uno spazio libero if(current == NULL) { for(i = 1; i < OBJECTS_MAX; i++) if(objects[i].x == -1) { obj_n++; current = &objects[i]; i = OBJECTS_MAX; } } } // Altrimenti la navicella sta' in posizione 0 else { current = &objects[0]; current_id = 0; } // Collision detect int collision_count = 0; // Se l'oggetto corrente ha una posizione inizializzata, faccio // il check delle collisioni if(current->x != -1) { for(i = 0; i < OBJECTS_MAX; i++) { // Un oggetto non collide con se stesso if(current_id == i) continue; // Nella posizione i non c'e' nessun oggetto if(objects[i].x == -1) continue; // Se una bomba colpisce un alieno, me ne frego if(((objects[i].type == OT_BOMB) && (current->type == OT_ALIEN)) || ((objects[i].type == OT_ALIEN) && (current->type == OT_BOMB))) continue; // Se due missili si colpiscono, me ne frego if(((objects[i].type == OT_MISSILE) && (current->type == OT_MISSILE))) continue; // Controllo lo stato delle collisioni tra l'oggetto corrente // e quello in posizione i col = control_check_collision(&objects[i], current); // Se c'e' stata una collisione if(col != 0) { // Imposto il flag collision_count = 1; // Se abilitato, stampo una stringa di debug #ifdef DEBUG char cinfo[1024]; sprintf(cinfo, "Collision: type %d and type %d, x %d and x %d, y %d and y %d", (int) objects[i].type, (int) current->type, objects[i].x, current->x, objects[i].y, current->y); mvaddstr(1, 1, cinfo); #endif // A seconda del tipo di oggetto corrente, faccio un azione diversa // per ogni tipo di collisione switch(current->type) { // Se un missile colpisce un alieno, toglie una vita // o lo ammazza, ed incrementa il punteggio case OT_MISSILE: if(objects[i].type == OT_ALIEN) { if((last_alien_hit == objects[i].pid) && (iterations >= MIN_HIT_DIFF)) { coll_m.coll = 'z'; last_alien_hit = -1; } else { coll_m.coll = 'c'; last_alien_hit = objects[i].pid; } iterations = 0; msgsnd(qid_coll[objects[i].id], &coll_m, sizeof(coll_m) - sizeof(coll_m.mtype), 0); scores += objects[i].size * 10; } // Se una bomba ed un missile collidono, killo la bomba else if(objects[i].type == OT_BOMB) kill(current->pid, SIGQUIT); // E killo il missile in ogni caso kill(current->pid, SIGQUIT); break; // Collisione alieno case OT_ALIEN: // Se due alieni collidono rimbalzano if(objects[i].type == OT_ALIEN) { coll_m.coll = 'r'; // Se collidono e stanno andando entrambi // nella stessa dir, cambio direzione solo ad uno if(objects[i].dir == current->dir) { if(current->x < objects[i].x) msgsnd(qid_coll[current->id], &coll_m, sizeof(coll_m) - sizeof(coll_m.mtype), 0); else msgsnd(qid_coll[objects[i].id], &coll_m, sizeof(coll_m) - sizeof(coll_m.mtype), 0); } else { msgsnd(qid_coll[objects[i].id], &coll_m, sizeof(coll_m) - sizeof(coll_m.mtype), 0); msgsnd(qid_coll[current->id], &coll_m, sizeof(coll_m) - sizeof(coll_m.mtype), 0); } } // Se collide con un missile, invio il messaggio // all'alieno e killo il missile else if(objects[i].type == OT_MISSILE) { if(last_alien_hit == current->pid && iterations >= MIN_HIT_DIFF) { coll_m.coll = 'z'; last_alien_hit = -1; } else { coll_m.coll = 'c'; last_alien_hit = current->pid; } iterations = 0; msgsnd(qid_coll[current->id], &coll_m, sizeof(coll_m) - sizeof(coll_m.mtype), 0); scores += current->size * 10; kill(objects[i].pid, SIGQUIT); } // Se un alieno collide con la navicella, fine gioco else if(objects[i].type == OT_SPACESHIP) { playing = 0; usleep(SLEEP_OVER); } break; // Collisione bomba case OT_BOMB: // Se la bomba collide con la navicella, game over if(objects[i].type == OT_SPACESHIP) { playing = 0; usleep(SLEEP_OVER); } // Se una bomba ed un missile collidono, le killo else if(objects[i].type == OT_MISSILE) { kill(objects[i].pid, SIGQUIT); kill(current->pid, SIGQUIT); } break; // Collisione navicella case OT_SPACESHIP: // Se la navicella collide con un missile o con una bomba, fine gioco if((objects[i].type == OT_BOMB) || (objects[i].type == OT_ALIEN)) { playing = 0; usleep(SLEEP_OVER); } break; } // Aggiorno lo schermo refresh(); } } } // Qualsiasi oggetto sia, cancello prima di tutto la sua vecchia // porzione di schermo, ed inserisco nell'array degli oggetti i // dati appena ricevuti if(current->x != -1) clear_quad(current->x, current->y, current->size); *current = recv_data; // A seconda del tipo di oggetto, eseguo un operazione differente switch(recv_data.type) { // Astronave aliena case OT_ALIEN: // Se la vita di un alieno e' negativa, vuol dire che deve morire; // deve comunque inviare la struttura inizializzando come tipo // OT_DELETE if(current->life == -1) { aliens--; continue; } // A seconda del livello, disegno l'alieno in modo diverso switch(current->size) { case ALIEN_DATA1_SIZE: render_string_array(current->x, current->y, ALIEN_DATA1, ALIEN_DATA1_SIZE); break; case ALIEN_DATA2_SIZE: render_string_array(current->x, current->y, ALIEN_DATA2, ALIEN_DATA2_SIZE); break; case ALIEN_DATA3_SIZE: render_string_array(current->x, current->y, ALIEN_DATA3, ALIEN_DATA3_SIZE); break; } // Il nemico e' sceso troppo in basso, game over if(current->y > (SCREEN_HEIGHT - ALIEN_DATA2_SIZE)) { playing = 0; usleep(SLEEP_OVER); } break; // Navicella case OT_SPACESHIP: render_string_array(current->x, current->y, SPACE_SHIP_DATA, SPACE_SHIP_SIZE); break; // Bomba aliena case OT_BOMB: mvaddch(current->y, current->x, BOMB_DATA); break; // Missile dell'astronave case OT_MISSILE: mvaddch(current->y, current->x, MISSILE_DATA); break; // Un oggetto sta' morendo e vuole esser cancellato dall'array case OT_DELETE: // Invalido la sua entry nell'array current->x = -1; // Decremento il numero di oggetti della scena obj_n--; // Attendo che muoia (per non aver zombie) waitpid(current->pid); break; }; // Cancello la riga del punteggio mvaddstr(0, 0, "\t\t\t\t\t\t\t\t\t\t"); // Visualizzo il punteggio attuale sprintf(buffer, "Scores: %d", scores); mvaddstr(0, 1, buffer); // Visualizzo il numero di oggetti della scena sprintf(buffer, "Active Processes: %d", obj_n); mvaddstr(0, 20, buffer); // Visualizzo il numero di oggetti della scena //sprintf(buffer, "Last hit: %d", last_alien_hit); //mvaddstr(0, 50, buffer); // Visualizzo il numero di alieni sprintf(buffer, "Aliens: %d", aliens); mvaddstr(0, 50, buffer); // Rendo invisibile il cursore e faccio il refresh curs_set(0); refresh(); // Aggiorno il numero di iterazioni iterations++; } while(playing && aliens > 0); // Fermo le ncurses #ifdef COLORS attroff(COLOR_PAIR(1)); #endif endwin(); // Se ci son processi rimasti, invio un segnale di kill per terminarli for (i = 0; i < OBJECTS_MAX; i++) { if(objects[i].x != -1) { // Se e' un alieno, utilizzo la coda dei messaggi per le collisioni // per dire di uccidersi if(objects[i].type == OT_ALIEN) { coll_m.coll = 'd'; msgsnd(qid_coll[objects[i].id], &coll_m, sizeof(coll_m) - sizeof(coll_m.mtype), 0); } else { kill(objects[i].pid, SIGQUIT); } // Attendo che il processo esca waitpid(objects[i].pid); obj_n--; objects[i].x = -1; } } // Elimino tutte le code dei messaggi create in precedenza msgctl(qid, IPC_RMID, NULL); for(i = 0; i < ALIEN_NUM; i++) msgctl(qid_coll[i], IPC_RMID, NULL); // Aggiungo il punteggio alla lista degli highscore e visualizzo // un messaggio di fine gioco system("clear"); int pos = scores_add(scores); if(aliens == 0) printf("Hai vinto!\n"); else printf("Hai perso!\n"); if(pos == 0) printf("Nuovo punteggio high score! %d\n", scores); else printf("Il tuo punteggio e' %d\n", scores); // Visualizzo la lista dei punteggi alti int scorl[SCORES_N_MAX]; scores_load(scorl); for(i = 0; i < SCORES_N_MAX; i++) printf("\t%d\t%d\n", i+1, scorl[i]); }
/*void Monde::afficherMap(int x,int y) const { init_pair(1, COLOR_RED, COLOR_RED); init_pair(2, COLOR_GREEN, COLOR_GREEN); init_pair(3, COLOR_YELLOW, COLOR_YELLOW); init_pair(4, COLOR_MAGENTA, COLOR_MAGENTA); init_pair(5, COLOR_BLACK, COLOR_BLACK); init_pair(6,COLOR_WHITE,COLOR_WHITE); for(int i=0;i<60;i++) { for(int j=0;j<75;j++) { switch(m_monde[0][0].getElements(i,j)) { case '#': attron(COLOR_PAIR(1)); printw("%c",m_monde[0][0].getElements(i,j)); attroff(COLOR_PAIR(1)); //m_monde.elementsMap(1,i,j); break; case 'P': attron(COLOR_PAIR(2)); printw("%c",m_monde[0][0].getElements(i,j)); attroff(COLOR_PAIR(2)); break; case ' ': attron(COLOR_PAIR(3)); printw("%c",m_monde[0][0].getElements(i,j)); attroff(COLOR_PAIR(3)); break; case 'A': attron(COLOR_PAIR(4)); printw("%c",m_monde[0][0].getElements(i,j)); attroff(COLOR_PAIR(4)); break; case 'X': attron(COLOR_PAIR(5)); printw("%c",m_monde[0][0].getElements(i,j)); attroff(COLOR_PAIR(5)); break; case 'O': attron(COLOR_PAIR(6)); printw("%c",m_monde[0][0].getElements(i,j)); attroff(COLOR_PAIR(6)); break; } } printw("\n"); } }*/ void Monde::afficherMap2() const { clear(); init_pair(1, COLOR_RED, COLOR_RED); init_pair(2, COLOR_GREEN, COLOR_GREEN); init_pair(3, COLOR_YELLOW, COLOR_YELLOW); init_pair(4, COLOR_MAGENTA, COLOR_MAGENTA); init_pair(5, COLOR_BLACK, COLOR_BLACK); init_pair(6,COLOR_WHITE,COLOR_WHITE); for(int i=0;i<60;i++) { for(int j=0;j<75;j++) { switch(m_monde[positionX][positionY].getElements(i,j)) { case '#': attron(COLOR_PAIR(1)); //printw("%c",getPlayerMap()->getElements(i,j)); printw("%c",m_monde[positionX][positionY].getElements(i,j)); attroff(COLOR_PAIR(1)); //m_monde.elementsMap(1,i,j); break; case 'P': attron(COLOR_PAIR(2)); //printw("%c",getPlayerMap()->getElements(i,j)); printw("%c",m_monde[positionX][positionY].getElements(i,j)); attroff(COLOR_PAIR(2)); break; case ' ': attron(COLOR_PAIR(3)); //printw("%c",getPlayerMap()->getElements(i,j)); printw("%c",m_monde[positionX][positionY].getElements(i,j)); attroff(COLOR_PAIR(3)); break; case 'A': attron(COLOR_PAIR(4)); //rintw("%c",getPlayerMap()->getElements(i,j)); printw("%c",m_monde[positionX][positionY].getElements(i,j)); attroff(COLOR_PAIR(4)); break; case 'X': attron(COLOR_PAIR(5)); // printw("%c",getPlayerMap()->getElements(i,j)); printw("%c",m_monde[positionX][positionY].getElements(i,j)); attroff(COLOR_PAIR(5)); break; case 'O': attron(COLOR_PAIR(6)); // printw("%c",getPlayerMap()->getElements(i,j)); printw("%c",m_monde[positionX][positionY].getElements(i,j)); attroff(COLOR_PAIR(6)); break; case 'B': attron(COLOR_PAIR(6)); // printw("%c",getPlayerMap()->getElements(i,j)); printw("%c",m_monde[positionX][positionY].getElements(i,j)); attroff(COLOR_PAIR(6)); break; } } printw("\n"); } }
int main(){ system("clear"); srand(time(NULL)); int filas=0,columnas=0,opcion=0,a=0; int **mat; initscr(); colores(); wbkgd(stdscr,COLOR_PAIR(3));refresh(); do{ erase();refresh(); printw("\nMenu\n\t1.-Generar Matriz\n\t2.-Mostrar Soluciones\n\t3.-Cargar Matriz\n\t4.-Guardar Matriz\n\t5.-Ver Matriz\n\t0.-Salir\n");refresh(); scanw("%i",&opcion); switch(opcion){ case 0: printw("\nAdios!\n");refresh(); printw("\nPresione cualquier tecla.");refresh(); getch(); break; case 1: printw("\nIngrese Filas:");refresh(); scanw("%i",&filas); printw("\nIngrese Columnas:");refresh(); scanw("%i",&columnas); mat=CreaMatriz(filas,columnas); Cargar(mat,filas,columnas); Mostrar(mat,filas,columnas,0,0); printw("\nPresione cualquier tecla.");refresh(); getch(); break; case 2: a=0; while(a<columnas){ if(mat[0][a]!=1){ attron(COLOR_PAIR(5)); printw("\n\n\nEntrando por(%i;%i)",0,a);refresh(); attroff(COLOR_PAIR(5)); printw("\n(%i;%i)",0,a);refresh(); mat[0][a]=2; Laberinto(mat,filas,columnas,0,a); mat[0][a]=0; } a++; } printw("\nPresione cualquier tecla.");refresh(); getch(); break; case 3: mat=CargaMat(&filas,&columnas); getch(); break; case 4: GuardaMat(mat,filas,columnas); getch(); break; case 5: Mostrar(mat,filas,columnas,0,0); printw("\nPresione cualquier tecla.");refresh(); getch(); break; default: printw("\nOpcion Invalida");refresh(); printw("\nPresione cualquier tecla.");refresh(); getch(); } }while(opcion!=0); endwin(); return(0); }
void draw() { _lines.clear(); Server::Stopwatches::const_iterator stopwatch; for (stopwatch = _server->_cache.begin(); stopwatch != _server->_cache.end(); ++stopwatch) { Server::TimingMap::const_iterator line; for (line = (*stopwatch).second.begin(); line != (*stopwatch).second.end(); ++line) { std::ostringstream os; os << std::setw(20) << (*line).first << " " << std::setw(6) << (*line).second[0] << " " << std::setw(6) << (*line).second.getMinimum() << " " << std::setw(6) << (*line).second.getMaximum() << " " << std::setw(6) << (*line).second.getAverage() << " " << std::setw(6) << (*line).second.getReciprocal()*1000.0 << " "; _lines.push_back(os.str()); } } std::sort(_lines.begin(), _lines.end()); if (_topLineIndex > _lines.size() - 1) { _topLineIndex = _lines.size() - 1; } if (_topLineIndex < 0) { _topLineIndex = 0; } const char title[] = "StopwatchViewer"; int center = (COLS - sizeof(title))/2; attron(A_BOLD|A_UNDERLINE); mvprintw(0, center, title); attroff(A_BOLD|A_UNDERLINE); const char legend[] = "f: flush; n: scroll down, p: scroll up; q: quit"; center = (COLS - sizeof(legend))/2; mvprintw(1, center, legend); // Each column has 1 space between it // Name[20] // Last[6] // Min[6] // Max[6] // Avg[6] // Hz[6] const char header[] = "Name Last Min Max Avg Hz "; attron(A_BOLD); mvprintw(3, 0, header); // Draw the lines based on the user's scroll position std::vector<std::string> lines; int output_line = 4; int input_line = _topLineIndex; while (input_line < _lines.size()) { mvprintw(output_line, 0, _lines[input_line].c_str()); output_line++; input_line++; } refresh(); }