Exemplo n.º 1
0
/*referee_restart_game( )
*	function to 'reload' the ball sleeve, and set the ticker a-runnin.
*	Don't need to protect drawing here, cause we'll stop the ticker and
*	just brute force the cleanup. 
*
*/
void referee_restart_game()
{
	
	//Stop the ticker, just in case
	set_ticker(0);
	
	//Blank out the fin message area
	mvaddstr(y_fin, x_fin, BLANK_MSG);
	mvaddstr(y_fin + 1, x_fin, BLANK_MSG);
	mvaddstr(y_fin + 2, x_fin, BLANK_MSG);
	refresh();

	//Reset the ball count
	ball_count = STARTING_BALL_COUNT;
	jmbtrn_display_ball_count(ball_count);
	
	//Reset the timer
	jmbtrn_zero_clock_display();
	
	//re-serve the ball
	ball_serve();
	
	//start the ticker
	if ( set_ticker( 1000 / (TICK_PER_SEC) ) == -1 ){
		set_in_error();
	}
	
}
Exemplo n.º 2
0
int main()
{
	welcom();
	tty_mode(0);//储存TTY的模式
	initscr();
	crmode();
	noecho();
	clear();
	box(stdscr,'|','-');
	mvaddch(pos_x,pos_y,BALL);
	bpos_x=LINES-4;
	bpos_y=4;
	mvaddstr(bpos_x,bpos_y,BAN);
	move(LINES-1,COLS-1);			//移动光标到右下角
	refresh();
	signal(SIGALRM,jmove);
	delay=50;	//200ms=0.2s
	if(set_ticker(delay) == -1)
		perror("set_ticker");
	else
		while(1)
		{
			ndelay = 0;
			c=getch();
			if(c=='Q') break;
			if(c=='f' && delay > 2) ndelay = delay/2;
			if(c=='s') ndelay = delay*2;
			if(c==' ') bdir_y=-bdir_y;
			if(ndelay > 0) set_ticker (delay = ndelay);
			//重置定时器
		}
}
Exemplo n.º 3
0
main()
{
    void on_alarm(int);     // handler for alarm
    void on_input(int);     // handler for keybd
    void enable_kbd_signals();

    initscr();
    crmode();
    noecho();
    clear();

    signal(SIGIO, on_input);        // install the handler
    enable_kbd_signals();
    signal(SIGALRM, on_alarm);
    set_ticker(delay);              // start ticking

    move(row, col);
    addstr(MESSAGE);

    while (1)
    {
        if (done == 1) break;
        pause();
    }
    endwin();
}
Exemplo n.º 4
0
int
main(int argc, char *argv[])
{
	tty_mode(0);
	set_cr_noecho_mode();
	initscr();
	clear();


	signal(SIGINT, sigint_handler);
	signal(SIGIO, on_input);	/* install input handler */
	setup_aio_buffer();		/* initialize aio ctrl buff */
	aio_read(&kbcbuf);		/* place a read request */

	signal(SIGALRM, on_alarm);	/* install alarm handler */
	set_ticker(delay);		/* start ticking */


	move(row, col);
	addstr(MSG);


	while (!done) {
		pause();
	}

	tty_mode(1);
	endwin();

	return 0;
}
Exemplo n.º 5
0
void set_up()
/*
 * init structure and other stuff
 * */
{
	void ball_move(int);

	the_ball.y_pos = Y_INIT;
	the_ball.x_pos = X_INIT;
	the_ball.y_ttg = the_ball.y_ttm = Y_TTM;
	the_ball.x_ttg = the_ball.x_ttm = X_TTM;
	the_ball.y_dir = 1;
	the_ball.x_dir = 1;
	the_ball.symbol = DFL_SYMBOL;

	initscr();
	noecho();
	crmode();

	signal( SIGINT, SIG_IGN);	/* ignore the ^C signal */
	mvaddch( the_ball.y_pos, the_ball.x_pos, the_ball.symbol);
	refresh();

	signal( SIGALRM, ball_move);
	set_ticker( 1000/ TICKS_PER_SEC);
		/* send millisecs per tick */
}
Exemplo n.º 6
0
int main(void)
{
     char c;
     setup();
     signal(SIGALRM,snake_show);
     set_ticker(200);
     snake_show_or_hide(BLANK);
     while(1)
     {
	  c= getch();
	  if(c== 'q') break;
	  if(c== 's' && dir_y == DIR_DEFAULT) {

	       dir_x = DIR_DEFAULT;
	       dir_y = DIR_POSITIVE;
	  }
	  if(c== 'w' && dir_y == DIR_DEFAULT){
	       dir_x = DIR_DEFAULT;
	       dir_y = DIR_NEGATIVE;   
	  }
	  if(c == 'a' && dir_x == DIR_DEFAULT){
	       dir_x = DIR_NEGATIVE;
	       dir_y = DIR_DEFAULT;
	  }
	  if(c == 'd' && dir_x == DIR_DEFAULT){
	       dir_x = DIR_POSITIVE;
	       dir_y = DIR_DEFAULT;
	  }
	  
     }
     endwin();
     return 0;
     
}
Exemplo n.º 7
0
extern void set_up() {
  the_ball.x_pos = X_INIT_POS;
  the_ball.y_pos = Y_INIT_POS;
  the_ball.x_ttm = the_ball.x_ttg = X_TIM;
  the_ball.y_ttm = the_ball.y_ttg = Y_TIM;
  the_ball.x_dir = 1;
  the_ball.y_dir = 1;
  the_ball.symbol = BALL_SYMBOL;

  the_bar.top_y = BAR_TOP_Y;
  the_bar.bottom_y = BAR_BOTTOM_Y;
  the_bar.dir = BAR_STOP;

  initscr();
  noecho();
  cbreak();

  signal(SIGALRM, SIG_IGN);
  mvaddch(the_ball.y_pos, the_ball.x_pos, the_ball.symbol);
  for (int i = the_bar.top_y; i <= the_bar.bottom_y; ++i)
    mvaddch(i, RIGHT_EDGE, BAR_SYMBOL);
  refresh();

  signal(SIGALRM, b_move);
  set_ticker(1000 / TICKS_PER_SEC);
}
Exemplo n.º 8
0
Arquivo: Bem.c Projeto: flack3r/Snake
int DrawBem(int x,int y,int StageMap[STAGE_ROW][STAGE_COL]){	//start game
	char c;
	CurrentMap = StageMap;
	delay = 200;

	signal(SIGALRM,whileBem);
	set_ticker(delay);
	setup(x,y);
	
	while(1){
		if((c=getchar()) == 'Q') break;
		else if( c == 'w')	{dir_x=0; dir_y=-1;}
		else if( c == 'a')	{dir_x=-1; dir_y=0;}
		else if( c == 's')	{dir_x=0; dir_y=1;}
		else if( c == 'd')	{dir_x=1; dir_y=0;}
		else if(c == 'x' && game_result == LOSE){ //게임 패배
			break;
		}
		else if(c == 'z' && game_result == WIN) // 게임 클리어
		{
			break;
		}
	}

	return game_result;	//이겼을 경우 0인가 1인가에 따라 승리화면과 패배화면을 출력하도록값을 넘겨줌 
}
Exemplo n.º 9
0
void set_up()
{
    theball.y_pos = Y_INIT;
    theball.x_pos = X_INIT;

    theball.y_ttg = theball.y_ttm = Y_TTM;
    theball.x_ttg = theball.x_ttm = X_TTM;

    theball.y_dir = 1;
    theball.x_dir = 1;

    theball.symbol = DEL_SYMBOL;

    thebaffles.length = BAFFLE_LEN;
    thebaffles.x_baffle_pos = RIGHT_EDGE - (RIGHT_EDGE - LEFT_EDGE) / 2 - BAFFLE_LEN / 2;
    thebaffles.y_baffle_pos = BOTTOM_ROW - (BOTTOM_ROW - TOP_ROW) / 2 - BAFFLE_LEN / 2;

    initscr();
    noecho();
    crmode();

    signal(SIGINT, SIG_IGN);

    draw_baffles();

    mvaddch(theball.y_pos, theball.x_pos, theball.symbol);
    refresh();

    signal(SIGALRM, refresh_draw);

    set_ticker(1000 / TICKS_PER_SEC);
}
Exemplo n.º 10
0
void key_control()
{
	char key_in = getch();
	switch (key_in)
	{
		case 'w':					//上
		case 'W':
			{
				dir_x = 0;
				dir_y = -1;
			};break;
		case 's':					//下
		case 'S':
			{
				dir_x = 0;
				dir_y = 1;
			};break;
		case 'a':					//左
		case 'A':
			{
				dir_x = -1;
				dir_y = 0;
			};break;	
		case 'd':					//右
		case 'D':
			{
				dir_x = 1;
				dir_y = 0;
			};break;
		case CHAR_BLANK:
			{
				set_ticker(0);		//停止发送信号,蛇不会自动更新
				while (getch() != CHAR_BLANK)
				{

				}
				set_ticker(100);
			};break;
		case 'q':
		case 'Q':
			{
				game_over();
			}
		default:break;
	}
}
Exemplo n.º 11
0
void
sigint_handler(int sig)
{
	tty_mode(1);
	set_ticker(0);
	endwin();
	exit(0);
}
Exemplo n.º 12
0
int main(int argc, char const *argv[])
{
  int c;

  col = 0;
  row = 10;
  dir = 1;

  initscr();
  clear();
  // move(row, col);
  // addstr(msg);

  signal(SIGALRM, move_message);
  set_ticker(delay);

  while(1)
  {
    c = getch();
    if (c == 'q')
    {
      break;
    }
    else if (c == 's')
    {
      delay *= 2; 
    }
    else if (c == ' ')
    {
      dir *= -1;
    }
    else if (c == 'f')
    {
      delay /= 2;
    }

    set_ticker(delay);
  }

  endwin();
  return 0;
}
Exemplo n.º 13
0
int main()
{
    void countdown(int);
    signal(SIGALRM, countdown);
    if (set_ticker(500) == -1) {
        perror("set_ticker");
    } else {
        while(1)
            pause();
    }
}
Exemplo n.º 14
0
int main()
{
    void countdown(int);

    signal(SIGALRM, countdown);
    if (set_ticker(500) == -1)
        perror("set_ticker");
    else
        while(1)
            pause();
    return 0;
}
int main(void) {
  signal(SIGALRM, countdown);

  if (set_ticker(500) == -1) {
    perror("set_ticker");
    exit(EXIT_FAILURE);
  }
  else {
    while (true)
      pause();
  }
  return EXIT_SUCCESS;
}
Exemplo n.º 16
0
int
main(void)
{
    int delay;
    int ndelay;
    int c;
    void move_msg(int);
    int set_ticker(int);

    initscr();
    crmode();
    noecho();
    clear();

    row = 10;
    col = 0;
    dir = 1;
    delay = 200;

    move(row,col);
    addstr(MESSAGE);
    signal(SIGALRM,move_msg);
    set_ticker(delay);

    while(1)
    {
            ndelay = 0;
            c = getchar();
            if (c == 'Q') break;
            if (c == ' ')dir = -dir;
            if (c == 'f' && delay > 2) ndelay = delay/2;
            if (c == 's') ndelay = delay * 2;
            if (ndelay > 0)
                set_ticker(delay = ndelay);
            }
    endwin();
    return 0;
}
Exemplo n.º 17
0
/*referee_end_game( )
*	method to end the game when no balls are left. Displays a
*	message in the center of the court and allows user to "play again" with 
*	the 'r' key, or quit with 'Q'
*
*/
void referee_end_game()
{

	//Stop the ticker
	set_ticker(0);
	
	//Display an end game message
	mvaddstr(y_fin, x_fin, BLANK_MSG);
	mvaddstr(y_fin + 1, x_fin, BLANK_MSG);
	mvaddstr(y_fin + 2, x_fin, BLANK_MSG);
	mvaddstr(y_fin, x_fin, FIN_MSG);
	mvaddstr(y_fin + 1, x_fin, PLAY_AGAIN_MSG);
	mvaddstr(y_fin + 2, x_fin, DONE_MSG);
	
	refresh();
	
}
Exemplo n.º 18
0
void set_up()
{

	initscr();		   /* turn on curses	*/
	noecho();		   /* turn off echo	*/
	cbreak();		   /* turn off buffering	*/
	srand( getpid() ); /*seed the random num generator*/

	signal(SIGINT, SIG_IGN);	/* ignore SIGINT	*/
	signal(SIGTERM, SIG_IGN);	/* ignore SIGINT	*/
	
	//Draw the court
	court_init( 3 );
	
	//Init the scoreboard display
	ppcourt_geom court_g;
	court_geom( &court_g );
	jmbtrn_init( court_g.top - 1, court_g.left + 1 ); /*Init's clock to 0*/
	jmbtrn_display_ball_count( STARTING_BALL_COUNT );
	
	//Init the referee
	referee_init();
	
	//Init the paddle
	paddle_init( );
	
	//Init and serve the ball
	ball_init( );
	
	//Create a sigaction with "handle_tick" as the handler
	struct sigaction tick_handler;
	tick_handler.sa_handler = handle_tick;
	tick_handler.sa_flags |= SA_RESTART; 	/*Make sure to restart sys calls*/
	if ( sigaction( SIGALRM, &tick_handler, NULL ) == -1 ){
		perror( "Sigaction" );
		exit( 1 );
	}else{
		if ( set_ticker( 1000 / (TICK_PER_SEC) ) == -1 ){/* send millisecs per tick */
			perror( "Error setting ticker" );
			exit( 1 );
		}	
	}
	
	
}
Exemplo n.º 19
0
void set_up( void )
{
  the_ball.y_pos = Y_INT;
  the_ball.x_pos = X_INT;
  the_ball.y_ttg = the_ball.y_ttm = Y_TTM;
  the_ball.x_ttg = the_ball.x_ttm = X_TTM;
  the_ball.y_dir = 1;
  the_ball.x_dir = 1;
  the_ball.symbol = DEF_SYMBOL;

  initscr();
  noecho();
  crmode();

  signal( SIGINT, SIG_IGN );
  mvaddch( the_ball.y_pos, the_ball.x_pos, the_ball.symbol );
  refresh();

  signal( SIGALRM, ball_move );
  set_ticker( 1000 / TICKS_PER_SEC );
}
Exemplo n.º 20
0
void set_up()
{
   ball.y_pos = Y_INIT;
   ball.x_pos = X_INIT;
   ball.y_ttg = ball.y_ttm = Y_TTM;
   ball.x_ttg = ball.x_ttm = X_TTM;
   ball.y_dir = 1;
   ball.x_dir = 1;
   ball.symbol = DFL_SYMBOL;

   initscr();
   noecho();
   crmode();

   signal( SIGINT, SIG_IGN );
   mvaddch( ball.y_pos, ball.x_pos, ball.symbol );
   refresh();

   signal( SIGALRM, ball_move );
   set_ticker( 1000 / TICKS_PER_SEC );
}
Exemplo n.º 21
0
void init(){
    int i,j;
    clear();
    if(start_color()==OK){  /*改变球和挡板的颜色*/
        attron(A_BOLD);  /*打开粗体*/
        init_pair(1,COLOR_YELLOW,COLOR_BLACK);
        attron(COLOR_PAIR(1));
    }
    //初始球
    pos_X =22;  /*球初始的横坐标*/
    pos_Y = BOTTOM-1;  /*球初始的纵坐标*/
    //初始化球的运动方向,朝右上方运动
    hdir=1; 
    vdir=-1;
 
    //初始挡板
    left_board=20;
    right_board=left_board+BOARD_LENGTH;
    for(i=left_board;i<=right_board;i++){  /*显示挡板*/
        move(BOTTOM,i);
        addch('-');
    }
 
    //初始刷新时间
    signal(SIGALRM,moveBall);
    set_ticker(delay);
 
    keypad(stdscr,TRUE);  /*打开 keypad 键盘响应*/
    attroff(A_BLINK);     /*关闭 A_BLINK 属性*/
     
    is_lose=0;
    move(pos_Y,pos_X);
    addch(BALL);
    move(LINES-1, COLS-1);
    refresh();
    usleep(100000);  /*睡眠*/
    move(LINES-1,COLS-1);
    refresh();
}
Exemplo n.º 22
0
void init()
{
	initscr();
	cbreak();
	noecho();
	curs_set(0);
	srand(time(0));

	dir_x = 1;
	dir_y = 0;
	
	head = (snake_tp)malloc(sizeof(snake_t));		//分配节点
	tail = (snake_tp)malloc(sizeof(snake_t));
	head->next = tail;
	tail->prev = head;
	head->x = rand() % WINDOW_RIGHT + 1;
	head->y = rand() % WINDOW_BOTTOM + 1;
	tail->x = head->x - dir_x;
	tail->y = head->y - dir_y;

	int temX, temY;
	do												//为食物分配坐标
	{
		temX = rand() % WINDOW_RIGHT;
		temY = rand() % WINDOW_BOTTOM;
		move(temX, temY);
	}while ( (char)inch() == CHAR_SNAKE);
	food.x = temX;
	food.y = temY;

	move(food.x, food.y);							//绘制食物
	addch(CHAR_FOOD);
	refresh();
	
	signal(SIGALRM, sig_alrm);						//将时钟信号和自定义函数进行关联
	set_ticker(100);								//设置定时器,0.5m后执行自定义函数

}
Exemplo n.º 23
0
void move_message(int signum)
{
  move(row, col - dir);
  addstr(blank);

  move(row, col);
  addstr(msg);

  move(LINES - 1, 0);
  col += dir;
  // move(row, col + 1);
  refresh();
  if (dir > 0 && col + strlen(msg) >= COLS)
  {
    dir = -1;
  }
  else if (dir < 0 && col <= 0)
  {
    dir = 1;
  }

  set_ticker(delay);
}
Exemplo n.º 24
0
int main(int argc, char **argv) {
	void on_alarm(int);
	void on_input(int);
	void enable_kbd_signals();
	int set_ticker(int);

	initscr();
	crmode();
	noecho();
	clear();
	
	signal(SIGIO, on_input);
	enable_kbd_signals();
	signal(SIGALRM, on_alarm);
	set_ticker(delay);

	move(row, col);
	addstr(MESSAGE);
	while (!done){
		pause();
	}
	endwin();
	return 0;
}
Exemplo n.º 25
0
void sig_alrm(int sigo)
{
	set_ticker(100);
	snake_move();
}
Exemplo n.º 26
0
/* stop ticker and curses */
void wrap_up()
{
	set_ticker( 0 );
	endwin();		/* put back to normal	*/
}
Exemplo n.º 27
0
void wrap_up()
{
    set_ticker(0);
    endwin();
}
Exemplo n.º 28
0
Arquivo: Bem.c Projeto: flack3r/Snake
// 충돌 이벤트 발생 처리 (이기고 지느냐에 따라 game_result값 결정)
void CheckEvent()
{
	int y,x;
	// 머리 부분 좌표
	int Bem_x = 0;
	int Bem_y = 0;

	if(reverse == 0)
	{
		Bem_x = Head->pos_x;
		Bem_y = Head->pos_y;
	}
	else
	{
		Bem_x = Tail->pos_x;
		Bem_y = Tail->pos_y;
	}

	for(y=0;y<STAGE_ROW;y++)
	{
		for(x=0;x<STAGE_COL;x++)
		{
			//벽인 경우 벰이 부딛혔는지 체크
			if(CurrentMap[y][x] == WALL)
			{
				if(CheckTouchWall(x,y) == 1)
				{
					// mvprintw(10,55,"Bem head x %2d, head y %2d",Bem_x,Bem_y);
					// mvprintw(23,50,"Wall !! %d",count++);
					mvprintw(10,55,"You die. Enter 'x' key");
					refresh();
					game_result = LOSE;
					GameOver();
				}
			}
			//먹이 먹은 경우
			else if(CurrentMap[y][x] == FOOD)
			{
				//뱀의 머리 부분이 닿을 경우
				if(Bem_x == x && Bem_y == y)
				{
					FoodNum--;
					CurrentMap[y][x] = EMPTY;
					move(y,x);
					addstr(" ");
					addBem();


					delay = delay-20>0? delay-20: 1;
					set_ticker(delay);
					//mvprintw(10,55,"%d",FoodNum);
					//음식 다 먹은 경우 승리
					if(FoodNum == 0)
					{
						mvprintw(10,55,"Clear. Enter 'z' key");
						refresh();
						game_result = WIN;
						GameOver();
					}
				}
			}
			//Reverse Item 먹을 경우
			else if(CurrentMap[y][x] == REVERSE)
			{
				if(Bem_x == x && Bem_y == y)
				{
					CurrentMap[y][x] = EMPTY;
					move(y,x);
					addstr(" ");
					ReverseBem();
				}
			}
			//SLOW 아이템 먹을 경우
			else if(CurrentMap[y][x] == SLOW)
			{
				if(Bem_x == x && Bem_y == y)
				{
					CurrentMap[y][x] = EMPTY;
					move(y,x);
					addstr(" ");
					delay = delay+60;
					set_ticker(delay);
				}
			}
			// FAST 아이템을 먹을 경우
			else if(CurrentMap[y][x] == FAST)
			{
				if(Bem_x == x && Bem_y == y)
				{
					CurrentMap[y][x] = EMPTY;
					move(y,x);
					addstr(" ");
					delay = delay-50>0? delay-50: 1;
					set_ticker(delay);
				}
			}
			// 길이 길어지는 것
			else if(CurrentMap[y][x] == ADDBODY)
			{
				if(Bem_x == x && Bem_y == y)
				{
					CurrentMap[y][x] = EMPTY;
					move(y,x);
					addstr(" ");
					addBem();
					addBem();
					addBem();
					addBem();
					addBem();
				}
			}

		}
	}
}
Exemplo n.º 29
0
void millisleep( int n )
{
	signal( SIGALRM , my_handler);	/* set handler		*/
	set_ticker( n );			/* set alarm timer	*/
	pause();				/* wait for sigalrm	*/
}
Exemplo n.º 30
0
static void
my_handler(int s)
{
	set_ticker( 0 );			/* turns off ticker */
}