Ejemplo n.º 1
0
int
main(int argc, char *argv[])
{
    int first = 1;
    char buf[80];

    progname = argv[0];

    if (init(argc, argv)) {	/* restored game */
	goto PL;
    }

    for (;;) {
	clear_level();
	make_level();
	put_objects();
	put_stairs();
	add_traps();
	put_mons();
	put_player(party_room);
	print_stats(STAT_ALL);
	if (first) {
	    sprintf(buf, mesg[10], nick_name);
	    message(buf, 0);
	}
    PL:
	first = 0;
	play_level();
	free_stuff(&level_objects);
	free_stuff(&level_monsters);
    }
}
Ejemplo n.º 2
0
static void play_game(void)
{
	while (load_level(level)) {
		play_level();
		level++;
		/* Save the new level achieved */
		if (conf_fd != -1) {
			lseek(conf_fd, 0L, SEEK_SET);
			write(conf_fd, &level, 2);
		}
	}
}
Ejemplo n.º 3
0
void available_levels(al_defs *al) {

  bool quit=false;
  level_list *list = get_level_list();
  level_list_mem *p = list->first;
  level* l = NULL;

  while(!quit) {
    al_clear_to_color(al_map_rgb(0,0,0));
    al_draw_text(al->logo_font,al_map_rgb(255,255,255),al->width/2,
        20,ALLEGRO_ALIGN_CENTRE,"sokoban");
    al_draw_text(al->menu_font,al_map_rgb(255,255,255), al->width/2, 
        160, ALLEGRO_ALIGN_CENTRE,"Select your level:");

    al_draw_textf(al->menu_font, al_map_rgb(255,0,0), al->width/2, 
        al->height/2, ALLEGRO_ALIGN_CENTRE, "%s", p->name);

    al_draw_text(al->hint_font, al_map_rgb(120, 120, 120), 10,
        al->height-30, ALLEGRO_ALIGN_LEFT, 
        "Use arrows to navigate, ENTER to choose, Esc to return to the main screen");
    al_flip_display();

    ALLEGRO_EVENT ev;
    al_wait_for_event(al->queue, &ev);
    if(ev.type == ALLEGRO_EVENT_KEY_DOWN) {
      //printf("EVENT KEYCODE: %d\n",ev.keyboard.keycode);
      switch(ev.keyboard.keycode) {
        case ALLEGRO_KEY_ESCAPE:
          quit=true;
          break;

        case ALLEGRO_KEY_ENTER: 
          do {
            if(l!=NULL) free_level(l);
            l = read_level(p->name);
            if(l==NULL) break;
          }while(play_level(al, l, p->name));
          free_level(l);
          l=NULL;
          break;

        case ALLEGRO_KEY_LEFT:
          p=p->prev;
          break;

        case ALLEGRO_KEY_RIGHT:
          p=p->next;
          break;
      }
    }
  }
}
Ejemplo n.º 4
0
void game (void)
{
  int lives = MAX_LIVES;
  int score = 0;
  long int level_score;
  int level = START_LEVEL;
  int result;

  do {
    result = play_level (level, &level_score, lives, score);
    /* The level has been played, now we must check to see what happened, display an appropriate
       message to the terminal if necessary, add up points, etc */
    
    switch (result)
      {	
      case MSG_WINLEVEL:
	score+= level_score;
	level++;
	display_message (result, lives, level, score);
	break;
      case MSG_WINGAME:
	score+= level_score;
	level++; /* This is for the log_score function */
	game_win ();
	
	lives = 0; /* This lets us get out of this function */
	
	/* Display ending message, then go back to menu */
	ansi_PutString (1, 25, "Done.");
	wait_for_select ();
	break;
      case MSG_QUIT: return;
      default: /* We know the users aircraft has crashed in some way, so deduct one life and display a message */
	lives--;
	display_message (result, lives, level, score);
	break;
      }
  } while (lives > 0);

#ifndef __ANDROID__
  log_score (score, level); /* This records the score of anyone who finishes or runs out of lives */
#endif // __ANDROID__
}
Ejemplo n.º 5
0
int
main(int ac, char *av[])
{
	bool		show_only;
	extern char	*Scorefile;
	int		score_wfd;     /* high score writable file descriptor */
	int		score_err = 0; /* hold errno from score file open */
	int		ch;
	extern int	optind;
	gid_t		gid;
#ifdef FANCY
	char		*sp;
#endif

	if ((score_wfd = open(Scorefile, O_RDWR)) < 0)
		score_err = errno;

	/* revoke privs */
	gid = getgid();
	setresgid(gid, gid, gid);

	show_only = FALSE;
	while ((ch = getopt(ac, av, "srajt")) != -1)
		switch (ch) {
		case 's':
			show_only = TRUE;
			break;
		case 'r':
			Real_time = TRUE;
			/* Could be a command-line option */
			tv.tv_sec = 3;
			tv.tv_usec = 0;
			FD_ZERO(&rset);
			break;
		case 'a':
			Start_level = 4;
			break;
		case 'j':
			Jump = TRUE;
			break;
		case 't':
			Teleport = TRUE;
			break;
		case '?':
		default:
			usage();
		}
	ac -= optind;
	av += optind;

	if (ac > 1)
		usage();
	if (ac == 1) {
		Scorefile = av[0];
		if (score_wfd >= 0)
			close(score_wfd);
		/* This file requires no special privileges. */
		if ((score_wfd = open(Scorefile, O_RDWR)) < 0)
			score_err = errno;
#ifdef	FANCY
		sp = strrchr(Scorefile, '/');
		if (sp == NULL)
			sp = Scorefile;
		if (strcmp(sp, "pattern_roll") == 0)
			Pattern_roll = TRUE;
		else if (strcmp(sp, "stand_still") == 0)
			Stand_still = TRUE;
		if (Pattern_roll || Stand_still)
			Teleport = TRUE;
#endif
	}

	if (show_only) {
		show_score();
		exit(0);
	}

	if (score_wfd < 0) {
		warnx("%s: %s; no scores will be saved", Scorefile,
			strerror(score_err));
		sleep(1);
	}

	initscr();
	signal(SIGINT, quit);
	cbreak();
	noecho();
	nonl();
	if (LINES != Y_SIZE || COLS != X_SIZE) {
		if (LINES < Y_SIZE || COLS < X_SIZE) {
			endwin();
			errx(1, "Need at least a %dx%d screen", Y_SIZE, X_SIZE);
		}
		delwin(stdscr);
		stdscr = newwin(Y_SIZE, X_SIZE, 0, 0);
	}

	srandomdev();
	do {
		init_field();
		for (Level = Start_level; !Dead; Level++) {
			make_level();
			play_level();
		}
		move(My_pos.y, My_pos.x);
		printw("AARRrrgghhhh....");
		refresh();
		score(score_wfd);
	} while (another());
	quit(0);
	/* NOT REACHED */
}
Ejemplo n.º 6
0
void
play_dat_level (int number)
{
  next_dat_level (number);
  play_level (&legacy_level);
}
Ejemplo n.º 7
0
int
main(int ac, char *av[])
{
	bool		show_only;
	extern char	Scorefile[PATH_MAX];
	int		score_wfd;     /* high score writable file descriptor */
	int		score_err = 0; /* hold errno from score file open */
	int		ch;
	int		ret;
	extern int	optind;
	char		*home;
#ifdef FANCY
	char		*sp;
#endif

	if (pledge("stdio rpath wpath cpath tty", NULL) == -1)
		err(1, "pledge");

	home = getenv("HOME");
	if (home == NULL || *home == '\0')
		err(1, "getenv");

	ret = snprintf(Scorefile, sizeof(Scorefile), "%s/%s", home,
	    ".robots.scores");
	if (ret < 0 || ret >= PATH_MAX)
		errc(1, ENAMETOOLONG, "%s/%s", home, ".robots.scores");

	if ((score_wfd = open(Scorefile, O_RDWR | O_CREAT, 0666)) < 0)
		score_err = errno;

	show_only = FALSE;
	while ((ch = getopt(ac, av, "srajt")) != -1)
		switch (ch) {
		case 's':
			show_only = TRUE;
			break;
		case 'r':
			Real_time = TRUE;
			/* Could be a command-line option */
			tv.tv_sec = 3;
			break;
		case 'a':
			Start_level = 4;
			break;
		case 'j':
			Jump = TRUE;
			break;
		case 't':
			Teleport = TRUE;
			break;
		case '?':
		default:
			usage();
		}
	ac -= optind;
	av += optind;

	if (ac > 1)
		usage();
	if (ac == 1) {
		if (strlcpy(Scorefile, av[0], sizeof(Scorefile)) >=
		    sizeof(Scorefile))
			errc(1, ENAMETOOLONG, "%s", av[0]);
		if (score_wfd >= 0)
			close(score_wfd);
		/* This file requires no special privileges. */
		if ((score_wfd = open(Scorefile, O_RDWR | O_CREAT, 0666)) < 0)
			score_err = errno;
#ifdef	FANCY
		sp = strrchr(Scorefile, '/');
		if (sp == NULL)
			sp = Scorefile;
		if (strcmp(sp, "pattern_roll") == 0)
			Pattern_roll = TRUE;
		else if (strcmp(sp, "stand_still") == 0)
			Stand_still = TRUE;
		if (Pattern_roll || Stand_still)
			Teleport = TRUE;
#endif
	}

	if (show_only) {
		show_score();
		return 0;
	}

	if (score_wfd < 0) {
		warnx("%s: %s; no scores will be saved", Scorefile,
			strerror(score_err));
		sleep(1);
	}

	initscr();
	signal(SIGINT, quit);
	cbreak();
	noecho();
	nonl();
	if (LINES != Y_SIZE || COLS != X_SIZE) {
		if (LINES < Y_SIZE || COLS < X_SIZE) {
			endwin();
			errx(1, "Need at least a %dx%d screen", Y_SIZE, X_SIZE);
		}
		delwin(stdscr);
		stdscr = newwin(Y_SIZE, X_SIZE, 0, 0);
	}

	do {
		init_field();
		for (Level = Start_level; !Dead; Level++) {
			make_level();
			play_level();
		}
		if (My_pos.x > X_FIELDSIZE - 16)
			move(My_pos.y, X_FIELDSIZE - 16);
		else
			move(My_pos.y, My_pos.x);
		printw("AARRrrgghhhh....");
		refresh();
		score(score_wfd);
	} while (another());
	quit(0);
}
Ejemplo n.º 8
0
int
main(int argc, char **argv)
{
	const char *word;
	bool show_only;
	int score_wfd; /* high score writable file descriptor */
	int score_err = 0; /* hold errno from score file open */
	int maximum = 0;
	int ch, i;

	score_wfd = open(Scorefile, O_RDWR);
	if (score_wfd < 0)
		score_err = errno;
	else if (score_wfd < 3)
		exit(1);

	/* Revoke setgid privileges */
	setgid(getgid());

	show_only = false;
	Num_games = 1;

	while ((ch = getopt(argc, argv, "Aajnrst")) != -1) {
		switch (ch) {
		    case 'A':
			Auto_bot = true;
			break;
		    case 'a':
			Start_level = 4;
			break;
		    case 'j':
			Jump = true;
			break;
		    case 'n':
			Num_games++;
			break;
		    case 'r':
			Real_time = true;
			break;
		    case 's':
			show_only = true;
			break;
		    case 't':
			Teleport = true;
			break;
		    default:
			errx(1,
			    "Usage: robots [-Aajnrst] [maximum] [scorefile]");
			break;
		}
	}

	for (i = optind; i < argc; i++) {
		word = argv[i];
		if (isdigit((unsigned char)word[0])) {
			maximum = atoi(word);
		} else {
			Scorefile = word;
			Max_per_uid = maximum;
			if (score_wfd >= 0)
				close(score_wfd);
			score_wfd = open(Scorefile, O_RDWR);
			if (score_wfd < 0)
				score_err = errno;
#ifdef FANCY
			word = strrchr(Scorefile, '/');
			if (word == NULL)
				word = Scorefile;
			if (strcmp(word, "pattern_roll") == 0)
				Pattern_roll = true;
			else if (strcmp(word, "stand_still") == 0)
				Stand_still = true;
			if (Pattern_roll || Stand_still)
				Teleport = true;
#endif
		}
	}

	if (show_only) {
		show_score();
		exit(0);
		/* NOTREACHED */
	}

	if (score_wfd < 0) {
		errno = score_err;
		warn("%s", Scorefile);
		warnx("High scores will not be recorded!");
		sleep(2);
	}

	if (!initscr())
		errx(0, "couldn't initialize screen");
	signal(SIGINT, quit);
	cbreak();
	noecho();
	nonl();
	if (LINES != Y_SIZE || COLS != X_SIZE) {
		if (LINES < Y_SIZE || COLS < X_SIZE) {
			endwin();
			printf("Need at least a %dx%d screen\n",
			    Y_SIZE, X_SIZE);
			exit(1);
		}
		delwin(stdscr);
		stdscr = newwin(Y_SIZE, X_SIZE, 0, 0);
	}

	srandom(time(NULL));
	if (Real_time)
		signal(SIGALRM, move_robots);
	do {
		while (Num_games--) {
			init_field();
			for (Level = Start_level; !Dead; Level++) {
				make_level();
				play_level();
				if (Auto_bot)
					sleep(1);
			}
			move(My_pos.y, My_pos.x);
			printw("AARRrrgghhhh....");
			refresh();
			if (Auto_bot)
				sleep(1);
			score(score_wfd);
			if (Auto_bot)
				sleep(1);
			refresh();
		}
		Num_games = 1;
	} while (!Auto_bot && another());
	quit(0);
	/* NOTREACHED */
	return(0);
}