/******************************************************************************* * MAIN FUNCTION */ int main( ) { int playAgain = 0; int missiles = 0; int validSelection = 0; int c; do { for ( c = 0; c < 80; c++ ) printf("\n"); // Clearing the screen printf("Select the difficulty\n"); printf("1- Easy\n"); printf("2- Medium\n"); printf("3- Hard\n\nOption: "); do { validSelection = 0; if ( scanf( "%1d", &missiles ) > 0 && (missiles == 1 || missiles == 2 || missiles == 3) ) validSelection = 1; else printf("Sorry, this is not a valid selection, try again: "); while ( getchar() != '\n' ); // Cleaning the buffer } while ( validSelection == 0 ); if ( missiles == 1 ) playBattleship(100); else if ( missiles == 2 ) playBattleship(75); else if ( missiles == 3 ) playBattleship(50); printf("Do you want to play again? (0 - No | 1 - Yes) \n"); do { validSelection = 0; if ( scanf( "%1d", &playAgain ) > 0 && (playAgain == 1 || playAgain == 0) ) validSelection = 1; else printf("Sorry, this is not a valid selection, try again: "); while ( getchar() != '\n' ); // Cleaning the buffer } while ( validSelection == 0 ); } while ( playAgain == 1 ); return 0; }
//Main function used to star the c battleship program int main() { playBattleship(); return 0; }