Example #1
0
int main(void)
{
	int y,x,c,halfy;

	initscr();

	getmaxyx(stdscr,y,x);
	halfy = y >> 1;

	for(c=0;c<y;c++)
		mvprintw(c,15,"This is amazing row %d!\n",c);
	refresh();
	getch();

	move(halfy,0);
	for(c=0;c<halfy;c++)
	{
		insdelln(1);
		refresh();
		napms(100);
	}

	move(0,0);
	for(c=0;c<halfy;c++)
	{
		insdelln(-1);
		refresh();
		napms(100);
	}

	endwin();
	return 0;
}
Example #2
0
int main(void)
{
	int rows,cols;

	initscr();
	getmaxyx(stdscr,rows,cols);
	rows--;
	cols--;

	mvaddch(0,0,'*');	// UL Corner. Cursors starts here by default, but dont want to assume it will.
	refresh();
	napms(500);	// Pauses half a sec.

	mvaddch(0,cols,'*');	// UR Corner
	refresh();
	napms(500);	// Pauses half a sec.

	mvaddch(rows,0,'*');	// LL Corner
	refresh();
	napms(00);	// Pauses half a sec.

	mvaddch(rows,cols,'*');	// LR Corner
	refresh();

	getch();

	endwin();
	return 0;
}
Example #3
0
void DemonCalc::preRun(){
	clear();
	printw("Game Start! The current level is %d\n", game.getSteps());
	printw("Please remeber the results!!");
	refresh();
	napms(1000);
	clear();

	for(int i = 0; i < game.getSteps(); ++i){
		std::string s = game.getQuestionStr(i);
		std::stringstream ss;
		ss<<"No."<<(i+1)<<": "<<s;

		mvscrolltxt(0, 0, ss.str());
		napms(1000);

		printw("\ncount down:");
		int r, c;
		getyx(stdscr, r, c);

		for(int i = 0; i < 5; i++){
			mvaddch(r, c+1, '0'+(5-i));
			refresh();
			napms(1000);
		}

		mvaddch(r, c+1, ' ');
		refresh();
	}
}
Example #4
0
int main(void)
{
	int rows,cols;

	initscr();
	getmaxyx(stdscr,rows,cols);
	rows--;
	cols--;

	move(0,0);		/* UL corner */
	addch('*');
	refresh();
	napms(500);			/* pause half a sec. */

	move(0,cols);		/* UR corner */
	addch('*');
	refresh();
	napms(500);

	move(rows,0);		/* LL corner */
	addch('*');
	refresh();
	napms(500);

	move(rows,cols);	/* LR corner */
	addch('*');
	refresh();
	getchar();

	endwin();
	return 0;
}
Example #5
0
/* Performs an enemy attack on a player */
void enemyAttack(ENEMY the_enemy, int round) {
    int inRoll = 0;
    int attack_result = 0;
    int damage = 0;

    battleStats(the_enemy,round);
    mvwprintw(win,10,3,"The %s attacks %s with a %s...",the_enemy.enemy_name,player.player_name,weapons[the_enemy.e_weapon].weapon_name);
    napms(500);
    inRoll = rollDie(1,20);

    if (inRoll == 1) mvwprintw(win,11,5,"...the %s misses!",the_enemy.enemy_name);

    attack_result = inRoll + the_enemy.str;
    if (inRoll == 20 || attack_result > (player.def + player.armor)) {

        damage = (the_enemy.str + weapons[the_enemy.e_weapon].basehit + rollDie(1,weapons[the_enemy.e_weapon].base_str)) - (player.def + player.armor);
        if (damage <= 0) {
            mvwprintw(win,11,5,"...the strike glances off %s's armor",player.player_name);
        } else {
            mvwprintw(win,11,5,"...the %s deals %i damage to %s!",the_enemy.enemy_name,damage,player.player_name);
            player.hp -= damage;
        }
    } else {
        mvwprintw(win,11,5,"...the %s misses!",the_enemy.enemy_name);
    }

    wrefresh(win);
    napms(500);
}
Example #6
0
int roll()
{
	int by=23,bx=6,pow,dir,t=0,last=clock(),xmod=0,dmod=0;
	float tcount = CLOCKS_PER_SEC /8;
	mvaddch(by,bx+2,'o'|COLOR_PAIR(COLOR_GREEN));
	dir=direct();
	pow=power();
	while(1)
	{
		t=clock()-last;
        if(t>=tcount)
        {
  			xmod=(dir==0)?48:(dir==-1||dir==1)?10:5;
  			dmod=(dir==0)?rand()%3-1:(dir>0)?1:-1;
  			mvaddch(by,bx+2,board[by][bx]);
  			if(rand()%xmod==0)
  			{
  				bx+=dmod;
  				if(bx==0)
  				{bx=1;dir=1;}
  				if (bx==12)
  				{bx=11;dir=-1;}
  			}

			--by;
			mvaddch(by,bx+2,'o'|COLOR_PAIR(COLOR_GREEN));
			refresh();
			last=clock();
			if(by==0||--pow==0)
			{
				if(by>=9&&by<=23)
				{
					while(by>=9&&by<=23)
					{
						mvaddch(by,bx+2,board[by][bx]);
						by++;
						mvaddch(by,bx+2,'o'|COLOR_PAIR(COLOR_GREEN));
						refresh();
						napms(200);
					}
						dir=direct();
						pow=power();
						by=23;
						mvaddch(by,bx+2,'o'|COLOR_PAIR(COLOR_GREEN));
						refresh();
						continue;
				}
				napms(1000);
				mvaddch(by,bx+2,board[by][bx]);
				if(by==0||by==8){return 0;}
				if(bx==1||bx==11||by==1||by==7){return 1;}
				if(by==2||by==3||by==6){return 2;}
				if(bx==6){return 4;}
				return 3;
			}
		}

	}
}
static void
scrollTest(WINDOW *win)
{
    int i;
    int half;
    int OldY;
    NCURSES_CONST char *Message = "The window will now scroll slowly";

    wclear(win);
    OldY = getmaxy(win);
    half = OldY / 2;
    MvWAddStr(win, OldY - 2, 1, Message);
    wrefresh(win);
    scrollok(win, TRUE);
    for (i = 1; i <= OldY; i++) {
	napms(600);
	scroll(win);
	wrefresh(win);
    }

    werase(win);
    for (i = 1; i < OldY; i++) {
	MvWPrintw(win, i, 1, "Line %d", i);
    }
    MvWPrintw(win, OldY - 2, 1, "The top of the window will scroll");
    wmove(win, 1, 1);
    wsetscrreg(win, 0, half - 1);
    box(win, ACS_VLINE, ACS_HLINE);
    wrefresh(win);
    for (i = 1; i <= half; i++) {
	napms(600);
	scroll(win);
	box(win, ACS_VLINE, ACS_HLINE);
	wrefresh(win);
    }

    werase(win);
    for (i = 1; i < OldY; i++) {
	MvWPrintw(win, i, 1, "Line %d", i);
    }
    MvWPrintw(win, 1, 1, "The bottom of the window will scroll");
    wmove(win, OldY - 2, 1);
    wsetscrreg(win, half, --OldY);
    box(win, ACS_VLINE, ACS_HLINE);
    wrefresh(win);
    for (i = half; i <= OldY; i++) {
	napms(600);
	wscrl(win, -1);
	box(win, ACS_VLINE, ACS_HLINE);
	wrefresh(win);
    }
    wsetscrreg(win, 0, OldY);
}
Example #8
0
void scrollTest(WINDOW *win)
{
    int i, OldY;
#ifndef PDCURSES
    int OldX;
#endif
    werase(win);
    mvwaddstr(win, height - 2, 1, "The window will now scroll slowly");
    box(win, ACS_VLINE, ACS_HLINE);
    wrefresh(win);
    scrollok(win, TRUE);
    napms(500);

    for (i = 1; i <= height; i++)
    {
        napms(150);
        scroll(win);
        wrefresh(win);
    };

#ifdef PDCURSES
    OldY = getmaxy(win);
#else
    getmaxyx(win, OldY, OldX);
#endif
    mvwaddstr(win, 6, 1, "The top of the window will scroll");
    wmove(win, 1, 1);
    wsetscrreg(win, 0, 4);
    box(win, ACS_VLINE, ACS_HLINE);
    wrefresh(win);

    for (i = 1; i <= 5; i++)
    {
        napms(500);
        scroll(win);
        wrefresh(win);
    }

    mvwaddstr(win, 3, 1, "The bottom of the window will scroll");
    wmove(win, 8, 1);
    wsetscrreg(win, 5, --OldY);
    box(win, ACS_VLINE, ACS_HLINE);
    wrefresh(win);

    for (i = 5; i <= OldY; i++)
    {
        napms(300);
        wscrl(win, -1);
        wrefresh(win);
    }

    wsetscrreg(win, 0, OldY);
}
Example #9
0
static void
AutoMove(int From, int To, int Num)
{
    if (Num == 1) {
	MakeMove(From, To);
	napms(500);
	return;
    }
    AutoMove(From, OTHER(From, To), Num - 1);
    MakeMove(From, To);
    napms(500);
    AutoMove(OTHER(From, To), To, Num - 1);
}
Example #10
0
int
main ()
{
  printf
    ("At the end of this line you will see the cursor, process will sleep for 5 seconds.");
  napms (5000);
  curs_set (0);
  printf
    ("\nAt the end of this line you will NOT see the cursor, process will again sleep for 5 seconds.");
  napms (5000);
  printf ("\nGoodbye.");
  return 0;
}
Example #11
0
/**
Forks things.

@return 0 if successful and -1 otherwise.
**/
int init_fork(void) {
	/*
	Creates a process monitor to avoid accidental daemonization.
	*/
	const pid_t child_pid = fork();
	if (child_pid == -1) {
		probno = log_error(FORK_PROBLEM);
		return -1;
	}
	else {
		pid = getpid();
		if (child_pid == 0) {//child
			shm_attach();

			/*
			Synchronizes with the parent process.
			*/
			while (shared.pids[0] != pid);

			return NO_PROBLEM;
		}
		else {//parent
			*shared.ppid = pid;
			shared.pids[0] = child_pid;

			/*
			Prevents defunct processes from appearing.
			*/
			signal(SIGCHLD, SIG_IGN);

			while (*shared.state != HAD_ENOUGH) {
				napms(NAP_RESOLUTION / frame_rate);
			}
			do {
				bool done_quitting = TRUE;
				for (int save = 0; save < cfg_saves; save++) {
					if (shared.pids[save] != 0) {
						done_quitting = FALSE;
					}
				}
				if (done_quitting) break;
				napms(NAP_RESOLUTION / frame_rate);
			} while (TRUE);
			uninit(TRUE);
			exit(NO_PROBLEM);
		}
	}

	return 0;
}
Example #12
0
File: haino.c Project: shixv/test
    static int
GetMove(int *From, int *To)
{
    attrset(A_REVERSE);
    mvaddstr(LINES-1, 20,"<Q>/<q> 退出       <1>-<3> 移动");
    attrset(A_NORMAL);
    mvaddstr(STATUSLINE, 0, "下一步: 从 ");
    clrtoeol();
    refresh();
    *From = getch();
    if ((*From == 'q')||(*From == 'Q') )return TRUE;
    *From -= ('0' + 1);
    addstr(" 到 ");
    clrtoeol();
    refresh();
    *To = getch();
    if ((*To == 'q') || (*To == 'Q'))return TRUE;
    *To -= ('0' + 1);
    refresh();
    napms(500);
    move(STATUSLINE, 0);
    clrtoeol();
    refresh();
    return FALSE;
}
Example #13
0
void flash_entity(struct entity *ent) {
    move(ent->pos.y + 1, ent->pos.x + 1);
    addch(' ');
    move(HEIGHT + 2, 0);
    refresh();
    napms(32);
}
Example #14
0
void modificaTeritoriu(char t, int culoare)
{
	int i, j, muta, aFost;
	attrset(COLOR_PAIR(culoare));
	for (i=0; i<HLIN; i++)
	{
		aFost = 0;
		muta = 1;
		for (j=0; j<HCOL; j++)
			if (toupper(liniiHarta[i][j]) == t)
			{
				if (muta) move(i+START_LIN, j+START_COL);
				if (!(liniiHarta[i][j] & 32)) addch(' ');
				else addch(t);
				muta = 0;
				aFost = 1;
			}
			else muta = 1;
		if (aFost)
		{
			CAPAT();
			refresh();
			napms(60);
		}
	}
	CAPAT();
	refresh();
}
Example #15
0
void afiseazaRaspunsGrila(int corect, int j1, int j2, int j3)
{
	conturColorat(START_AFISR_LIN, START_AFISR_COL, 7, 50, COL_INTREBARE);
	chenarColorat(START_AFISR_LIN + 1, START_AFISR_COL + 1, 5, 48, COL_FUNDAL_INTREBARE, "");
	mvprintw(START_AFISR_LIN + 1, START_AFISR_COL + 3, "Raspunsul corect este: %c)", 'a' + (char)(corect-1));

	attrset(COLOR_PAIR(COL_J1));
	move(START_AFISR_LIN + 3, START_AFISR_COL + 1);
	if (j1) printw("Jucatorul 1:   %c)          ", 'a' + (char)(j1-1));
	else printw("Jucatorul 1:   nu a raspuns");

	attrset(COLOR_PAIR(COL_J2));
	move(START_AFISR_LIN + 4, START_AFISR_COL + 1);
	if (j2) printw("Jucatorul 2:   %c)          ", 'a' + (char)(j2-1));
	else printw("Jucatorul 2:   nu a raspuns");
	
	attrset(COLOR_PAIR(COL_J3));
	move(START_AFISR_LIN + 5, START_AFISR_COL + 1);
	if (j3) printw("Jucatorul 3:   %c)          ", 'a' + (char)(j3-1));
	else printw("Jucatorul 3:   nu a raspuns");

	CAPAT();
	refresh();
	napms(4000);
}
Example #16
0
void *drop_bombs(void *arg) {
    Block *block;
    block = (Block *) arg;
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
    pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
    int rand_wait_time;
    int bomb_position;
    Block *bomb;
    srand(time(NULL));
    while(1) {
        pthread_t *pid = malloc(sizeof(pthread_t));
        bomb = malloc(sizeof(Block));
        while(1) {
            bomb->col = (rand() % block->screen_width);
            pthread_mutex_lock(&mutex);
            if(block->cols[bomb->col] == 0) {
                block->cols[bomb->col] = 1;
                break;
            }
            pthread_mutex_unlock(&mutex);
        }
        pthread_mutex_unlock(&mutex);
        bomb->row = 2;
        bomb->screen_height = block->screen_height;
        bomb->screen_width = block->screen_width;
        bomb->block = block;
        pthread_mutex_lock(&mutex);
        bomb->cols = block->cols;
        rand_wait_time = (rand() % 4 + 1) * speed; // wait is between 1 and 3 seconds
        pthread_create(pid, NULL, create_bomb, (void *) bomb);
        pthread_mutex_unlock(&mutex);
        pthread_testcancel();
        napms(rand_wait_time);
    }
}
Example #17
0
int main(int argc, char* argv[])
{
    STATE* state;

    state = Init(argc, argv);
    if (!state) {
        fprintf(stderr, "<ntetris>\tCould not initialize state.  Abort.\n");
        return 0;
    }

    while(state->status != STATUS_GAMEOVER) {
        state->ticks ++;

        Input(state);
        Update(state);
        Paint(state);
        Refresh(state);

        napms(REFRESH_DELAY);
    }

    Cleanup(state);

    return 0;
}
Example #18
0
static int
GetMove(int *From, int *To)
{
    MvAddStr(STATUSLINE, 0, "Next move ('q' to quit) from ");
    clrtoeol();
    refresh();
    if ((*From = getch()) == 'q')
	return TRUE;
    *From -= ('0' + 1);
    addstr(" to ");
    clrtoeol();
    refresh();

    if ((*To = getch()) == 'q')
	return TRUE;
    *To -= ('0' + 1);
    refresh();
    if (!AutoFlag)
	napms(500);

    move(STATUSLINE, 0);
    clrtoeol();
    refresh();
    return FALSE;
}
Example #19
0
void winner(void) {
    WINDOW *win = newwin(0, 0, 0, 0);
    char *logname = getenv("LOGNAME");
    char ending[] = "You are a true stardork.";
    char won_msg[255];
    int fr, i;
    fr = i = 0;

    wattrset(win, A_BOLD);
    box(win, ' ', ' ');
    sprintf(won_msg, "You win %s, in %d moves", (logname ? logname : " "), hud.moves);
    mvwprintw(win, 4, (COLS / 2) - strlen(won_msg) / 2, "%s", won_msg);

    srand((unsigned)time(NULL));
    for (i = 0; i < sizeof(ending); i++) {
        fr = (rand() % 550) + 100;
        sndon(fr);
        mvwprintw(win, 12, i + ((COLS / 2) - 12), "%c", ending[i]);
        napms(200);
        wrefresh(win);
    }
    sndoff();
    wgetch(win);
    wattrset(win, A_NORMAL);
    wrefresh(win);
    flushinp();
    endwin();
    exit(0);
}
Example #20
0
int	main() {
  int		c = 0;
    
  //  if (ac > 1 && (std::string(av[1]) == std::string("-t"))) {
    Monitor	m(false);

    my_init_curs();
    timeout(0);
    while (true) {
      m.refresh();
      m.display();
      if (c == 27) {
	my_deinit_curs();
	return 0;
      }
      napms(1000);
      c = getch();
    }
    my_deinit_curs();
    /*  }
  else {
    //ajouter fonction Qt de folie
    Monitor	m(true);
    while (true) {
      m.refresh();
      m.display();
      if (c == 27) {
	return 0;
      }
      napms(1000);
      c = getch();
      }
  }*/
  return 0;
}
Example #21
0
static void
PutChar(int ch)
{
    putchar(ch);
    fflush(stdout);
    napms(moveit ? 10 : 50);	/* not really termcap... */
}
Example #22
0
int delay_output(int ms)
{
	T((T_CALLED("delay_output(%d)"), ms));

	if (cur_term == 0 || cur_term->_baudrate <= 0) {
		(void) fflush(OUTPUT);
		_nc_timed_wait(0, ms, (int *)0);
	}
#ifdef no_pad_char
	else if (no_pad_char)
		napms(ms);
#endif /* no_pad_char */
	else {
		register int	nullcount;
		char	null = '\0';

#ifdef pad_char
		if (pad_char)
			null = pad_char[0];
#endif /* pad_char */

		nullcount = ms * cur_term->_baudrate / 10000;
		for (_nc_nulls_sent += nullcount; nullcount > 0; nullcount--)
			my_outch(null);
		if (my_outch == _nc_outch)
			(void) fflush(OUTPUT);
	}

	returnCode(OK);
}
Example #23
0
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;
}
Example #24
0
void slowerase(int y,int x,char * message){
  move(y,x);
  attroff(A_BOLD);
  while(*message){
    mvaddch(y,x,*(message));
    refresh();
    napms(45);
    mvaddch(y,x,' ');
    x++;
    refresh();
    if(*(message++)==' ')
      napms(15);
    else
      napms(35);
  }
  attroff(A_BOLD);
}
Example #25
0
void slowrite(int y,int x,char * message){
  while(*message){
    attroff(A_BOLD);
    mvaddch(y,x,*(message));
    refresh();
    napms(50);
    attron(A_BOLD);
    mvaddch(y,x,*(message));
    x++;
    refresh();
    if(*(message++)==' ')
      napms(20);
    else
      napms(40);
  }
  attroff(A_BOLD);
}
Example #26
0
static void catch_sigint(int signo) {
    mvprintw(5, 10, "Bye Bye!\n", 11);
    attrset(A_NORMAL);
    refresh();
    napms(100);
    endwin();
    exit(0);
}
Example #27
0
File: nap.c Project: downsj2/ularn
/*
 *	routine to take a nap for n milliseconds
 */
void nap(int x)
{
	if (x<=0 || nonap)
		return; /* eliminate chance for infinite loop */
	lflush();
	if (x > 999) 
		sleep ((int)(x/1000));
	else napms(x);
}
Example #28
0
void *guestFunc(void* i)
{
    int arg = * (int*) i;
	while(1)
	{
		visit[arg][1]=1;
        pthread_mutex_lock(&refr);
		visit[arg][1]=2;
		napms(5000);
		if(ownerdo==0)
		pthread_mutex_unlock(&refr);
		visit[arg][1]=3;
		napms(10000);
 		--nbotle_refr;
		++visit[arg][2];
		if(visit[arg][2]==10) {visit[arg][1]=4; napms(120000);}
	}
}
Example #29
0
static void
look_out(int msecs)
{
	napms(msecs);
	if (getch() != ERR) {
		beep();
		done(0);
	}
}
Example #30
0
void showEncounter() {
    wclear(encounterwin);
    wbkgd(encounterwin,COLOR_PAIR(4) | A_BOLD);
    box(encounterwin,ACS_VLINE,ACS_HLINE);
    mvwprintw(encounterwin,1,1,"!!! ENCOUNTER !!!");
    wrefresh(encounterwin);
//    wgetch(encounterwin);
    napms(1500);
    doBattle();
}