int main(void) { const char witch_one[] = "First Witch"; const char witch_two[] = "Second Witch"; const char *scan_ptr; initscr(); move(5,15); attron(A_BOLD); printw("%s", "Macbeth");/* writes to the window */ attroff(A_BOLD); /* this macro makes the character bold*/ refresh(); sleep(1); move(8, 15); attron(A_STANDOUT); /* Best highlighting mode of the terminal */ printw("%s", "Thunder and Lighting"); attroff(A_STANDOUT); refresh(); sleep(1); move(10, 10); printw("%s", "When shall we meet again"); move(11, 23); printw("%s", "In the thunder lightining or in the rain"); move(13, 10); printw("%s", "When the hurlyburly's done"); move(14, 23); printw("%s", "When the battle is lost and won"); refresh(); sleep(1); attron(A_DIM); /* half Bright */ scan_ptr = witch_one + strlen(witch_two) - 1; while(scan_ptr != witch_one) { move(10, 10); insch(*scan_ptr--); /* moves character further */ } scan_ptr = witch_two + strlen(witch_one) - 1; while(scan_ptr != witch_two) { move(13, 10); insch(*scan_ptr--); } attroff(A_DIM); refresh(); sleep(1); move(LINES - 1, COLS - 1);/* macros giving max no. of lines and col */ refresh(); sleep(1); endwin(); exit(EXIT_SUCCESS); }
int main(void) { const char witch_one[]=" First Witch "; const char witch_two[]=" Second Witch "; const char *scan_ptr; initscr(); move(5,15); attron(A_BOLD); printw("%s","Macbeth"); attroff(A_BOLD); refresh(); sleep(1); move(8,15); attron(A_STANDOUT); printw("%s","Thunder and lightning"); attroff(A_STANDOUT); refresh(); sleep(1); move(10,10); printw("%s","When shall we three meet again"); move(11,23); printw("%s","In thunder, lightning, or in rain ?"); move(13,10); printw("%s","When the hurlyburly's done,"); move(14,23); printw("%s","When the battle's lost and won."); refresh(); sleep(1); attron(A_DIM); scan_ptr=witch_one+strlen(witch_one)-1; while(scan_ptr!=witch_one){ move(10,10); insch(*scan_ptr--); } scan_ptr=witch_two+strlen(witch_two)-1; while(scan_ptr!=witch_two){ move(13,10); insch(*scan_ptr--); } attroff(A_DIM); refresh(); sleep(1); move(LINES-1,COLS-1); refresh(); sleep(1); endwin(); exit(EXIT_SUCCESS); }
void delete_cowboy(int side) { int i; assert(side == RIGHT || side == LEFT); for ( i = 0; i < COWBOY_HEIGHT; i++ ) { move(cowboys[side].y+i, cowboys[side].x); delch(); delch(); delch(); delch(); insch(' '); insch(' '); insch(' '); insch(' '); } refresh(); }
void moveBlockToRight(int row, int *start, int *end, int screen_width) { if(*end >= screen_width) return; SET_COLOR_WHITE; move(row, *start); delch(); insch(' '); (*start)++; SET_COLOR_RED; move(row, *end); delch(); insch(' '); (*end)++; return; }
int main(void) { char text[] = "Stock Market Swells! DOW tops 15,000!"; char *t; int len; initscr(); fill(); refresh(); len = strlen(text); t = text; /* initialize pointer */ while(len) { move(5,5); /* always insert at the same spot */ insch(*(t+len-1)); /* work through string backwards */ refresh(); napms(100); /* .1 sec. delay */ len--; } getchar(); endwin(); return 0; }
void moveBlockToLeft(int row, int *start, int *end) { if(*start < 1) return; SET_COLOR_RED; (*start)--; move(row, *start); delch(); insch(' '); SET_COLOR_WHITE; move(row, *end); delch(); insch(' '); (*end)--; move(row, *end); return; }
void put(int ch) { getyx(mywin, r, c); if (insmode == 0) addch(ch); else if (insmode == 1) insch(ch); refresh(); }
int main(){ char* one = " XXOO "; char* scan_ptr; initscr(); move(5,15); attron(A_STANDOUT); printw("%s", "Hello World!"); attroff(A_STANDOUT); refresh(); sleep(1); attron(A_DIM); scan_ptr = one + strlen(one) - 1; while(scan_ptr != one){ move(10,10); insch(*scan_ptr--); sleep(1); refresh(); } attroff(A_DIM); while(1); endwin(); return 0; }
void broadcast() { char str[36]; sprintf(str, "%d:%d:%d", g_Round, g_max_x, g_max_y); mvaddstr(8, 8, str); // show map int x, y; for (x = 0; x < g_max_x; x++) { for (y = 0; y < g_max_y; y++) { if (map[x][y] < enTile_RedHeadUp) { attrset(COLOR_PAIR(3));//system output } else if (map[x][y] < enTile_GreenHeadUp) { attrset(COLOR_PAIR(1));//red output } else { attrset(COLOR_PAIR(2));//green output } move(x, y); insch(gcTable[map[x][y]]); } } sprintf(str, "%d", g_Round); mvaddstr(g_max_x/2, g_max_y/2, str); // notify player // todo... }
/* * Displays the current board in a curses window * * Parameters: const World_t* world, Lens_t* lens, WINDOW* display_area * Return: void */ void display_curses(const World_t* world, Lens_t* lens, WINDOW* window) { int x, y; int display_x, display_y; int display_width, display_height; int value; char display_value; // determine terminal's rows and columns. Display cell if in bounds getmaxyx(window, display_height, display_width); lens_set(lens, world->board, display_width, display_height); // clear the display of the old frame clear(); for(y = lens->min_y; y < lens->max_y; y++) { for(x = lens->min_x; x < lens->max_x; x++) { value = board_get_cell(world->board, x, y); // Adjust display coordinates by the BOARD_BORDER_SIZE offset display_x = x - lens->x_display_offset; display_y = y - lens->y_display_offset; move(display_y, display_x); // display o for each living cell within the terminal if (display_y < display_height && display_x < display_width) { display_value = world->rule->state_chars[value]; if (display_value != ' ') { insch(display_value); } } } } refresh(); }
void delete_bomb(Block *bomb) { int index; SET_COLOR_WHITE; for(index = 2; index < bomb->screen_height - 1; ++index) { move(index, bomb->col); delch(); insch(' '); } }
/***************************************************** * Draws whole screen based on (*chip8).screen array * * ***************************************************/ int draw(chip8* myChip8) { int x; int y; // loop through every x,y postion for(y = 0; y < 32; y++){ for(x = 0; x < 64; x++){ move(y, x); // move the cursor to position x, y delch(); // delect the character currently in this postion if((*myChip8).screen[x][y] == 1) // if pixel is set insch('#'); // draw a pixel else insch('-'); // draw a blank } } move(33, 0); refresh(); // after the new screen is drawn, refresh the terminal so it show the changes return 1; }
void draw(char dc) { move(r, c); delch(); insch(dc); refresh(); r++; if (r == nrows) { r = 0; c++; if (c == ncols) c = 0; } }
static int InsCh(chtype ch) { int code; cchar_t tmp_cchar; if (ConvertCh(ch, &tmp_cchar)) { code = ins_wch(&tmp_cchar); } else { code = insch(ch); } return code; }
void move_bullets() { int i, side; for ( i = 0; i < maxbalas; i++ ) { for ( side = LEFT; side <= RIGHT; side++ ) { if ( !bullets[side][i].empty ) { move(bullets[side][i].y, bullets[side][i].x); delch(); insch(' '); if ( side == LEFT ) { bullets[side][i].x++; if ( bullets[side][i].x >= NCOLS ) { bullets[side][i].empty = 1; } else { move(bullets[side][i].y, bullets[side][i].x); delch(); insch('>'); } } else { bullets[side][i].x--; if ( bullets[side][i].x < 0 ) { bullets[side][i].empty = 1; } else { move(bullets[side][i].y, bullets[side][i].x); delch(); insch('<'); } } } } } refresh(); }
void *create_bomb(void *arg) { Block *bomb; bomb = (Block *) arg; pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); pthread_mutex_lock(&mutex); addThread(pthread_self()); pthread_mutex_unlock(&mutex); while(bomb->row <= bomb->screen_height) { if(bomb->row == bomb->screen_height - 1) { pthread_mutex_lock(&mutex); if(bomb->col >= bomb->block->start && bomb->col <= bomb->block->end) { increaseScore(); displayScore(); } else { flash(); decreaseScore(score); displayScore(); } delete_bomb(bomb); pthread_mutex_unlock(&mutex); break; } pthread_mutex_lock(&mutex); SET_COLOR_BLUE; move(bomb->row, bomb->col); delch(); insch(' '); (bomb->row)++; SET_COLOR_RED; pthread_mutex_unlock(&mutex); refresh(); pthread_testcancel(); napms(150); } pthread_mutex_lock(&mutex); bomb->cols[bomb->col] = 0; removeThread(pthread_self()); pthread_mutex_unlock(&mutex); free(bomb); pthread_exit((void *) 0); }
/* * Insert mode: accept characters and insert them. * End with ^D or EIC */ void input() { int c; standout(); mvaddstr(LINES - 1, COLS - 20, "INPUT MODE"); standend(); move(row, col); refresh(); for (;;) { c = getch(); if (c == CTRL('D') || c == KEY_EIC) break; insch(c); move(row, ++col); refresh(); } move(LINES - 1, COLS - 20); clrtoeol(); move(row, col); refresh(); }
/* get a line from the terminal in non-canonical mode */ int mygetline(char p[], char s[], unsigned size, int firstchar, BOOL iscaseless) { int c; unsigned int i = 0, j; char *sright; /* substring to the right of the cursor */ unsigned int ri = 0; /* position in right-string */ /* Inserts and deletes are always performed on the left-string, * but we'll also have a right-string 'sright' to hold characters * which are on the right of the cursor [insertion point]. * * Think of 'sright' as a stack -- we push chars into it when the cursor * moves left, and we pop chars off it when the cursor moves right again. * At the end of the function, we'll pop off any remaining characters * onto the end of 's' */ sright = calloc(sizeof(char), size ); strcpy ( s, p); i += strlen(p); /* if a character already has been typed */ if (firstchar != '\0') { if(iscaseless == YES) { firstchar = tolower(firstchar); } addch(firstchar); /* display it */ s[i++] = firstchar; /* save it */ } /* until the end of the line is reached */ while ((c = mygetch()) != '\r' && c != '\n' && c != KEY_ENTER) { if (c == KEY_LEFT || c == ctrl('B')) { /* left */ if (i > 0) { addch('\b'); /* move this char into the second (rhs) string */ sright[ri++] = s[--i]; } } else if (c == KEY_RIGHT || c == ctrl('F')) { /* right */ if (i < size && ri > 0) { /* move this char to the left of the cursor */ s[i++] = sright[--ri]; addch(s[i-1]); } } else if ( #ifdef KEY_HOME c == KEY_HOME || #endif c == ctrl('A') ) { while (i > 0) { sright[ri++] = s[--i]; addch('\b'); addch(s[i]); addch('\b'); } } else if ( #ifdef KEY_END c == KEY_END || #endif c == ctrl('E') ) { while (ri > 0) { s[i++] = sright[--ri]; addch(s[i-1]); } } else if (c == erasechar() || c == KEY_BACKSPACE || c == DEL || c == ctrl('H') ) { /* erase */ if (i > 0) { if (ri == 0) { addstr("\b \b"); } else { addch('\b'); delch(); } s[i] = '\0'; --i; } } else if (c == killchar() || c == KEY_BREAK) { /* kill */ for (j = 0; j < i; ++j) { addch('\b'); } for (j = 0; j < i; ++j) { addch(' '); } for (j = 0; j < i; ++j) { addch('\b'); } i = 0; } else if (isprint(c) || c == '\t') { /* printable */ if(iscaseless == YES) { c = tolower(c); } /* if it will fit on the line */ if (i < size) { s[i++] = c; /* save it */ if (ri == 0) { addch(c); /* display it */ } else { insch(c); /* display it */ addch(c); /* advance cursor */ } } #if UNIXPC } else if (unixpcmouse == YES && c == ESC) { /* mouse */ getmouseaction(ESC); /* ignore it */ #endif } else if (mouse == YES && c == ctrl('X')) { getmouseaction(ctrl('X')); /* ignore it */ } else if (c == EOF) { /* end-of-file */ break; } /* return on an empty line to allow a command to be entered */ if (firstchar != '\0' && (i+ri) == 0) { break; } } /* move any remaining chars on the rhs of the cursor * onto the end of our string */ while (ri > 0) { s[i++] = sright[--ri]; } free(sright); s[i] = '\0'; return(i); }
/* * Remove everything currently in `inbuf' and stick it up on the * in-memory display. There's a big state machine in here to * process escape sequences... */ void term_out(void) { int c; int must_update = FALSE; while ( (c = inbuf_getc()) != -1) { #ifdef LOG { static FILE *fp = NULL; if (!fp) fp = fopen("putty.log", "wb"); if (fp) fputc (c, fp); } #endif switch (termstate) { case TOPLEVEL: do_toplevel: switch (c) { case '\005': /* terminal type query */ ldisc->send ("\033[?1;2c", 7); break; case '\007': beep(); disptop = scrtop; must_update = TRUE; break; case '\b': if (curs_x == 0 && curs_y > 0) curs_x = cols-1, curs_y--; else if (wrapnext) wrapnext = FALSE; else curs_x--; fix_cpos; disptop = scrtop; must_update = TRUE; break; case '\016': cset = 1; break; case '\017': cset = 0; break; case '\033': termstate = SEEN_ESC; break; case 0233: termstate = SEEN_CSI; esc_nargs = 1; esc_args[0] = ARG_DEFAULT; esc_query = FALSE; break; case 0235: termstate = SEEN_OSC; esc_args[0] = 0; break; case '\r': curs_x = 0; wrapnext = FALSE; fix_cpos; disptop = scrtop; must_update = TRUE; break; case '\013': case '\014': case '\n': if (curs_y == marg_b) scroll (marg_t, marg_b, 1, TRUE); else if (curs_y < rows-1) curs_y++; if (cfg.lfhascr) curs_x = 0; fix_cpos; wrapnext = FALSE; disptop = scrtop; nl_count++; break; case '\t': do { curs_x++; } while (curs_x < cols-1 && !tabs[curs_x]); if (curs_x >= cols) curs_x = cols-1; { unsigned long *old_cpos = cpos; fix_cpos; check_selection (old_cpos, cpos); } disptop = scrtop; must_update = TRUE; break; default: if (c >= ' ' && c != 0234) { if (wrapnext) { cpos[1] = ATTR_WRAPPED; if (curs_y == marg_b) scroll (marg_t, marg_b, 1, TRUE); else if (curs_y < rows-1) curs_y++; curs_x = 0; fix_cpos; wrapnext = FALSE; nl_count++; } if (insert) insch (1); check_selection (cpos, cpos+1); *cpos++ = xlat_tty2scr((unsigned char)c) | curr_attr | (c <= 0x7F ? cset_attr[cset] : ATTR_ASCII); curs_x++; if (curs_x == cols) { cpos--; curs_x--; wrapnext = wrap; } disptop = scrtop; } } break; case IGNORE_NEXT: termstate = TOPLEVEL; break; case OSC_MAYBE_ST: /* * This state is virtually identical to SEEN_ESC, with the * exception that we have an OSC sequence in the pipeline, * and _if_ we see a backslash, we process it. */ if (c == '\\') { do_osc(); termstate = TOPLEVEL; break; } /* else fall through */ case SEEN_ESC: termstate = TOPLEVEL; switch (c) { case '\005': case '\007': case '\b': case '\016': case '\017': case '\033': case 0233: case 0234: case 0235: case '\r': case '\013': case '\014': case '\n': case '\t': termstate = TOPLEVEL; goto do_toplevel; /* hack... */ case ' ': /* some weird sequence? */ termstate = IGNORE_NEXT; break; case '[': /* enter CSI mode */ termstate = SEEN_CSI; esc_nargs = 1; esc_args[0] = ARG_DEFAULT; esc_query = FALSE; break; case ']': /* xterm escape sequences */ termstate = SEEN_OSC; esc_args[0] = 0; break; case '(': /* should set GL */ termstate = SET_GL; break; case ')': /* should set GR */ termstate = SET_GR; break; case '7': /* save cursor */ save_cursor (TRUE); break; case '8': /* restore cursor */ save_cursor (FALSE); disptop = scrtop; must_update = TRUE; break; case '=': app_keypad_keys = TRUE; break; case '>': app_keypad_keys = FALSE; break; case 'D': /* exactly equivalent to LF */ if (curs_y == marg_b) scroll (marg_t, marg_b, 1, TRUE); else if (curs_y < rows-1) curs_y++; fix_cpos; wrapnext = FALSE; disptop = scrtop; nl_count++; break; case 'E': /* exactly equivalent to CR-LF */ curs_x = 0; wrapnext = FALSE; if (curs_y == marg_b) scroll (marg_t, marg_b, 1, TRUE); else if (curs_y < rows-1) curs_y++; fix_cpos; wrapnext = FALSE; nl_count++; disptop = scrtop; break; case 'M': /* reverse index - backwards LF */ if (curs_y == marg_t) scroll (marg_t, marg_b, -1, TRUE); else if (curs_y > 0) curs_y--; fix_cpos; wrapnext = FALSE; disptop = scrtop; must_update = TRUE; break; case 'Z': /* terminal type query */ ldisc->send ("\033[?6c", 5); break; case 'c': /* restore power-on settings */ power_on(); fix_cpos; disptop = scrtop; must_update = TRUE; break; case '#': /* ESC # 8 fills screen with Es :-) */ termstate = SEEN_ESCHASH; break; case 'H': /* set a tab */ tabs[curs_x] = TRUE; break; } break; case SEEN_CSI: termstate = TOPLEVEL; /* default */ switch (c) { case '\005': case '\007': case '\b': case '\016': case '\017': case '\033': case 0233: case 0234: case 0235: case '\r': case '\013': case '\014': case '\n': case '\t': termstate = TOPLEVEL; goto do_toplevel; /* hack... */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (esc_nargs <= ARGS_MAX) { if (esc_args[esc_nargs-1] == ARG_DEFAULT) esc_args[esc_nargs-1] = 0; esc_args[esc_nargs-1] = 10 * esc_args[esc_nargs-1] + c - '0'; } termstate = SEEN_CSI; break; case ';': if (++esc_nargs <= ARGS_MAX) esc_args[esc_nargs-1] = ARG_DEFAULT; termstate = SEEN_CSI; break; case '?': esc_query = TRUE; termstate = SEEN_CSI; break; case 'A': /* move up N lines */ move (curs_x, curs_y - def(esc_args[0], 1), 1); disptop = scrtop; must_update = TRUE; break; case 'B': case 'e': /* move down N lines */ move (curs_x, curs_y + def(esc_args[0], 1), 1); disptop = scrtop; must_update = TRUE; break; case 'C': case 'a': /* move right N cols */ move (curs_x + def(esc_args[0], 1), curs_y, 1); disptop = scrtop; must_update = TRUE; break; case 'D': /* move left N cols */ move (curs_x - def(esc_args[0], 1), curs_y, 1); disptop = scrtop; must_update = TRUE; break; case 'E': /* move down N lines and CR */ move (0, curs_y + def(esc_args[0], 1), 1); disptop = scrtop; must_update = TRUE; break; case 'F': /* move up N lines and CR */ move (0, curs_y - def(esc_args[0], 1), 1); disptop = scrtop; must_update = TRUE; break; case 'G': case '`': /* set horizontal posn */ move (def(esc_args[0], 1) - 1, curs_y, 0); disptop = scrtop; must_update = TRUE; break; case 'd': /* set vertical posn */ move (curs_x, (dec_om ? marg_t : 0) + def(esc_args[0], 1) - 1, (dec_om ? 2 : 0)); disptop = scrtop; must_update = TRUE; break; case 'H': case 'f': /* set horz and vert posns at once */ if (esc_nargs < 2) esc_args[1] = ARG_DEFAULT; move (def(esc_args[1], 1) - 1, (dec_om ? marg_t : 0) + def(esc_args[0], 1) - 1, (dec_om ? 2 : 0)); disptop = scrtop; must_update = TRUE; break; case 'J': /* erase screen or parts of it */ { unsigned int i = def(esc_args[0], 0) + 1; if (i > 3) i = 0; erase_lots(FALSE, !!(i & 2), !!(i & 1)); } disptop = scrtop; must_update = TRUE; break; case 'K': /* erase line or parts of it */ { unsigned int i = def(esc_args[0], 0) + 1; if (i > 3) i = 0; erase_lots(TRUE, !!(i & 2), !!(i & 1)); } disptop = scrtop; must_update = TRUE; break; case 'L': /* insert lines */ if (curs_y <= marg_b) scroll (curs_y, marg_b, -def(esc_args[0], 1), FALSE); disptop = scrtop; must_update = TRUE; break; case 'M': /* delete lines */ if (curs_y <= marg_b) scroll (curs_y, marg_b, def(esc_args[0], 1), FALSE); disptop = scrtop; must_update = TRUE; break; case '@': /* insert chars */ insch (def(esc_args[0], 1)); disptop = scrtop; must_update = TRUE; break; case 'P': /* delete chars */ insch (-def(esc_args[0], 1)); disptop = scrtop; must_update = TRUE; break; case 'c': /* terminal type query */ ldisc->send ("\033[?6c", 5); break; case 'n': /* cursor position query */ if (esc_args[0] == 6) { char buf[32]; sprintf (buf, "\033[%d;%dR", curs_y + 1, curs_x + 1); ldisc->send (buf, strlen(buf)); } break; case 'h': /* toggle a mode to high */ toggle_mode (esc_args[0], esc_query, TRUE); break; case 'l': /* toggle a mode to low */ toggle_mode (esc_args[0], esc_query, FALSE); break; case 'g': /* clear tabs */ if (esc_nargs == 1) { if (esc_args[0] == 0) { tabs[curs_x] = FALSE; } else if (esc_args[0] == 3) { int i; for (i = 0; i < cols; i++) tabs[i] = FALSE; } } break; case 'r': /* set scroll margins */ if (!esc_query && esc_nargs <= 2) { int top, bot; top = def(esc_args[0], 1) - 1; if (top < 0) top = 0; bot = (esc_nargs <= 1 || esc_args[1] == 0 ? rows : def(esc_args[1], rows)) - 1; if (bot >= rows) bot = rows-1; if (top <= bot) { marg_t = top; marg_b = bot; curs_x = 0; /* * I used to think the cursor should be * placed at the top of the newly marginned * area. Apparently not: VMS TPU falls over * if so. */ curs_y = 0; fix_cpos; disptop = scrtop; must_update = TRUE; } } break; case 'm': /* set graphics rendition */ { int i; for (i=0; i<esc_nargs; i++) { switch (def(esc_args[i], 0)) { case 0: /* restore defaults */ curr_attr = ATTR_DEFAULT; break; case 1: /* enable bold */ curr_attr |= ATTR_BOLD; break; case 4: /* enable underline */ case 21: /* (enable double underline) */ curr_attr |= ATTR_UNDER; break; case 7: /* enable reverse video */ curr_attr |= ATTR_REVERSE; break; case 22: /* disable bold */ curr_attr &= ~ATTR_BOLD; break; case 24: /* disable underline */ curr_attr &= ~ATTR_UNDER; break; case 27: /* disable reverse video */ curr_attr &= ~ATTR_REVERSE; break; case 30: case 31: case 32: case 33: case 34: case 35: case 36: case 37: /* foreground */ curr_attr &= ~ATTR_FGMASK; curr_attr |= (esc_args[i] - 30) << ATTR_FGSHIFT; break; case 39: /* default-foreground */ curr_attr &= ~ATTR_FGMASK; curr_attr |= ATTR_DEFFG; break; case 40: case 41: case 42: case 43: case 44: case 45: case 46: case 47: /* background */ curr_attr &= ~ATTR_BGMASK; curr_attr |= (esc_args[i] - 40) << ATTR_BGSHIFT; break; case 49: /* default-background */ curr_attr &= ~ATTR_BGMASK; curr_attr |= ATTR_DEFBG; break; } } } break; case 's': /* save cursor */ save_cursor (TRUE); break; case 'u': /* restore cursor */ save_cursor (FALSE); disptop = scrtop; must_update = TRUE; break; case 't': /* set page size - ie window height */ request_resize (cols, def(esc_args[0], 24)); deselect(); break; case 'X': /* write N spaces w/o moving cursor */ { int n = def(esc_args[0], 1); unsigned long *p = cpos; if (n > cols - curs_x) n = cols - curs_x; check_selection (cpos, cpos+n); while (n--) *p++ = ERASE_CHAR; disptop = scrtop; must_update = TRUE; } break; case 'x': /* report terminal characteristics */ { char buf[32]; int i = def(esc_args[0], 0); if (i == 0 || i == 1) { strcpy (buf, "\033[2;1;1;112;112;1;0x"); buf[2] += i; ldisc->send (buf, 20); } } break; } break; case SET_GL: case SET_GR: switch (c) { case 'A': cset_attr[termstate == SET_GL ? 0 : 1] = ATTR_GBCHR; break; case '0': cset_attr[termstate == SET_GL ? 0 : 1] = ATTR_LINEDRW; break; default: /* specifically, 'B' */ cset_attr[termstate == SET_GL ? 0 : 1] = ATTR_ASCII; break; } termstate = TOPLEVEL; break; case SEEN_OSC: osc_w = FALSE; switch (c) { case '\005': case '\007': case '\b': case '\016': case '\017': case '\033': case 0233: case 0234: case 0235: case '\r': case '\013': case '\014': case '\n': case '\t': termstate = TOPLEVEL; goto do_toplevel; /* hack... */ case 'P': /* Linux palette sequence */ termstate = SEEN_OSC_P; osc_strlen = 0; break; case 'R': /* Linux palette reset */ palette_reset(); term_invalidate(); termstate = TOPLEVEL; break; case 'W': /* word-set */ termstate = SEEN_OSC_W; osc_w = TRUE; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': esc_args[0] = 10 * esc_args[0] + c - '0'; break; case 'L': /* * Grotty hack to support xterm and DECterm title * sequences concurrently. */ if (esc_args[0] == 2) { esc_args[0] = 1; break; } /* else fall through */ default: termstate = OSC_STRING; osc_strlen = 0; } break; case OSC_STRING: if (c == 0234 || c == '\007') { /* * These characters terminate the string; ST and BEL * terminate the sequence and trigger instant * processing of it, whereas ESC goes back to SEEN_ESC * mode unless it is followed by \, in which case it is * synonymous with ST in the first place. */ do_osc(); termstate = TOPLEVEL; } else if (c == '\033') termstate = OSC_MAYBE_ST; else if (osc_strlen < OSC_STR_MAX) osc_string[osc_strlen++] = c; break; case SEEN_OSC_P: { int max = (osc_strlen == 0 ? 21 : 16); int val; if (c >= '0' && c <= '9') val = c - '0'; else if (c >= 'A' && c <= 'A'+max-10) val = c - 'A' + 10; else if (c >= 'a' && c <= 'a'+max-10) val = c - 'a' + 10; else termstate = TOPLEVEL; osc_string[osc_strlen++] = val; if (osc_strlen >= 7) { palette_set (osc_string[0], osc_string[1] * 16 + osc_string[2], osc_string[3] * 16 + osc_string[4], osc_string[5] * 16 + osc_string[6]); term_invalidate(); termstate = TOPLEVEL; } } break; case SEEN_OSC_W: switch (c) { case '\005': case '\007': case '\b': case '\016': case '\017': case '\033': case 0233: case 0234: case 0235: case '\r': case '\013': case '\014': case '\n': case '\t': termstate = TOPLEVEL; goto do_toplevel; /* hack... */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': esc_args[0] = 10 * esc_args[0] + c - '0'; break; default: termstate = OSC_STRING; osc_strlen = 0; } break; case SEEN_ESCHASH: if (c == '8') { unsigned long *p = scrtop; int n = rows * (cols+1); while (n--) *p++ = ATTR_DEFAULT | 'E'; disptop = scrtop; must_update = TRUE; check_selection (scrtop, scrtop + rows * (cols+1)); } termstate = TOPLEVEL; break; } check_selection (cpos, cpos+1); } if (must_update || nl_count > MAXNL) term_update(); }
int main() { const char witch_one[] = " First Witch "; const char witch_two[] = " Second Witch "; const char *scan_ptr; initscr(); /* Now for the three initial sets of text that appear at intervals on the screen. Note the on and off flagging of text attributes. */ move(5, 15); attron(A_BOLD); printw("%s", "Macbeth"); attroff(A_BOLD); refresh(); sleep(1); move(8, 15); attron(A_STANDOUT); printw("%s", "Thunder and Lightning"); attroff(A_STANDOUT); refresh(); sleep(1); move(10, 10); printw("%s", "When shall we three meet again"); move(11, 23); printw("%s", "In thunder, lightning, or in rain ?"); move(13, 10); printw("%s", "When the hurlyburly's done,"); move(14,23); printw("%s", "When the battle's lost and won."); refresh(); sleep(1); /* Lastly, the actors are identified and their names are inserted a character at the time. We also add the reset function at the end of the main function. */ attron(A_DIM); scan_ptr = witch_one + strlen(witch_one) - 1; while(scan_ptr != witch_one) { move(10,10); insch(*scan_ptr--); } scan_ptr = witch_two + strlen(witch_two) - 1; while (scan_ptr != witch_two) { move(13, 10); insch(*scan_ptr--); } attroff(A_DIM); refresh(); sleep(1); move(LINES - 1, COLS - 1); refresh(); sleep(1); endwin(); exit(EXIT_SUCCESS); }
int modifica_janela(char **campos, int side, int codigo) { int i; switch(codigo) { case NSH: if(strcmp(campos[1],"P2")==0) side=RIGHT; if(strcmp(campos[1],"P1")==0) side=LEFT; /**SE SYNC - TEM QUE ACTIVAR THREAD PARA ACTUALIZAR BALAS**/ for ( i = 0; i < maxbalas; i++ ) { if ( bullets[side][i].empty ) { break; } } if ( i < maxbalas ) { bullets[side][i].empty = FALSE; bullets[side][i].y = cowboys[side].y + 2; /***BLOQUEAR*/ cowboys[side].bulletsleft--; if ( side == LEFT ) { bullets[side][i].x = cowboys[side].x+4; move(bullets[side][i].y, bullets[side][i].x); delch(); insch('>'); } else { bullets[side][i].x = cowboys[side].x-1; move(bullets[side][i].y, bullets[side][i].x); delch(); insch('<'); } refresh(); } return FALSE; break; case REL: /****BLOQUEAR***/ cowboys[LEFT].bulletsleft=maxbalas; cowboys[RIGHT].bulletsleft=maxbalas; free(campos[0]); return FALSE; break; case BLT: /**Move as balas*/ if(!check_dead(LEFT) && !check_dead(RIGHT)) { for ( i = 0; i < maxbalas; i++ ) { if ( bullets[side][i].empty ) { break; } } if(i<maxbalas+1) move_bullets(); } free(campos[0]); return FALSE; break; case MOV: if(strcmp(campos[1],"P1")==0) side = LEFT; else side = RIGHT; delete_cowboy(side); cowboys[side].y = atoi(campos[2]); draw_cowboy(side); return FALSE; break; case EOG: clear(); if(strcmp(campos[1],"P1")==0) { mvwprintw(wnd, NROWS/2, NCOLS/2-(strlen("VENCEDOR DA PARTIDA: ")+strlen(cowboys[LEFT].name))/2, "Vencedor da partida: %s",cowboys[LEFT].name); cowboys[LEFT].games=atoi(campos[2]); } else if(strcmp(campos[1],"P2")==0) { mvwprintw(wnd, NROWS/2, NCOLS/2-(strlen("VENCEDOR DA PARTIDA: ")+strlen(cowboys[RIGHT].name))/2, "Vencedor da partida: %s",cowboys[RIGHT].name); cowboys[RIGHT].games=atoi(campos[2]); } else { mvwprintw(wnd, NROWS/2-4, NCOLS/2-(strlen("VENCEDOR DA PARTIDA: JOGADOR EMPATE"))/2, "Vencedor da partida: Empate"); } wtimeout(wnd,-1); mvwprintw(wnd, 0, 0, "High Noon - Projecto de Programacao de Sistemas"); /**Colocar numero da partida?*/ mvwprintw(wnd, 1, 0, "Fim da Partida Numero: %d",cowboys[RIGHT].games+cowboys[LEFT].games); mvwprintw(wnd, NROWS-1, 0, "Pressione uma tecla qualquer para começar um novo jogo\n"); refresh(); getch(); clear(); refresh(); /**Recebe novamente tudo*/ close_HN_window(); /*delwin(wnd);*/ boas_vindas(side,FALSE); com_partida(side); clear(); refresh(); draw_cowboy(LEFT); draw_cowboy(RIGHT); return FALSE; break; case EXT: if(strcmp(campos[1],"P1")==0) side = LEFT; else side = RIGHT; cowboys[side].games=atoi(campos[2]); cowboys[!side].games=atoi(campos[3]); return TRUE; break; case ERR: break; default: close_HN_window(); printf("ERRO: Mensagem nao reconhecida!\n"); exit(EXIT_FAILURE); break; } return FALSE; }
/* * Insert a character at the current position */ void screen_insert_char(int c) { insch((unsigned char) c); }
void draw_cowboy(int side) { assert(side == RIGHT || side == LEFT); move(cowboys[side].y, cowboys[side].x+side); delch(); delch(); delch(); insch('_'); insch('M'); insch('_'); move(cowboys[side].y+1, cowboys[side].x+side+1); delch(); insch('|'); move(cowboys[side].y+2, cowboys[side].x+side); delch(); delch(); delch(); insch('-'); insch('O'); insch('-'); move(cowboys[side].y+3, cowboys[side].x+side+1); delch(); insch('|'); move(cowboys[side].y+4, cowboys[side].x+side); delch(); delch(); delch(); insch('\\'); insch(' '); insch('/'); if ( side == LEFT ) { move(cowboys[side].y+2, cowboys[side].x+3); delch(); insch('>'); } else { move(cowboys[side].y+2, cowboys[side].x); delch(); insch('<'); } refresh(); }
int main(void) { // int pid = getpid(); // printf("PID = %d\n", pid); // getchar(); initscr(); cbreak(); noecho(); keypad(stdscr, TRUE); int scr_width, scr_height; getmaxyx(stdscr, scr_height, scr_width); int columns[scr_width]; int arr_index; for(arr_index = 0; arr_index < scr_width; ++arr_index) columns[arr_index] = 0; start_color(); assume_default_colors(COLOR_WHITE, COLOR_WHITE); init_pair(1, COLOR_RED, COLOR_RED); init_pair(2, COLOR_WHITE, COLOR_WHITE); init_pair(3, COLOR_BLUE, COLOR_BLUE); init_pair(4, COLOR_BLACK, COLOR_WHITE); init_pair(5, COLOR_BLACK, COLOR_BLACK); int block_start = 1; int block_end = block_start + 20; int block_row = scr_height - 1; int index; SET_COLOR_RED; for(index = block_start; index < 20; ++index) { move(block_row, index); delch(); insch(' '); } SET_COLOR_BLACK; for(index = 0; index <= scr_width; ++index) { move(1, index); delch(); insch(' '); } // hide cursor. doesn't work?. curs_set(0); refresh(); // pthread_attr_t attr; pthread_mutex_init(&mutex, NULL); Block *block = malloc(sizeof(Block)); // freed by another thread block->start = 1; block->end = (block->start) + 20; block->row = scr_height - 1; block->screen_height = scr_height; block->screen_width = scr_width; block->cols = columns; // initialize score information score.bombs_caught = 0; score.bombs_missed = 0; score.points = 0; displayScore(); speed = 1000; // 1 second pthread_t block_thread; threadPool.tid = block_thread; threadPool.next = NULL; pthread_create(&block_thread, NULL, blockMovement, (void *) block); pthread_t timer_thread; pthread_create(&timer_thread, NULL, changeSpeed, (void *) 0); addThread(timer_thread); pthread_t bomb_thread; pthread_create(&bomb_thread, NULL, drop_bombs, (void *) block); addThread(bomb_thread); // void *status; // wait for the user to press q to actually quit pthread_join(block_thread, NULL); // free(score); pthread_mutex_destroy(&mutex); pthread_exit(NULL); }
cell pp_curs_insch(cell x) { if (!Running) return UNSPECIFIC; insch(char_value(car(x))); return UNSPECIFIC; }