java - 2D Char array Minesweeper game loop -


i'm comp sci student taking intro comp sci. right working on end of year project text based minesweeper game using java. first part suppose make representation of 5x5 minesweeper board 2 d char array , manually add bomb locations , update numbers indicate neighboring bombs.then create second representation of board represent whether or not cell has been revealed.

after need write following methods:

print board(char[][] board, boolean[][] revealed): prints minesweeper board screen in text form. keep in mind, printed board should reflect cells have been revealed.

reveal cell(int row, int col, boolean[][] game board, char[][] answers board): appropriately modifies state array when cell revealed while determining how reveal surrounding blank spaces according rules of minesweeper.

then have write main game loops incorporates both of these methods while checking see if player won or lost.

i've done print board , reveal cell method, need make game board , game loop test it.

we not aloud use classes or modules outside java.lang (do not import libraries).

here code:
public static void main(string[] args) {

char[][]answerboard= {{'b', '1', '0', '1', 'b'},                       {'1', '1', '1', '2', '1'},                       {'0', '1', 'b', '2', '1'},                       {'1', '1', '1', '2', 'b'},                       {'b', '1', '0', '1', '1'}}; // initialized answer board: board shows inside each cell. need create second 2d array representation shows cells have been revealed. int row , col ; (row = 0; row < answerboard.length; row++){      (col = 0; col < answerboard[1].length; col++)      system.out.print(answerboard[row][col]);      system.out.println();      }   }   public static void printboard(char[][] board, boolean[][] isrevealed)      {         for(int i=0; < board.length; i++)         {                 for(int j=0; j<=board[0].length; j++)                 {                         if(isrevealed[i][j]=true)                         system.out.print(board[i][j]+" ");//prints hidden char                         else                         if(isrevealed[i][j]= false)                         system.out.print("- ");                 }                 system.out.println(" ");         }  }      public static void revealcell(int row, int col, boolean[][] gameboard, char[][]answersboard) {     system.out.println(row + " " + col);     if(row < 0|| row >=answersboard.length ||col < 0|| col > answersboard[0].length){         system.out.println("bad input");         return;     }      if(answersboard[row][col] == 'b'){         gameboard[row][col] = answersboard[row][col];         return;     }     if(answersboard[row][col] == '1'||answersboard[row][col] == '2'){         gameboard[row][col] = answersboard[row][col];         return;     }      if(answersboard[row][col] == '0'){         gameboard[row][col] = answersboard[row][col];         for(int = row-1; <= row +1; i++){             for(int j = col-1; j<= col +1;j++){                 revealcell(i,j, gameboard, answersboard);             }         }     } } 

not sure question is... yeah doesn't asked one.

just suggestion, perhaps might idea make minesweeperboard class, , have these public non-static methods of class. teachers see first year students getting handle on object orients programming , able pull classes out of problems.

edit. shouldn't have system.out.println(...) stuff in methods supposed working on state of gameboard. creating side effects , breaks 1 task per method idea. rather have whatever method handling input/output decide if input appropriate prior calling method. ideally have these methods throw illegalargumentexceptions if give bad data method, may not have covered yet.

good luck on rest of project , exams!!


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -