/* * Battleship.java * * Version: * $Id: Battleship.java,v 1.2 2007/12/14 20:10:34 iaw5991 Exp iaw5991 $ * * Revision: * $Log: Battleship.java,v $ * Revision 1.2 2007/12/14 20:10:34 iaw5991 * Basic exception for too few arguments put in * * Revision 1.1 2007/12/12 23:07:44 iaw5991 * Initial revision * * */ import java.util.Scanner; /** * This is the main program to the Battlehip game * * @author Ian Wittenberg */ public class Battleship { /** * Main program * * @param args Command line arguments: board size and file */ public static void main( String[] args ) { if( args.length != 2 ) { throw new IllegalArgumentException( "Not enough args" ); } int size = Integer.parseInt( args[0] ); Scanner input = new Scanner( System.in ); Board board = new Board( size ); board.printBoard(); Scanner tokenizer; String command = ""; while(!command.equals( "quit" ) ) { System.out.print( "> " ); command = input.nextLine().trim(); //Implement a new Scanner to be able to tokenize the command tokenizer = new Scanner( command ); String firstCommand = tokenizer.next(); //Parse commands if(command.equals( "" ) ) { //Do nothing and let the loop reiterate }else if( firstCommand.equals( "board" ) ) { board.printBoard(); }else if( firstCommand.equals( "board2") ) { board.printBoard(); } } } }