Example #1
0
int
pushsnake(void)
{
	int	i, bonus;
	int	issame = 0;
	struct point tmp;

	/*
	 * My manual says times doesn't return a value.  Furthermore, the
	 * snake should get his turn every time no matter if the user is
	 * on a fast terminal with typematic keys or not.
	 * So I have taken the call to times out.
	 */
	for (i = 4; i >= 0; i--)
		if (same(&snake[i], &snake[5]))
			issame++;
	if (!issame)
		pchar(&snake[5], ' ');
	/* Need the following to catch you if you step on the snake's tail */
	tmp.col = snake[5].col;
	tmp.line = snake[5].line;
	for (i = 4; i >= 0; i--)
		snake[i + 1] = snake[i];
	chase(&snake[0], &snake[1]);
	pchar(&snake[1], SNAKETAIL);
	pchar(&snake[0], SNAKEHEAD);
	for (i = 0; i < 6; i++) {
		if ((same(&snake[i], &you)) || (same(&tmp, &you))) {
			surround(&you);
			i = (cashvalue) % 10;
			bonus = arc4random_uniform(10);
			mvprintw(lcnt + 1, 0, "%d\n", bonus);
			refresh();
			delay(30);
			if (bonus == i) {
				spacewarp(1);
#ifdef LOGGING
				logit("bonus");
#endif
				flushinp();
				return(1);
			}
			flushinp();
			endwin();
			if (loot >= penalty) {
				printf("\nYou and your $%d have been eaten\n", cashvalue);
			} else {
				printf("\nThe snake ate you.  You owe $%d.\n", -cashvalue);
			}
#ifdef LOGGING
			logit("eaten");
#endif
			length(moves);
			snscore(TOPN);
			close(rawscores);
			exit(0);
		}
	}
	return(0);
}
Example #2
0
void end_curses()
{
    flushinp();
    erase();
    refresh();
    endwin();
}
void pollInput(Game *g)
{
    int pressed = getch();
    switch (pressed) {
    case KEY_UP:
        moveUp(g);
        break;
    case KEY_DOWN:
        moveDown(g);
        break;
    case KEY_RIGHT:
        moveRight(g);
        break;
    case KEY_LEFT:
        moveLeft(g);
        break;
    case KEY_RETURN:
        clickSquare(g);
        break;
    case KEY_SPACE:
        flagSquare(g);
        break;
    case 'l':
        logSquareInfo(g);
        break;
    case 27:
        quitWithError("game over");
        break;
    }
    flushinp();
}
Example #4
0
int main(void)
{
	WINDOW *mainw; /* An NCurses window to draw on. */
	Pile *deck; /* A deck of cards. */

	setlocale(LC_ALL, ""); /* Important for UTF-8 to print properly. */
	srandom(time(NULL)); /* Need to seed RNG for shuffling. */

	deck = standard_deck(1); /* Create a 52 card deck (1 copy). */
	shuffle_pile(&deck, &random); /* Shuffle it using standard random() */

	/* Init NCurses and setup a colour for printing our stuff. */
    if(!initscr() || start_color() == ERR)
		return 1;
	init_pair(1, COLOR_WHITE, COLOR_BLACK);
	mainw = newwin(24,80,0,0);
	clicards_init_ncurses(); /* This call to make colours work right. */
	refresh();
	flushinp();

	wattrset(mainw, COLOR_PAIR(1));
	wprintw(mainw, "%i cards:\n", num_cards(deck));
	wprint_pile(deck, mainw); /* Print the shuffled deck. */
	wrefresh(mainw);
	getch(); /* Allow user to see it before closing. */
	delwin(mainw);
	endwin(); /* Close NCurses session. */

	free_pile(deck); /* Free up memory used by deck. */
	return 0;
}
Example #5
0
int kaboom( char map[MAP_HSIZE][MAP_WSIZE] ){
  timespec req;
  req.tv_sec = 0;
  req.tv_nsec = 50000000;
  int die = 0;
  int i, ii, move;
  int iy, ix;
  char obj;
  for(i = 0; i < MAP_HSIZE; i++)
    for(ii = 0; ii < MAP_WSIZE; ii++){
      if( map[i][ii] == BOMB ){
        map[i][ii] = EMPTY;
        for( move = 0; move < MAX_MV; move++ ){
          iy =  i + dy[ move ];
          ix = ii + dx[ move ];
          if( ix >= 0 && iy >= 0 && ix < MAP_WSIZE && iy <  MAP_HSIZE ){
            obj = map[iy][ix];
            if( obj == DIRT || obj == STONE || obj == MONSTER ) map[iy][ix] = EMPTY;
            if( obj == PLAYER ) die = 1;
          }
        }    // for move

        draw_map( map, MAP_Y, MAP_X );
        refresh();
        nanosleep( &req, 0 );
      }      // if  map == BOMB
    }        // for MAP_WSIZE

  flushinp();
  return die;
}
Example #6
0
// キー入力ループ
// 
void CWindows::keyloop()
{
	flushinp();
	timeout(-1);	// キー入力で待つ

	for( ; ; )
	{
		int ch = wgetch(m_this);
		switch(ch)
		{
			case MYKEY_LEFT:
				if (!onkeypress_left())		return;
				break;
			case MYKEY_DOWN:
				if (!onkeypress_down())		return;
				break;
			case MYKEY_UP:
				if (!onkeypress_up())		return;
				break;
			case MYKEY_RIGHT:
				if (!onkeypress_right())	return;
				break;
			case MYKEY_OK:
				if (!onkeypress_ok())		return;
				break;
			case MYKEY_CANCEL:
				if (!onkeypress_cancel())	return;
				break;
			default:
				continue;
		}
	}
}
Example #7
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 #8
0
void IThread::run() {
	while ( !stopped ) {
		screen->ControlPlayer(getch());
		msleep(90);
		flushinp();
	}
}
Example #9
0
/* Initialises curses */
void
initcursestuff(void)
{
	int height, width;

	if (graph)
		return;

	height = width = 0;

	initscr();
	graph = 1;

	getmaxyx(stdscr, height, width);
	if (height < 24 || width < 80)
		xerrx(1, _("You need at least 80 x 24 terminal!"));

	keypad(stdscr, TRUE);
	noecho();
	cbreak();
	start_color();
	nodelay(stdscr, FALSE);
	flushinp();

	init_pair(1, COLOR_GREEN, COLOR_BLACK);
	init_pair(2, COLOR_WHITE, COLOR_BLACK);
	init_pair(3, COLOR_RED, COLOR_BLACK);
	init_pair(4, COLOR_MAGENTA, COLOR_BLACK);
	init_pair(5, COLOR_CYAN, COLOR_BLACK);
	init_pair(6, COLOR_BLUE, COLOR_BLACK);
	init_pair(7, COLOR_YELLOW, COLOR_BLACK);
}
void GameContextDemo::loop(){
	camera->updateViewport();
	int k = getch();
	if (k != ERR) {
        if (k == 105) {
            camera->moveForward();
        } else if (k == 107) {
            camera -> moveBackward();
        }
        if (k == 106) {
            camera->moveLeft();
        } else if (k == 108) {
            camera->moveRight();
        }
        if (k == 117) {
            camera->turnLeft();
        } else if (k == 111) {
            camera->turnRight();
        }
		if (k == 113) {
			this->game->stop();
		}
	}
	flushinp();
    glEnable(GL_MODELVIEW);
	glClearColor(0,0,0,0);
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glBindTexture(GL_TEXTURE_2D, texture);
	glRotatef(angle+=0.6,0,1,0);
	glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);



}
Example #11
0
/* This function waits until a key has been pressed */
void
pressanykey(int y, int x)
{
	flushinp();
	xcolor_set(4);
	mvaddstr(y, x, _("Press any key to continue..."));
	getch();
}
Example #12
0
char	*recup_entry(t_program *tetris)
{
  my_bzero(tetris->start.key, tetris->start.maxl + 1);
  if (read(0, tetris->start.key, tetris->start.maxl) <= 0)
    return (NULL);
  flushinp();
  if (!tetris->start.key[0])
    return (NULL);
  return (tetris->start.key);
}
Example #13
0
void search()
{
	int cpos = 0;
	int c;
	point_t o_point = curbp->b_point;
	point_t found;

	searchtext[0] = '\0';
	display_prompt_and_response(m_sprompt, searchtext);
	cpos = strlen(searchtext);

	for (;;) {
		c = getch();
		/* ignore control keys other than C-g, backspace, CR,  C-s, C-R, ESC */
		if (c < 32 && c != 07 && c != 0x08 && c != 0x13 && c != 0x12 && c != 0x1b)
			continue;

		switch(c) {
		case 0x1b: /* esc */
			searchtext[cpos] = '\0';
			flushinp(); /* discard any escape sequence without writing in buffer */
			return;

		case 0x07: /* ctrl-g */
			curbp->b_point = o_point;
			return;

		case 0x13: /* ctrl-s, do the search */
			found = search_forward(searchtext);
			display_search_result(found, FWD_SEARCH, m_sprompt, searchtext);
			break;

		case 0x12: /* ctrl-r, do the search */
			found = search_backwards(searchtext);
			display_search_result(found, REV_SEARCH, m_sprompt, searchtext);
			break;

		case 0x7f: /* del, erase */
		case 0x08: /* backspace */
			if (cpos == 0)
				continue;
			searchtext[--cpos] = '\0';
			display_prompt_and_response(m_sprompt, searchtext);
			break;

		default:
			if (cpos < STRBUF_M - 1) {
				searchtext[cpos++] = c;
				searchtext[cpos] = '\0';
				display_prompt_and_response(m_sprompt, searchtext);
			}
			break;
		}
	}
}
Example #14
0
void
curses_start(void)
{
  initscr();
  noecho();
  keypad(stdscr, TRUE);
  curs_set(0);
  refresh();

  flushinp();
}
Example #15
0
File: app.c Project: baylesj/cs411
/*
 * get_input ()
 * Get input from the keyboard as it is pressed. (Don't wait for Enter)
 */
int get_input ()
{
    int key = 0;
    while (!check_key(key)) {
        key = getch();
    }

    flushinp();

    return key;
}
Example #16
0
static enum ncurses_return_value
wait_until_stop_or_quit() {
    nodelay(stdscr, false);
    flushinp();
    int key;
    do {
        if ((key = getch()) == KEY_QUIT)
            return NCURSES_QUIT;
    } while (key != KEY_STOP);
    nodelay(stdscr, true);

    return NCURSES_OK;
}
Example #17
0
int mainTerminal_text()
{
	char prompt[20];

	while (1 == 1)
	{
		clearCommander(0);
		/*Print info about help*/
        printAndWriteFrom(20, "> ");
		printFrom(22, 6, "Type 'help' to display help entry");

		/*Wait for input*/
		flushinp();
		getstr(prompt);
		/*If the player would like to identify himself*/
		if (strcmp(prompt, "identify") == 0)
			{
				/*If the player has successfully logged in*/
				if (userIdentify() == TRUE)
				{
					return 0;
				}
				continue;
			}
		/*If the player would like to read help entry*/
		else if (strcmp(prompt, "help") == 0)
			{
				showHelp(mainTerminal);
				continue;
			}
		/*If the player would like to exit the game*/
		else if (strcmp(prompt, "exit") == 0)
			{
				clearCommander(0);
				return EXIT;
			}
		/*If the player would like to create a new account*/
		else if (strcmp(prompt, "create") == 0)
		{
			createAccount();
			continue;
		}
		/*If the player typed unknown command*/
		else
		{
			showCommanderInfo("Unknown command", 1);
		}
	}
	return 0;
}
Example #18
0
char promptUser(void)
{
	char		car = 0;

	if ((car = static_cast<char>(getch())) != ERR)
		flushinp();
	if (car == EXIT)
	{
		endwin();
		exit(0);//end game;
	}

	return (car);
}
/*Main function of interactif window*/
void runInteractif()
{
    interactif_win = newwin(HEIGHT_INT, WIDTH_WIN, 1, 1);
    init_pair(1, COLOR_BLACK, COLOR_WHITE);
    bgchange(interactif_win, COLOR_BLACK, COLOR_WHITE, 99);

    /*Load board from array from the file or from somewhere else*/
    loadMap("menu");

    /*Print bottom info*/
    wattron(stdscr, COLOR_PAIR(1));
    printFrom(stdscr, HEIGHT-1, 1, "Use");
    wattroff(stdscr, COLOR_PAIR(1));
    init_pair(4, COLOR_RED, COLOR_WHITE);
    wattron(stdscr, COLOR_PAIR(4));
    printFrom(stdscr, HEIGHT-1, 5, "ARROW KEYS");
    wattroff(stdscr, COLOR_PAIR(4));
    wattron(stdscr, COLOR_PAIR(1));
    printFrom(stdscr, HEIGHT-1, 16, "to move your character. Use");
    wattroff(stdscr, COLOR_PAIR(1));
    wattron(stdscr, COLOR_PAIR(4));
    printFrom(stdscr, HEIGHT-1, 44, "ENTER");
    wattroff(stdscr, COLOR_PAIR(4));
    wattron(stdscr, COLOR_PAIR(1));
    printFrom(stdscr, HEIGHT-1, 50, "to 'use' objects");
    wattroff(stdscr, COLOR_PAIR(1));

    flushinp();
    int input;
    while (1 == 1)
    {
        /*Receive input*/
        flushinp();
        input = getch();
        getMove(input);
    }
}
void splash(void)
{
  int x;

  attrset(COLOR_PAIR(COLOR_RED) | A_BOLD);
  gplot("htext", 20, 1, 1);

  attrset(COLOR_PAIR(COLOR_GREEN));
  gplot("tdesc", 42, 9, 1);

  attrset(COLOR_PAIR(COLOR_RED));
  mvprintw(4, MAP_XSIZE - strlen(VERSION), "%s", VERSION);

  attrset(COLOR_PAIR(COLOR_CYAN));
  for(x = 0; x < MAP_XSIZE; x++) {
    mvaddch(MAP_YSIZE - 1, x, ':');
    mvaddch(0, x, ':');
  }

  attrset(COLOR_PAIR(COLOR_MAGENTA));

  mvprintw(MAP_YSIZE, 0, "CAVEZ of PHEAR Copyright 2003-2007 Tom Rune Flo <*****@*****.**>");
  mvprintw(MAP_YSIZE + 1, 0, "Distributed under the terms of the GPL license");

  refresh();

  attrset(COLOR_PAIR(COLOR_WHITE) | A_NORMAL);

  mysleep(100000);

  for(x = -40; x < 0; x++) {
    gplot("spgraf", x, 1, 0);
    refresh();
    mysleep(7000);
  }

  attrset(COLOR_PAIR(COLOR_YELLOW));
  mvprintw(15, 42, "PRESS ANY KEY TO START!");

  attrset(A_NORMAL);

  refresh();

  flushinp();
  getch(); 

  return;
}
Example #21
0
static void
edition_post_exec (void)
{
    do_enter_ca_mode ();

    /* FIXME: Missing on slang endwin? */
    reset_prog_mode ();
    flushinp ();

    keypad (stdscr, TRUE);
    mc_raw_mode ();
    channels_up ();
    enable_mouse ();
    if (alternate_plus_minus)
	application_keypad_mode ();
}
Example #22
0
/*This will display arrows animation on the right bottom part of console*/
void waitingArrows()
{
    silenceOn();
    int c = 0, i = 67, k;
    flushinp();
    timeout (0);
    while (1 == 1)
    {
        for (k = 1; k < 6; k++)
        {
            c = getch();
            if (c == 10) break;
            if (k%2 == 1)
            {
                mvprintw(23, i, ">");
            }
            else
            {
                mvprintw(23, i, " ");
                i++;
                Sleep(NORMSPEED);
                mvprintw(23, i, " ");
            }
            i++;
            wrefresh(stdscr);
            c = getch();
            if (c == 10) break;
            Sleep(NORMSPEED);
        }
        if (c == 10) break;
        i -= 8;
        for (k = 1; k <= 9; k++)
        {
            c = getch();
            if (c == 10) break;
            mvprintw(23, i, " ");
            i++;
            wrefresh(stdscr);
            Sleep(NORMSPEED);
        }
        if (c == 10) break;
        i -= 8;
    }
    timeout (-1);
    silenceOff();
    clearLine(23);
}
Example #23
0
int main(int argc, char *argv[])
{
        char buffer[81];

        initscr();

        addstr("Type on the keyboard whilst I wait...\n");
        refresh();
        napms(5000);    // 5 seconds

        addstr("Here is what you typed:\n");
        flushinp();
        getnstr(buffer, 80);
        refresh();

        endwin();
        return 0;
}
Example #24
0
void game_over(int y, int x) {
    int i = 1, j = LINES, fr;

    attrset(A_BOLD);
    mvprintw(y, x, aircraft.ship);
    getch();
    mvprintw(y, x, space.blank);

    srand((unsigned)time(NULL));
    while (i < (LINES / 2 - 2)) {
        ++i;
        j--;
        fr = (rand() % 150) + 100;
        sndon(fr);
        mvprintw(i, (COLS / 2 - 30), space.blank);
        mvprintw(i + 1, (COLS / 2 - 30), "G");
        mvprintw(i, (COLS / 2 - 20), space.blank);
        mvprintw(i + 1, (COLS / 2 - 20), "A");
        mvprintw(i, (COLS / 2 - 10), space.blank);
        mvprintw(i + 1, (COLS / 2 - 10), "M");
        mvprintw(i, (COLS / 2), space.blank);
        mvprintw(i + 1, (COLS / 2), "E");

        mvprintw(j, (COLS / 2 - 30), space.blank);
        mvprintw(j - 1, (COLS / 2 - 30), "O");
        mvprintw(j, (COLS / 2 - 20), space.blank);
        mvprintw(j - 1, (COLS / 2 - 20), "V");
        mvprintw(j, (COLS / 2 - 10), space.blank);
        mvprintw(j - 1, (COLS / 2 - 10), "E");
        mvprintw(j, (COLS / 2), space.blank);
        mvprintw(j - 1, (COLS / 2), "R");
        napms(100);
        refresh();
    }

    sndoff();
    nocbreak();
    getch();
    attrset(A_NORMAL);
    refresh();
    flushinp();
    endwin();
    exit(0);
}
Example #25
0
void showHelp() {
    flushinp();
    wclear(helpwindow);
    wbkgd(helpwindow,COLOR_PAIR(2) | A_DIM);
    wborder(helpwindow,0,0,0,0,0,0,0,0);
    wattrset(helpwindow,A_BOLD);
    mvwprintw(helpwindow,0,2,"Help");
    mvwprintw(helpwindow,2,2,"Q - Quit");
    mvwprintw(helpwindow,3,2,"F1 - Help (this screen)");
    mvwprintw(helpwindow,4,2,"Left Arrow - Move Left");
    mvwprintw(helpwindow,5,2,"Right Arrow - Move Right");
    mvwprintw(helpwindow,6,2,"Down Arrow - Move Down");
    mvwprintw(helpwindow,7,2,"Up Arrow - Move Up");
    wattrset(helpwindow,A_REVERSE);
    mvwprintw(helpwindow,18,2,"Press any key to resume");
    wattrset(helpwindow,A_NORMAL);
    wrefresh(helpwindow);
    wgetch(helpwindow);
}
Example #26
0
enum ncurses_return_value
ncurses_handle_key(long *wait) {
    switch (getch()) {
        case KEY_QUIT:
            return NCURSES_QUIT;
        case KEY_SPEED_DOWN:
            wait_more(wait);
            break;
        case KEY_SPEED_UP:
            wait_less(wait);
            break;
        case KEY_STOP:
            return wait_until_stop_or_quit();
            break;
    }
    flushinp();

    return NCURSES_OK;
}
Example #27
0
/*
 *  Functions definitions
 */
void send_xy(out_t *info){
    int xy[2];
    char buff[BUFF_S];
    char tmp[5];
    char *lin_col[2];
    char *end;
    int (*attr_ch)(WINDOW*, int);

    lin_col[0] = "Digite a linha [0-99]: ";
    lin_col[1] = "Digite a coluna [0-99]: ";

    flushinp();
    show_panel(info->panel);

    for( int i = 0; i < 2; i++ ){
        attr_ch = wattroff;

        do{
            attr_ch(info->win, COLOR_PAIR(1));

            memset(tmp, 0, 5);

            wclear(info->win);
            box(info->win, 0, 0);

            mvwaddstr(info->win, 1, 1, lin_col[i]);
            wgetnstr(info->win, tmp, 5);
            xy[i] = strtol(tmp, &end, 10);

            attr_ch = wattron;
        }while( tmp == end || *end != 0 || xy[i] < 0 || xy[i] > 99 );
    }

    sprintf(buff, "%d*%d", xy[0], xy[1]);
    send(info->socket, buff, strlen(buff), 0);
    memset(buff, 0, BUFF_S);

    hide_panel(info->panel);
    update_panels();

    return;
}
Example #28
0
int main(int argc, char *argv[]) {
	int i;

	initscr();

	// hide the cursor and keypresses
	curs_set(0);
	noecho();

	if (has_colors()) {
		color_ind = 1;
		start_color();

		// set background to black even for areas outside the drawing region
		assume_default_colors(COLOR_CYAN, COLOR_BLACK);

		init_pair(ETCH_COLOR_FRAME, COLOR_RED, COLOR_BLACK);
		init_pair(ETCH_COLOR_KNOB, COLOR_WHITE, COLOR_BLACK);
		init_pair(ETCH_COLOR_DRAW, COLOR_CYAN, COLOR_BLACK);
	} else {
		color_ind = 0;
	}


	// show the etch device
	drawEtch();

	// etch animation
	etchResume();


	// clear any pending keypresses and wait for another before quitting
	flushinp();
	getch();


	// restore the cursor and cleanup
	curs_set(1);
	endwin();

	return 1;
}
Example #29
0
void Input(STATE* state)
{
    int c = 0;

    c = getch();
    if (c == ERR)
        return;


    if (c == state->keymap[TETRIS_KEY_QUIT]) {
        state->status = STATUS_GAMEOVER;
    } else if (c == state->keymap[TETRIS_KEY_DROP]) {
        EventDrop(state);
    } else if (c == state->keymap[TETRIS_KEY_LOWER]) {
        EventLower(state);
    } else if (c == state->keymap[TETRIS_KEY_ROTATE_CW]) {
        EventRotate(state, 1);
    } else if (c == state->keymap[TETRIS_KEY_ROTATE_CCW]) {
        EventRotate(state, -1);
    } else if (c == state->keymap[TETRIS_KEY_MOVE_LEFT]) {
        EventMove(state, -1);
    } else if (c == state->keymap[TETRIS_KEY_MOVE_RIGHT]) {
        EventMove(state, 1);
    } else if (c == state->keymap[TETRIS_KEY_PAUSE]) {
        if (! state->game_over_f) {
            if (state->pause_f)
                EventUnpause(state);
            else
                EventPause(state);
        }
    } else if (c == state->keymap[TETRIS_KEY_RESET]) {
        Reset(state);
    } else {
        printw("\a");
    }

    flushinp();
    return;
}
Example #30
0
/*It shows help info about chosen part of program*/
void f_showHelp(char* aboutWhat)
{
	silenceOn();
	clearCommander(0);
	/*If called from mainTerminal function*/
	if (strcmp(aboutWhat, " ") == 0)
	{
		printFrom(20, 4, " ");
		wrefresh(stdscr);
	}
	/*If passed invalid help menu*/
	else
	{
		perror("Invalid help menu");
		assert(!TRUE);
	}
	/*Wait till key is being pressed*/
	flushinp();
	getch();
	silenceOff();

}