int main(int argc, char **argv) { int c; /* Revoke setgid privileges */ setgid(getgid()); #ifdef DEBUG while ((c = getopt(argc, argv, "a:b:hp:r:t:d")) != -1) #else while ((c = getopt(argc, argv, "a:b:hp:r:t:")) != -1) #endif switch (c) { case 'a': arrow_num = atoi(optarg); break; case 'b': bat_num = atoi(optarg); break; #ifdef DEBUG case 'd': debug = 1; break; #endif case 'h': level = HARD; break; case 'p': pit_num = atoi(optarg); break; case 'r': room_num = atoi(optarg); if (room_num < MIN_ROOMS_IN_CAVE) { (void)fprintf(stderr, "No self-respecting wumpus would live in such a small cave!\n"); exit(1); } if (room_num > MAX_ROOMS_IN_CAVE) { (void)fprintf(stderr, "Even wumpii can't furnish caves that large!\n"); exit(1); } break; case 't': link_num = atoi(optarg); if (link_num < 2) { (void)fprintf(stderr, "Wumpii like extra doors in their caves!\n"); exit(1); } break; case '?': default: usage(); } if (link_num > MAX_LINKS_IN_ROOM || link_num > room_num - (room_num / 4)) { (void)fprintf(stderr, "Too many tunnels! The cave collapsed!\n(Fortunately, the wumpus escaped!)\n"); exit(1); } if (level == HARD) { bat_num += ((random() % (room_num / 2)) + 1); pit_num += ((random() % (room_num / 2)) + 1); } if (bat_num > room_num / 2) { (void)fprintf(stderr, "The wumpus refused to enter the cave, claiming it was too crowded!\n"); exit(1); } if (pit_num > room_num / 2) { (void)fprintf(stderr, "The wumpus refused to enter the cave, claiming it was too dangerous!\n"); exit(1); } instructions(); cave_init(); /* and we're OFF! da dum, da dum, da dum, da dum... */ (void)printf( "\nYou're in a cave with %d rooms and %d tunnels leading from each room.\n\ There are %d bat%s and %d pit%s scattered throughout the cave, and your\n\ quiver holds %d custom super anti-evil Wumpus arrows. Good luck.\n", room_num, link_num, bat_num, plural(bat_num), pit_num, plural(pit_num), arrow_num); for (;;) { initialize_things_in_cave(); arrows_left = arrow_num; do { display_room_stats(); (void)printf("Move or shoot? (m-s) "); (void)fflush(stdout); if (!fgets(answer, sizeof(answer), stdin)) break; } while (!take_action()); if (!getans("\nCare to play another game? (y-n) ")) exit(0); if (getans("In the same cave? (y-n) ")) clear_things_in_cave(); else cave_init(); } /* NOTREACHED */ return (0); }
int main(int argc, char *argv[]) { int c; #ifdef DEBUG while ((c = getopt(argc, argv, "a:b:hop:r:t:d")) != -1) #else while ((c = getopt(argc, argv, "a:b:hop:r:t:")) != -1) #endif switch (c) { case 'a': arrow_num = atoi(optarg); break; case 'b': bat_num = atoi(optarg); break; #ifdef DEBUG case 'd': debug = 1; break; #endif case 'h': level = HARD; break; case 'o': oldstyle = 1; break; case 'p': pit_num = atoi(optarg); break; case 'r': room_num = atoi(optarg); if (room_num < MIN_ROOMS_IN_CAVE) errx(1, "no self-respecting wumpus would live in such a small cave!"); if (room_num > MAX_ROOMS_IN_CAVE) errx(1, "even wumpii can't furnish caves that large!"); break; case 't': link_num = atoi(optarg); if (link_num < 2) errx(1, "wumpii like extra doors in their caves!"); break; case '?': default: usage(); } if (oldstyle) { room_num = 20; link_num = 3; /* Original game had exactly 2 bats and 2 pits */ if (bat_num < 0) bat_num = 2; if (pit_num < 0) pit_num = 2; } else { if (bat_num < 0) bat_num = BAT_COUNT; if (pit_num < 0) pit_num = PIT_COUNT; } if (link_num > MAX_LINKS_IN_ROOM || link_num > room_num - (room_num / 4)) errx(1, "too many tunnels! The cave collapsed!\n(Fortunately, the wumpus escaped!)"); if (level == HARD) { if (room_num / 2 - bat_num) bat_num += arc4random_uniform(room_num / 2 - bat_num); if (room_num / 2 - pit_num) pit_num += arc4random_uniform(room_num / 2 - pit_num); } /* Leave at least two rooms free--one for the player to start in, and * potentially one for the wumpus. */ if (bat_num > room_num / 2 - 1) errx(1, "the wumpus refused to enter the cave, claiming it was too crowded!"); if (pit_num > room_num / 2 - 1) errx(1, "the wumpus refused to enter the cave, claiming it was too dangerous!"); instructions(); if (oldstyle) dodecahedral_cave_init(); else cave_init(); /* and we're OFF! da dum, da dum, da dum, da dum... */ (void)printf( "\nYou're in a cave with %d rooms and %d tunnels leading from each room.\n\ There are %d bat%s and %d pit%s scattered throughout the cave, and your\n\ quiver holds %d custom super anti-evil Wumpus arrows. Good luck.\n", room_num, link_num, bat_num, plural(bat_num), pit_num, plural(pit_num), arrow_num); for (;;) { initialize_things_in_cave(); arrows_left = arrow_num; do { display_room_stats(); (void)printf("Move or shoot? (m-s) "); (void)fflush(stdout); (void)fpurge(stdin); if (!fgets(answer, sizeof(answer), stdin)) break; } while (!take_action()); (void)fpurge(stdin); if (!getans("\nCare to play another game? (y-n) ")) { (void)printf("\n"); exit(0); } clear_things_in_cave(); if (!getans("In the same cave? (y-n) ")) { if (oldstyle) dodecahedral_cave_init(); else cave_init(); } } /* NOTREACHED */ }