void scum(unsigned long startingSeed, short numberOfSeedsToScan, short scanThroughDepth) { unsigned long theSeed; char path[BROGUE_FILENAME_MAX]; item *theItem; creature *monst; char buf[500]; FILE *logFile; logFile = fopen("Brogue seed catalog.txt", "w"); rogue.nextGame = NG_NOTHING; getAvailableFilePath(path, LAST_GAME_NAME, GAME_SUFFIX); strcat(path, GAME_SUFFIX); fprintf(logFile, "Brogue seed catalog, seeds %li to %li, through depth %i.\n\n\ To play one of these seeds, press control-N from the title screen \ and enter the seed number. Knowing which items will appear on \ the first %i depths will, of course, make the game significantly easier.", startingSeed, startingSeed + numberOfSeedsToScan - 1, scanThroughDepth, scanThroughDepth); for (theSeed = startingSeed; theSeed < startingSeed + numberOfSeedsToScan; theSeed++) { fprintf(logFile, "\n\nSeed %li:", theSeed); printf("\nScanned seed %li.", theSeed); rogue.nextGamePath[0] = '\0'; randomNumbersGenerated = 0; rogue.playbackMode = false; rogue.playbackFastForward = false; rogue.playbackBetweenTurns = false; strcpy(currentFilePath, path); initializeRogue(theSeed); rogue.playbackOmniscience = true; for (rogue.depthLevel = 1; rogue.depthLevel <= scanThroughDepth; rogue.depthLevel++) { startLevel(rogue.depthLevel == 1 ? 1 : rogue.depthLevel - 1, 1); // descending into level n fprintf(logFile, "\n Depth %i:", rogue.depthLevel); for (theItem = floorItems->nextItem; theItem != NULL; theItem = theItem->nextItem) { itemName(theItem, buf, true, true, NULL); upperCase(buf); fprintf(logFile, "\n %s", buf); if (pmap[theItem->xLoc][theItem->yLoc].machineNumber > 0) { fprintf(logFile, " (vault %i)", pmap[theItem->xLoc][theItem->yLoc].machineNumber); } } for (monst = monsters->nextCreature; monst != NULL; monst = monst->nextCreature) { scumMonster(monst, logFile); } for (monst = dormantMonsters->nextCreature; monst != NULL; monst = monst->nextCreature) { scumMonster(monst, logFile); } } freeEverything(); remove(currentFilePath); // Don't add a spurious LastGame file to the brogue folder. } fclose(logFile); }
int DestroyHashTable(HashTablePTR *table){ //Classic Deadbeef check if((*table) == NULL || (*table)->sentinel != 0xDEADBEEF){return -1;} else{ //go through the buckets and free every linked list compliments of //freeEverything for(int i = 0; i < range; i++){ freeEverything(((*table)->buckets)[i]); } //free the last pesky pointers free((*table)->buckets); free((*table)); *table = NULL; return 0; } }
// This is the basic program loop. // When the program launches, or when a game ends, you end up here. // If the player has already said what he wants to do next // (by storing it in rogue.nextGame -- possibilities listed in enum NGCommands), // we'll do it. The path (rogue.nextGamePath) is essentially a parameter for this command, and // tells NG_VIEW_RECORDING and NG_OPEN_GAME which file to open. If there is a command but no // accompanying path, and it's a command that should take a path, then pop up a dialog to have // the player specify a path. If there is no command (i.e. if rogue.nextGame contains NG_NOTHING), // then we'll display the title screen so the player can choose. void mainBrogueJunction() { rogueEvent theEvent; char path[BROGUE_FILENAME_MAX], buf[100], seedDefault[100]; char maxSeed[20]; short i, j, k; boolean seedTooBig; // clear screen and display buffer for (i=0; i<COLS; i++) { for (j=0; j<ROWS; j++) { displayBuffer[i][j].character = 0; displayBuffer[i][j].needsUpdate = false; displayBuffer[i][j].opacity = 100; for (k=0; k<3; k++) { displayBuffer[i][j].foreColorComponents[k] = 0; displayBuffer[i][j].backColorComponents[k] = 0; } plotCharWithColor(' ', i, j, &black, &black); } } initializeLaunchArguments(&rogue.nextGame, rogue.nextGamePath, &rogue.nextGameSeed); do { rogue.gameHasEnded = false; rogue.playbackFastForward = false; rogue.playbackMode = false; switch (rogue.nextGame) { case NG_NOTHING: // Run the main menu to get a decision out of the player. // Seth: Added setBrogueGameEvent(BrogueGameEventShowTitle); titleMenu(); break; case NG_NEW_GAME: case NG_NEW_GAME_WITH_SEED: rogue.nextGamePath[0] = '\0'; randomNumbersGenerated = 0; rogue.playbackMode = false; rogue.playbackFastForward = false; rogue.playbackBetweenTurns = false; getAvailableFilePath(path, LAST_GAME_NAME, GAME_SUFFIX); strcat(path, GAME_SUFFIX); strcpy(currentFilePath, path); if (rogue.nextGame == NG_NEW_GAME_WITH_SEED) { if (rogue.nextGameSeed == 0) { // Prompt for seed; default is the previous game's seed. sprintf(maxSeed, "%lu", ULONG_MAX); if (previousGameSeed == 0) { seedDefault[0] = '\0'; } else { sprintf(seedDefault, "%lu", previousGameSeed); } if (getInputTextString(buf, "Generate dungeon with seed number:", log10(ULONG_MAX) + 1, seedDefault, "", TEXT_INPUT_NUMBERS, true) && buf[0] != '\0') { seedTooBig = false; if (strlen(buf) > strlen(maxSeed)) { seedTooBig = true; } else if (strlen(buf) == strlen(maxSeed)) { for (i=0; maxSeed[i]; i++) { if (maxSeed[i] > buf[i]) { break; // we're good } else if (maxSeed[i] < buf[i]) { seedTooBig = true; break; } } } if (seedTooBig) { rogue.nextGameSeed = ULONG_MAX; } else { sscanf(buf, "%lu", &rogue.nextGameSeed); } } else { rogue.nextGame = NG_NOTHING; break; // Don't start a new game after all. } } } else { rogue.nextGameSeed = 0; // Seed based on clock. } // Seth: Added setBrogueGameEvent(BrogueGameEventStartNewGame); rogue.nextGame = NG_NOTHING; initializeRogue(rogue.nextGameSeed); startLevel(rogue.depthLevel, 1); // descending into level 1 mainInputLoop(); freeEverything(); break; case NG_OPEN_GAME: rogue.nextGame = NG_NOTHING; // Seth: Added setBrogueGameEvent(BrogueGameEventBeginOpenGame); path[0] = '\0'; if (rogue.nextGamePath[0]) { strcpy(path, rogue.nextGamePath); rogue.nextGamePath[0] = '\0'; } else { dialogChooseFile(path, GAME_SUFFIX, "Open saved game:"); //chooseFile(path, "Open saved game: ", "Saved game", GAME_SUFFIX); } if (openFile(path)) { loadSavedGame(); // Seth: Added setBrogueGameEvent(BrogueGameEventOpenGame); mainInputLoop(); freeEverything(); } else { //dialogAlert("File not found."); } rogue.playbackMode = false; rogue.playbackOOS = false; // Seth: Added setBrogueGameEvent(BrogueGameEventOpenGameFinished); break; case NG_VIEW_RECORDING: rogue.nextGame = NG_NOTHING; // Seth: Added setBrogueGameEvent(BrogueGameEventBeginOpenGame); path[0] = '\0'; if (rogue.nextGamePath[0]) { strcpy(path, rogue.nextGamePath); rogue.nextGamePath[0] = '\0'; } else { dialogChooseFile(path, RECORDING_SUFFIX, "View recording:"); //chooseFile(path, "View recording: ", "Recording", RECORDING_SUFFIX); } if (openFile(path)) { // Seth: Added setBrogueGameEvent(BrogueGameEventPlayRecording); randomNumbersGenerated = 0; rogue.playbackMode = true; initializeRogue(0); // Seed argument is ignored because we're in playback. if (!rogue.gameHasEnded) { startLevel(rogue.depthLevel, 1); pausePlayback(); displayAnnotation(); // in case there's an annotation for turn 0 } while(!rogue.gameHasEnded && rogue.playbackMode) { rogue.RNG = RNG_COSMETIC; // dancing terrain colors can't influence recordings rogue.playbackBetweenTurns = true; nextBrogueEvent(&theEvent, false, true, false); rogue.RNG = RNG_SUBSTANTIVE; executeEvent(&theEvent); } freeEverything(); } else { // announce file not found } rogue.playbackMode = false; rogue.playbackOOS = false; break; case NG_HIGH_SCORES: rogue.nextGame = NG_NOTHING; // Seth: Added setBrogueGameEvent(BrogueGameEventShowHighScores); printHighScores(false); break; case NG_SCUM: rogue.nextGame = NG_NOTHING; scum(1, 1000, 5); break; case NG_QUIT: // No need to do anything. break; default: break; } } while (rogue.nextGame != NG_QUIT); }
// This is the basic program loop. // When the program launches, or when a game ends, you end up here. // If the player has already said what he wants to do next // (by storing it in rogue.nextGame -- possibilities listed in enum NGCommands), // we'll do it. The path (rogue.nextGamePath) is essentially a parameter for this command, and // tells NG_VIEW_RECORDING and NG_OPEN_GAME which file to open. If there is a command but no // accompanying path, and it's a command that should take a path, then pop up a dialog to have // the player specify a path. If there is no command (i.e. if rogue.nextGame contains NG_NOTHING), // then we'll display the title screen so the player can choose. void mainBrogueJunction() { rogueEvent theEvent; char path[BROGUE_FILENAME_MAX], buf[100], seedDefault[100]; char maxSeed[64]; short i; boolean seedTooBig; if (ioInitialize() != 0) { printf("Failure to initialize display\n"); exit(1); } initializeLaunchArguments(&rogue.nextGame, rogue.nextGamePath, &rogue.nextGameSeed); do { rogue.gameHasEnded = false; rogue.playbackFastForward = false; rogue.playbackMode = false; switch (rogue.nextGame) { case NG_NOTHING: // Run the main menu to get a decision out of the player. titleMenu(); break; case NG_NEW_GAME: case NG_NEW_GAME_WITH_SEED: rogue.nextGamePath[0] = '\0'; randomNumbersGenerated = 0; rogue.playbackMode = false; rogue.playbackFastForward = false; rogue.playbackBetweenTurns = false; getAvailableFilePath(path, LAST_GAME_NAME, GAME_SUFFIX); strcat(path, GAME_SUFFIX); strcpy(currentFilePath, path); if (rogue.nextGame == NG_NEW_GAME_WITH_SEED) { if (rogue.nextGameSeed == 0) { // Prompt for seed; default is the previous game's seed. sprintf(maxSeed, "%lu", ULONG_MAX); if (previousGameSeed == 0) { seedDefault[0] = '\0'; } else { sprintf(seedDefault, "%lu", previousGameSeed); } if (getInputTextString(buf, "输入随机数种子生成地下城:", log10(ULONG_MAX) + 1 + 6, // pad for header text seedDefault, "", TEXT_INPUT_NUMBERS, true) && buf[0] != '\0') { seedTooBig = false; if (strlen(buf) > strlen(maxSeed)) { seedTooBig = true; } else if (strlen(buf) == strlen(maxSeed)) { for (i=0; maxSeed[i]; i++) { if (maxSeed[i] > buf[i]) { break; // we're good } else if (maxSeed[i] < buf[i]) { seedTooBig = true; break; } } } if (seedTooBig) { rogue.nextGameSeed = ULONG_MAX; } else { sscanf(buf, "%lu", &rogue.nextGameSeed); } } else { rogue.nextGame = NG_NOTHING; break; // Don't start a new game after all. } } } else { rogue.nextGameSeed = 0; // Seed based on clock. } rogue.nextGame = NG_NOTHING; initializeRogue(rogue.nextGameSeed); startLevel(rogue.depthLevel, 1); // descending into level 1 mainInputLoop(); freeEverything(); break; case NG_OPEN_GAME: rogue.nextGame = NG_NOTHING; path[0] = '\0'; if (rogue.nextGamePath[0]) { strcpy(path, rogue.nextGamePath); rogue.nextGamePath[0] = '\0'; } else { dialogChooseFile(path, GAME_SUFFIX, "选择中断存档进行读取:"); //chooseFile(path, "Open saved game: ", "Saved game", GAME_SUFFIX); } if (openFile(path)) { loadSavedGame(); mainInputLoop(); freeEverything(); } else { //dialogAlert("File not found."); } rogue.playbackMode = false; rogue.playbackOOS = false; break; case NG_VIEW_RECORDING: rogue.nextGame = NG_NOTHING; path[0] = '\0'; if (rogue.nextGamePath[0]) { strcpy(path, rogue.nextGamePath); rogue.nextGamePath[0] = '\0'; } else { dialogChooseFile(path, RECORDING_SUFFIX, "选择录像文件进行回放:"); //chooseFile(path, "View recording: ", "Recording", RECORDING_SUFFIX); } if (openFile(path)) { randomNumbersGenerated = 0; rogue.playbackMode = true; initializeRogue(0); // Seed argument is ignored because we're in playback. if (!rogue.gameHasEnded) { startLevel(rogue.depthLevel, 1); pausePlayback(); displayAnnotation(); // in case there's an annotation for turn 0 } while(!rogue.gameHasEnded && rogue.playbackMode) { rogue.RNG = RNG_COSMETIC; // dancing terrain colors can't influence recordings rogue.playbackBetweenTurns = true; nextBrogueEvent(&theEvent, false, true, false); rogue.RNG = RNG_SUBSTANTIVE; executeEvent(&theEvent); } freeEverything(); } else { // announce file not found } rogue.playbackMode = false; rogue.playbackOOS = false; break; case NG_HIGH_SCORES: rogue.nextGame = NG_NOTHING; printHighScores(false); break; case NG_SCUM: rogue.nextGame = NG_NOTHING; scum(1, 1000, 5); break; case NG_QUIT: // No need to do anything. break; default: break; } } while (rogue.nextGame != NG_QUIT); }
void move(Map *map, char direction) { //If there is a collision return. Else move. if (isCollision(map, direction) == 1) return; else { checkItemPickup(map, direction); //Checks movement direction then applies the movement. Will handle collision switch (direction) { case 0: break; //Movement case MOVE_UP: map->map[map->currentPlayerLocation[0]][map->currentPlayerLocation[1]] = '-'; map->map[map->currentPlayerLocation[0] - 1][map->currentPlayerLocation[1]] = PLAYER; map->currentPlayerLocation[0] -= 1; break; case MOVE_LEFT: map->map[map->currentPlayerLocation[0]][map->currentPlayerLocation[1]] = '-'; map->map[map->currentPlayerLocation[0]][map->currentPlayerLocation[1] - 1] = PLAYER; map->currentPlayerLocation[1] -= 1; break; case MOVE_RIGHT: map->map[map->currentPlayerLocation[0]][map->currentPlayerLocation[1]] = '-'; map->map[map->currentPlayerLocation[0]][map->currentPlayerLocation[1] + 1] = PLAYER; map->currentPlayerLocation[1] += 1; break; case MOVE_DOWN: map->map[map->currentPlayerLocation[0]][map->currentPlayerLocation[1]] = '-'; map->map[map->currentPlayerLocation[0] + 1][map->currentPlayerLocation[1]] = PLAYER; map->currentPlayerLocation[0] += 1; break; //Checks if other keys are pressed case QUIT_KEY: printf("Quitting...\n"); freeEverything(map); exit(1); break; case INV_KEY: showInventory(); break; case SPACEBAR: check = checkNPC(map); if (check != 0) { printf("Check was successful\n"); int i; for (i = 0; i < 1; i++) { if (map->npcs[i]->location[0] == *(check + i) && map->npcs[i]->location[1] == *(check + 1 + i)) talkNPC(map, map->npcs[i]); else printf("Error talking to NPC\n"); } } break; default: printMap(map); } } //Checks if inventory is closed. If so, print the map if (inventoryOpen == 0) { printMap(map); } }
int main(){ int options; printf("\nWelcome to The Song Database."); while (options != 5) { options = intro(); if (options == 1) { char* artist; char* album; char* song_title; char* date; char* song_time_char; int song_time; artist = malloc (MAX_SIZE); album = malloc (MAX_SIZE); song_title = malloc (MAX_SIZE); date = malloc (MAX_SIZE); song_time_char = malloc (MAX_SIZE); printf ("\nPlease enter the artist name: "); fgets (artist, MAX_SIZE, stdin); if ((strlen(artist)>0) && (artist[strlen (artist) - 1] == '\n')) artist[strlen (artist) - 1] = '\0'; printf ("Please enter the album name: "); fgets (album, MAX_SIZE, stdin); if ((strlen(album)>0) && (album[strlen (album) - 1] == '\n')) album[strlen (album) - 1] = '\0'; printf("Please enter the song title: "); fgets (song_title, MAX_SIZE, stdin); if ((strlen(song_title)>0) && (song_title[strlen (song_title) - 1] == '\n')) song_title[strlen (song_title) - 1] = '\0'; printf("Please enter the date: "); fgets (date, MAX_SIZE, stdin); if ((strlen(date)>0) && (date[strlen (date) - 1] == '\n')) date[strlen (date) - 1] = '\0'; printf("Please enter song time: "); fgets(song_time_char, MAX_SIZE, stdin); if ((strlen(song_time_char)>0) && (song_time_char[strlen (song_time_char) - 1] == '\n')) song_time_char[strlen (song_time_char) - 1] = '\0'; song_time = atoi(song_time_char); pushItem(artist, album, song_title, date, song_time); free(artist); free(album); free(song_title); free(date); free(song_time_char); } else if (options == 2) { delete_artist(); } else if (options == 3) { if (head == NULL) { printf("\nNo entries found\n"); } else { printf("\nPrinting it forward:\n"); print_forward(head); } } else if (options == 4) { if (head == NULL) { printf("\nNo entries found\n"); } else { printf("\nPrinting it backward\n"); print_backward(tail); } } else if (options == 5) { freeEverything(head); printf("\nGoodbye.\n"); break; } else { printf("\nNo Valid Input\n"); } } return 0; }
int main(int argc, char **argv) { // Declarations for getopt extern int optind; extern char * optarg; int ch; char * format = "f:hnBm:"; // Default makefile name will be Makefile char szMakefile[64] = "Makefile"; char szTarget[64]; char szLog[64]; while((ch = getopt(argc, argv, format)) != -1) { switch(ch) { case 'f': strcpy(szMakefile, strdup(optarg)); break; case 'n': commands[0] = 1; break; case 'B': commands[1] = 1; break; case 'm': commands[2] = 1; strcpy(szLog, strdup(optarg)); break; case 'h': default: show_error_message(argv[0]); exit(1); } } argc -= optind; argv += optind; // at this point, what is left in argv is the targets that were // specified on the command line. argc has the number of them. // If getopt is still really confusing, // try printing out what's in argv right here, then just running // with various command-line arguments. //redirect output if option is given if(commands[2]) { int fd; if((fd = open(szLog, O_CREAT | O_WRONLY, 0644)) == -1) { printf("Error opening log file\n"); return EXIT_FAILURE; } if(dup2(fd, 1) == -1) { printf("Error redirecting the output\n"); return EXIT_FAILURE; } if(close(fd) == -1) { printf("Error closing log file\n"); return EXIT_FAILURE; } } if(argc > 1) { show_error_message(argv[1]); return EXIT_FAILURE; } char* defTarget; /* Parse graph file or die */ if((parse(szMakefile, &defTarget)) == -1) { return EXIT_FAILURE; } assignParents(); //You may start your program by setting the target that make4061 should build. //if target is not set, set it to default (first target from makefile) if(argc == 1) { targ = argv[0]; if(removeNonTargets(argv[0]) == -1) { printf("Error: target was not found"); return EXIT_FAILURE; } } else { targ = defTarget; if(removeNonTargets(defTarget) == -1) { printf("Error: target was not found"); return EXIT_FAILURE; } } //printNodes(); if(run() == -1){ show_error_message(argv[0]); return EXIT_FAILURE; } //free all data structures freeEverything(); //after parsing the file, you'll want to check all dependencies (whether they are available targets or files) //then execute all of the targets that were specified on the command line, along with their dependencies, etc. return EXIT_SUCCESS; }