Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void promptUser(){
- Scanner scan = new Scanner(System.in);
- System.out.print("Pick a coordinate [row col] or press [q] to quit.");
- int row = 0;
- int row = 0;
- String line = scan.nextLine().trim();
- String[] contents = line.split(" ");
- if (contents[0] == "q"){
- isRunning = false;
- System.exit(0);
- }// if quit
- if (contents.length < 1 || contents.length > 2){
- System.out.print("Invalid Response. Try again.");
- promptUser();
- }// if wrong amount of input
- else {
- row = Integer.parseInt(contents[0]);
- col = Integer.parseInt(contents[1]);
- }// parse ints else
- if (inBounds(row, col) == true){
- if(!(board[row][col] == 'c'){
- click(row, col);
- }// has been clicked
- }// in bounds?
- else{
- System.out.print("Invalid response. Try again.");
- promptUser();
- }// else error
- }// promptUser method
- Exception in thread "main" java.lang.NumberFormatException: For input string: "q"
- at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
- at java.lang.Integer.parseInt(Integer.java:481)
- at java.lang.Integer.parseInt(Integer.java:514)
- at Minesweeper.promptUser(Minesweeper.java:197)
- at Driver.main(Driver.java:12)
- public void initialize(){
- isRunning = true;
- board = new char[this.rows][this.cols];
- for (int i = 0; i < board.length; i++){
- for(int j = 0; j < board[i].length; j++){
- board[i][j] = 'e';
- }
- }
- mineBoard = new boolean[this.rows][this.cols];
- for (int i = 0; i < mineBoard.length; i++){
- for (int j = 0; j < mineBoard[i].length; j++){
- mineBoard[i][j] = false;
- }
- }
- Random bob = new Random();
- Random sally = new Random();
- for (int i = mines; i > 0; i--){
- int mineX = bob.nextInt(10);
- int mineY = sally.nextInt(10);
- if (mineBoard[mineX][mineY] == false){
- mineBoard[mineX][mineY] = true;
- }
- else{
- i++;
- }
- }
- }
- private boolean inBounds(int row, int col){
- if (row < 0 || row > board.length){
- return false;
- }
- if (col < 0 || col > board[0].length){
- return false;
- }else
- return true;
- }
- contents[0].equals("q")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement