COP 2800 Assignment 4 This is a simplified minesweeper game. The player moves fr
ID: 669300 • Letter: C
Question
COP 2800
Assignment 4
This is a simplified minesweeper game. The player moves from the starting position on the board to the finish without stepping on a bomb.
Your program must work like this...
Player starts in upper left
Player moves one space at a time
Player can only move right or down. Ignore any other input.
Player cannot move off the board
Player wins when he/she reaches lower right corner
Player loses if he/she steps on a bomb
Your program should prompt for the size of the board. Ensure that input is at least size 3. Place one bomb for a 3X3 board. Add an additional bomb for each row above 3.
Bombs must be placed randomly. Your instructor will check this thoroughly.
Insure that bombs are not placed at the start or the finish.
Game board should be printed out in a user friendly fashion at the start and after each move, except the last. Since you are doing this as a homework exercise rather than a real game, your board display should show where the bombs are. This will make it easier for your instructor to grade your program.
See the 4 pages of sample output included in this document.
You are free to design your program any way you wish, with one stipulation. The intent of this exercise is to give you experience with arrays in Java. The game board must implemented in your program as an array.
Submit a single .java file. Programs that do not compile with receive a grade of 0.
COP 2800
Assignment 4
This is a simplified minesweeper game. The player moves from the starting position on the board to the finish without stepping on a bomb.
Your program must work like this...
Player starts in upper left
Player moves one space at a time
Player can only move right or down. Ignore any other input.
Player cannot move off the board
Player wins when he/she reaches lower right corner
Player loses if he/she steps on a bomb
Your program should prompt for the size of the board. Ensure that input is at least size 3. Place one bomb for a 3X3 board. Add an additional bomb for each row above 3.
Bombs must be placed randomly. Your instructor will check this thoroughly.
Insure that bombs are not placed at the start or the finish.
Game board should be printed out in a user friendly fashion at the start and after each move, except the last. Since you are doing this as a homework exercise rather than a real game, your board display should show where the bombs are. This will make it easier for your instructor to grade your program.
See the 4 pages of sample output included in this document.
You are free to design your program any way you wish, with one stipulation. The intent of this exercise is to give you experience with arrays in Java. The game board must implemented in your program as an array.
Submit a single .java file. Programs that do not compile with receive a grade of 0.
COP 2800
Assignment 4
This is a simplified minesweeper game. The player moves from the starting position on the board to the finish without stepping on a bomb.
Your program must work like this...
Player starts in upper left
Player moves one space at a time
Player can only move right or down. Ignore any other input.
Player cannot move off the board
Player wins when he/she reaches lower right corner
Player loses if he/she steps on a bomb
Your program should prompt for the size of the board. Ensure that input is at least size 3. Place one bomb for a 3X3 board. Add an additional bomb for each row above 3.
Bombs must be placed randomly. Your instructor will check this thoroughly.
Insure that bombs are not placed at the start or the finish.
Game board should be printed out in a user friendly fashion at the start and after each move, except the last. Since you are doing this as a homework exercise rather than a real game, your board display should show where the bombs are. This will make it easier for your instructor to grade your program.
See the 4 pages of sample output included in this document.
You are free to design your program any way you wish, with one stipulation. The intent of this exercise is to give you experience with arrays in Java. The game board must implemented in your program as an array.
Submit a single .java file. Programs that do not compile with receive a grade of 0.
COP 2800
Assignment 4
This is a simplified minesweeper game. The player moves from the starting position on the board to the finish without stepping on a bomb.
Your program must work like this...
Player starts in upper left
Player moves one space at a time
Player can only move right or down. Ignore any other input.
Player cannot move off the board
Player wins when he/she reaches lower right corner
Player loses if he/she steps on a bomb
Your program should prompt for the size of the board. Ensure that input is at least size 3. Place one bomb for a 3X3 board. Add an additional bomb for each row above 3.
Bombs must be placed randomly. Your instructor will check this thoroughly.
Insure that bombs are not placed at the start or the finish.
Game board should be printed out in a user friendly fashion at the start and after each move, except the last. Since you are doing this as a homework exercise rather than a real game, your board display should show where the bombs are. This will make it easier for your instructor to grade your program.
See the 4 pages of sample output included in this document.
You are free to design your program any way you wish, with one stipulation. The intent of this exercise is to give you experience with arrays in Java. The game board must implemented in your program as an array.
Submit a single .java file. Programs that do not compile with receive a grade of 0.
COP 2800
Assignment 4
This is a simplified minesweeper game. The player moves from the starting position on the board to the finish without stepping on a bomb.
Your program must work like this...
Player starts in upper left
Player moves one space at a time
Player can only move right or down. Ignore any other input.
Player cannot move off the board
Player wins when he/she reaches lower right corner
Player loses if he/she steps on a bomb
Your program should prompt for the size of the board. Ensure that input is at least size 3. Place one bomb for a 3X3 board. Add an additional bomb for each row above 3.
Bombs must be placed randomly. Your instructor will check this thoroughly.
Insure that bombs are not placed at the start or the finish.
Game board should be printed out in a user friendly fashion at the start and after each move, except the last. Since you are doing this as a homework exercise rather than a real game, your board display should show where the bombs are. This will make it easier for your instructor to grade your program.
See the 4 pages of sample output included in this document.
You are free to design your program any way you wish, with one stipulation. The intent of this exercise is to give you experience with arrays in Java. The game board must implemented in your program as an array.
Submit a single .java file. Programs that do not compile with receive a grade of 0.
COP 2800
Assignment 4
This is a simplified minesweeper game. The player moves from the starting position on the board to the finish without stepping on a bomb.
Your program must work like this...
Player starts in upper left
Player moves one space at a time
Player can only move right or down. Ignore any other input.
Player cannot move off the board
Player wins when he/she reaches lower right corner
Player loses if he/she steps on a bomb
Your program should prompt for the size of the board. Ensure that input is at least size 3. Place one bomb for a 3X3 board. Add an additional bomb for each row above 3.
Bombs must be placed randomly. Your instructor will check this thoroughly.
Insure that bombs are not placed at the start or the finish.
Game board should be printed out in a user friendly fashion at the start and after each move, except the last. Since you are doing this as a homework exercise rather than a real game, your board display should show where the bombs are. This will make it easier for your instructor to grade your program.
See the 4 pages of sample output included in this document.
You are free to design your program any way you wish, with one stipulation. The intent of this exercise is to give you experience with arrays in Java. The game board must implemented in your program as an array.
Submit a single .java file. Programs that do not compile with receive a grade of 0.
Explanation / Answer
Minesweeper game implemented in java
public class Minesweeper {
public static void main(String[] args) {
int M = Integer.parseInt(args[0]);
int N = Integer.parseInt(args[1]);
double p = Double.parseDouble(args[2]);
boolean[][] bombs = new boolean[M+2][N+2];
for (int i = 1; i <= M; i++)
for (int j = 1; j <= N; j++)
bombs[i][j] = (Math.random() < p);
for (int i = 1; i <= M; i++) {
for (int j = 1; j <= N; j++)
if (bombs[i][j]) System.out.print("* ");
else System.out.print(". ");
System.out.println();
}
int[][] sol = new int[M+2][N+2];
for (int i = 1; i <= M; i++)
for (int j = 1; j <= N; j++)
// (ii, jj) indexes neighboring cells
for (int ii = i - 1; ii <= i + 1; ii++)
for (int jj = j - 1; jj <= j + 1; jj++)
if (bombs[ii][jj]) sol[i][j]++;
System.out.println();
for (int i = 1; i <= M; i++) {
for (int j = 1; j <= N; j++) {
if (bombs[i][j]) System.out.print("* ");
else System.out.print(sol[i][j] + " ");
}
System.out.println();
}
}
}