Exemple #1
0
int ask_save_game(Game* game) {
	
	/* Testing whether the game is saved of not. If not, asking the players if they want to save it */
	if(game->saved == NO) {
		
		/* If the answer is yes, retrieving the name of the file */
		if(ask_YN("Do you wish to save the game?") == YES) {
			
			char filename[MAX_FILE_NAME];
			printf("\nType the saving file's name (maximum of %d characters) : ", MAX_FILE_NAME);
			
			fgets(filename, MAX_FILE_NAME, stdin);
			
			/* Ungetting the last character readed if the string entered is too long */
			ungetc(filename[strlen(filename)-1], stdin);
			
			/* Emptying the buffer (so that extra characters won't be used for the next answer */
			empty_buffer();
			
			/* If the last character of the name is a new line (that fgets can put into a string), replacing it with a string terminating character */
			if(filename[strlen(filename)-1] == NL)
				filename[strlen(filename)-1] = '\0';
			
			/* If the file already exists and can be opened for writing, asking if the user wants to continue */
			if(exists_file(filename, W_OK) == YES) {
				printf("\nThis file already exists, saving the game will erase all its contents");
				
				/* If he doesn't want to, returning NO for the saving */
				if(ask_YN("\nDo you wish to continue?") == NO)
					return NO;
			}
			
			/* Saving the game, and if it has been saved, printing a message */
			if(game_saving(game, filename))
				printf("\nYour game has been saved in the file '%s'\n", filename);
			
			/* If it has not been saved, printing an error */
			else
				printf("\nSomething went wrong, the game has not been saved - don't get mad at me...");
		}
		
		/* If player don't want to save the game, returning NO for the saving */
		else
			return NO;
	}
	
	/* If the game was already saved, printing a message */
	else {
		printf("\nThe current game is already saved");
		
		/* Returning no for the saving */
		return NO;
	}
	
	/* Returning YES if it has been saved */
	return YES;
}
Exemple #2
0
int ask_new_game() {
	
	/* Asking for a new game */
	if(ask_YN("\nDo you want to start a new game?") == YES)
		return YES;
	else
		return NO;
}
Exemple #3
0
int ask_confirmation(const char*_format, ...)
{
  va_list ap;
  int res;
  WINDOW *window=newwin(LINES, COLS, 0, 0);	/* full screen */
  aff_copy(window);
  va_start(ap,_format);
  vaff_txt(4, window, _format, ap);
  va_end(ap);
  res=ask_YN(window);
  delwin(window);
  (void) clearok(stdscr, TRUE);
#ifdef HAVE_TOUCHWIN
  touchwin(stdscr);
#endif
  return res;
}