Sie sind auf Seite 1von 7

package minesweeper;

import java.util.*;
import static minesweeper.minesweeper.display10by10;
public class minesweeper
{
private static String[][] display10by10;

public static void main(String[] args)


{
int bombList5by5[][] ={ {0,0,1,0,0},
{0,0,0,0,0},
{0,1,0,0,0},
{0,0,0,1,1},
{0,1,1,0,0} };
char xbombList5by5[][] = { {'1', '1', 'X', '1', '1'},
{'2', '2', '2', '2', '2'},
{'3', 'X', '3', '3', '3'},
{'4', '4', '4', 'X', 'X'},
{'5', 'X', 'X', '5', '5'} };

char zbombList5by5[][] = { {' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' '} };

int bombList10by10[][] ={ {0,0,1,0,0,0,0,1,0,0},


{0,0,0,0,0,0,0,0,0,0},
{0,1,0,0,0,0,1,0,0,0},
{0,0,0,1,1,0,0,0,1,1},
{0,1,1,0,0,0,1,1,0,0},
{0,0,1,0,0,0,0,1,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,1,0,0,0,0,1,0,0,0},
{0,0,0,1,1,0,0,0,1,1},
{0,1,1,0,0,0,1,1,0,0} };

char xbombList10by10[][] = { {'1', 'X', 'X', '1', '1', 'X', '1', '1', '1',
'X'},
{'2', '2', 'X', '2', '2', '2', 'X', 'X', '2', '2'},
{'3', '3', '3', '3', '3', '3', '3', '3', '3', 'X'},
{'X', '4', '4', '4', '4', 'X', '4', '4', '4', '4'},
{'5', '5', 'X', '5', '5', '5', '5', '5', '5', '5'},
{'6', '6', '6', '6', '6', '6', '6', 'X', 'X', '6'},
{'7', 'X', '7', '7', '7', 'X', '7', '7', '7', 'X'},
{'8', '8', 'X', '8', '8', '8', '8', '8', '8', '8'},
{'9', '9', 'X', '9', '9', 'X', '9', '9', '9', '9'},
{'X', '1', 'X', '1', '1', '1', '1', 'X', '1',
'X'} };

char zbombList10by10[][] = { {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '
'},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '
'},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '
'},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '
'},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '
'},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '
'},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '
'},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '
'},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}
};
int row_max = 0;
int col_max = 0;
Scanner scan = new Scanner(System.in);

System.out.println("********* MINESWEEPER *********");


System.out.println("-------------------------------");
System.out.println("\tChoose Size of Grid\t");
System.out.println("-------------------------------");
System.out.println("\t[A] 5x5 Grid \t");
System.out.println("\t[B] 10x10 Grid\t");
System.out.println("-------------------------------");
System.out.print("Choose: ");
String choice = scan.next();
if(choice.equalsIgnoreCase("1"))
{
display5by5();

for(int x = 0 ; x < 19 ; x++){

System.out.print("Enter Row:");
row_max = scan.nextInt();
System.out.print("Enter Column:");
col_max = scan.nextInt();

if (bombList5by5[row_max][col_max] == 1)
{
System.out.println("[" + xbombList5by5[0][0] + "] [" +
xbombList5by5[0][1] + "] [" + xbombList5by5[0][2] + "] [" + xbombList5by5[0][3] +
"] [" + xbombList5by5[0][4] + "] ");
System.out.println("[" + xbombList5by5[1][0] + "] [" +
xbombList5by5[1][1] + "] [" + xbombList5by5[1][2] + "] [" + xbombList5by5[1][3] +
"] [" + xbombList5by5[1][4] + "] ");
System.out.println("[" + xbombList5by5[2][0] + "] [" +
xbombList5by5[2][1] + "] [" + xbombList5by5[2][2] + "] [" + xbombList5by5[2][3] +
"] [" + xbombList5by5[2][4] + "] ");
System.out.println("[" + xbombList5by5[3][0] + "] [" +
xbombList5by5[3][1] + "] [" + xbombList5by5[3][2] + "] [" + xbombList5by5[3][3] +
"] [" + xbombList5by5[3][4] + "] ");
System.out.println("[" + xbombList5by5[4][0] + "] [" +
xbombList5by5[4][1] + "] [" + xbombList5by5[4][2] + "] [" + xbombList5by5[4][3] +
"] [" + xbombList5by5[4][4] + "] ");
System.out.println("Ooppps! You stepped on a bomb. Sorry,
game over! ");
x = 19;

}
else if (zbombList5by5[row_max][col_max] != ' '){
System.out.println("You already mark this coordinates! ");
x--;
}
else if (bombList5by5[row_max][col_max] == 0){
if (row_max == 0 ){
zbombList5by5[row_max][col_max] = '1';
}
else if (row_max == 1 ){
zbombList5by5[row_max][col_max] = '2';
}
else if (row_max == 2 ){
zbombList5by5[row_max][col_max] = '3';
}
else if (row_max == 3 ){
zbombList5by5[row_max][col_max] = '4';
}
else if (row_max == 4 ){
zbombList5by5[row_max][col_max] = '5';
}
System.out.println("[" + zbombList5by5[0][0] + "] [" +
zbombList5by5[0][1] + "] [" + zbombList5by5[0][2] + "] [" + zbombList5by5[0][3] +
"] [" + zbombList5by5[0][4] + "] ");
System.out.println("[" + zbombList5by5[1][0] + "] [" +
zbombList5by5[1][1] + "] [" + zbombList5by5[1][2] + "] [" + zbombList5by5[1][3] +
"] [" + zbombList5by5[1][4] + "] ");
System.out.println("[" + zbombList5by5[2][0] + "] [" +
zbombList5by5[2][1] + "] [" + zbombList5by5[2][2] + "] [" + zbombList5by5[2][3] +
"] [" + zbombList5by5[2][4] + "] ");
System.out.println("[" + zbombList5by5[3][0] + "] [" +
zbombList5by5[3][1] + "] [" + zbombList5by5[3][2] + "] [" + zbombList5by5[3][3] +
"] [" + zbombList5by5[3][4] + "] ");
System.out.println("[" + zbombList5by5[4][0] + "] [" +
zbombList5by5[4][1] + "] [" + zbombList5by5[4][2] + "] [" + zbombList5by5[4][3] +
"] [" + zbombList5by5[4][4] + "] ");

if (x == 18){
System.out.println("Congratulation You beat The
Minesweeper! ");
}
}
}
}
if(choice.equalsIgnoreCase("2"))
{
display10by10();
makeMove(bombList10by10,row_max,col_max,display10by10,display5by5);
for (int y = 0 ; y < 77 ; y++)
{

System.out.print("Enter Row:");
row_max = scan.nextInt();
System.out.print("Enter Column:");
col_max = scan.nextInt();

if (bombList10by10[row_max][col_max] == 1)
{
System.out.println("[" + xbombList10by10[0][0] + "] [" +
xbombList10by10[0][1] + "] [" + xbombList10by10[0][2] + "] [" + xbombList10by10[0]
[3] + "] [" + xbombList10by10[0][4] + "] [" + xbombList10by10[0][5] + "] [" +
xbombList10by10[0][6] + "] [" + xbombList10by10[0][7] + "] [" + xbombList10by10[0]
[8] + "] [" + xbombList10by10[0][9] + "]");
System.out.println("[" + xbombList10by10[1][0] + "] [" +
xbombList10by10[1][1] + "] [" + xbombList10by10[1][2] + "] [" + xbombList10by10[1]
[3] + "] [" + xbombList10by10[1][4] + "] [" + xbombList10by10[1][5] + "] [" +
xbombList10by10[1][6] + "] [" + xbombList10by10[1][7] + "] [" + xbombList10by10[1]
[8] + "] [" + xbombList10by10[1][9] + "]");
System.out.println("[" + xbombList10by10[2][0] + "] [" +
xbombList10by10[2][1] + "] [" + xbombList10by10[2][2] + "] [" + xbombList10by10[2]
[3] + "] [" + xbombList10by10[2][4] + "] [" + xbombList10by10[2][5] + "] [" +
xbombList10by10[2][6] + "] [" + xbombList10by10[2][7] + "] [" + xbombList10by10[2]
[8] + "] [" + xbombList10by10[2][9] + "]");
System.out.println("[" + xbombList10by10[3][0] + "] [" +
xbombList10by10[3][1] + "] [" + xbombList10by10[3][2] + "] [" + xbombList10by10[3]
[3] + "] [" + xbombList10by10[3][4] + "] [" + xbombList10by10[3][5] + "] [" +
xbombList10by10[3][6] + "] [" + xbombList10by10[3][7] + "] [" + xbombList10by10[3]
[8] + "] [" + xbombList10by10[3][9] + "]");
System.out.println("[" + xbombList10by10[4][0] + "] [" +
xbombList10by10[4][1] + "] [" + xbombList10by10[4][2] + "] [" + xbombList10by10[4]
[3] + "] [" + xbombList10by10[4][4] + "] [" + xbombList10by10[4][5] + "] [" +
xbombList10by10[4][6] + "] [" + xbombList10by10[4][7] + "] [" + xbombList10by10[4]
[8] + "] [" + xbombList10by10[4][9] + "]");
System.out.println("[" + xbombList10by10[5][0] + "] [" +
xbombList10by10[5][1] + "] [" + xbombList10by10[5][2] + "] [" + xbombList10by10[5]
[3] + "] [" + xbombList10by10[5][4] + "] [" + xbombList10by10[5][5] + "] [" +
xbombList10by10[5][6] + "] [" + xbombList10by10[5][7] + "] [" + xbombList10by10[5]
[8] + "] [" + xbombList10by10[5][9] + "]");
System.out.println("[" + xbombList10by10[6][0] + "] [" +
xbombList10by10[6][1] + "] [" + xbombList10by10[6][2] + "] [" + xbombList10by10[6]
[3] + "] [" + xbombList10by10[6][4] + "] [" + xbombList10by10[6][5] + "] [" +
xbombList10by10[6][6] + "] [" + xbombList10by10[6][7] + "] [" + xbombList10by10[6]
[8] + "] [" + xbombList10by10[6][9] + "]");
System.out.println("[" + xbombList10by10[7][0] + "] [" +
xbombList10by10[7][1] + "] [" + xbombList10by10[7][2] + "] [" + xbombList10by10[7]
[3] + "] [" + xbombList10by10[7][4] + "] [" + xbombList10by10[7][5] + "] [" +
xbombList10by10[7][6] + "] [" + xbombList10by10[7][7] + "] [" + xbombList10by10[7]
[8] + "] [" + xbombList10by10[7][9] + "]");
System.out.println("[" + xbombList10by10[8][0] + "] [" +
xbombList10by10[8][1] + "] [" + xbombList10by10[8][2] + "] [" + xbombList10by10[8]
[3] + "] [" + xbombList10by10[8][4] + "] [" + xbombList10by10[8][5] + "] [" +
xbombList10by10[8][6] + "] [" + xbombList10by10[8][7] + "] [" + xbombList10by10[8]
[8] + "] [" + xbombList10by10[8][9] + "]");
System.out.println("[" + xbombList10by10[9][0] + "] [" +
xbombList10by10[9][1] + "] [" + xbombList10by10[9][2] + "] [" + xbombList10by10[9]
[3] + "] [" + xbombList10by10[9][4] + "] [" + xbombList10by10[9][5] + "] [" +
xbombList10by10[9][6] + "] [" + xbombList10by10[9][7] + "] [" + xbombList10by10[9]
[8] + "] [" + xbombList10by10[9][9] + "]");
System.out.println("Ooppps! You stepped on a bomb. Sorry,
game over! ");
y = 77;
}
else if (zbombList10by10[row_max][col_max] != ' ')
{
System.out.println("You already mark this coordinates! ");
y--;
}
else if (bombList10by10[row_max][col_max] == 0)
{
if (row_max == 0 )
{
zbombList10by10[row_max][col_max] = '1';
}
else if (row_max == 1 )
{
zbombList10by10[row_max][col_max] = '2';
}
else if (row_max == 2 )
{
zbombList10by10[row_max][col_max] = '3';
}
else if (row_max == 3 )
{
zbombList10by10[row_max][col_max] = '4';
}
else if (row_max == 4 )
{
zbombList10by10[row_max][col_max] = '5';
}
else if (row_max == 5 )
{
zbombList10by10[row_max][col_max] = '6';
}
else if (row_max == 6 )
{
zbombList10by10[row_max][col_max] = '7';
}
else if (row_max == 7 )
{
zbombList10by10[row_max][col_max] = '8';
}
else if (row_max == 8 )
{
zbombList10by10[row_max][col_max] = '9';
}
else if (row_max == 9 )
{
zbombList10by10[row_max][col_max] = '1';
}
System.out.println("[" + zbombList10by10[0][0] + "] [" +
zbombList10by10[0][1] + "] [" + zbombList10by10[0][2] + "] [" + zbombList10by10[0]
[3] + "] [" + zbombList10by10[0][4] + "] [" + zbombList10by10[0][5] + "] [" +
zbombList10by10[0][6] + "] [" + zbombList10by10[0][7] + "] [" + zbombList10by10[0]
[8] + "] [" + zbombList10by10[0][9] + "]");
System.out.println("[" + zbombList10by10[1][0] + "] [" +
zbombList10by10[1][1] + "] [" + zbombList10by10[1][2] + "] [" + zbombList10by10[1]
[3] + "] [" + zbombList10by10[1][4] + "] [" + zbombList10by10[1][5] + "] [" +
zbombList10by10[1][6] + "] [" + zbombList10by10[1][7] + "] [" + zbombList10by10[1]
[8] + "] [" + zbombList10by10[1][9] + "]");
System.out.println("[" + zbombList10by10[2][0] + "] [" +
zbombList10by10[2][1] + "] [" + zbombList10by10[2][2] + "] [" + zbombList10by10[2]
[3] + "] [" + zbombList10by10[2][4] + "] [" + zbombList10by10[2][5] + "] [" +
zbombList10by10[2][6] + "] [" + zbombList10by10[2][7] + "] [" + zbombList10by10[2]
[8] + "] [" + zbombList10by10[2][9] + "]");
System.out.println("[" + zbombList10by10[3][0] + "] [" +
zbombList10by10[3][1] + "] [" + zbombList10by10[3][2] + "] [" + zbombList10by10[3]
[3] + "] [" + zbombList10by10[3][4] + "] [" + zbombList10by10[3][5] + "] [" +
zbombList10by10[3][6] + "] [" + zbombList10by10[3][7] + "] [" + zbombList10by10[3]
[8] + "] [" + zbombList10by10[3][9] + "]");
System.out.println("[" + zbombList10by10[4][0] + "] [" +
zbombList10by10[4][1] + "] [" + zbombList10by10[4][2] + "] [" + zbombList10by10[4]
[3] + "] [" + zbombList10by10[4][4] + "] [" + zbombList10by10[4][5] + "] [" +
zbombList10by10[4][6] + "] [" + zbombList10by10[4][7] + "] [" + zbombList10by10[4]
[8] + "] [" + zbombList10by10[4][9] + "]");
System.out.println("[" + zbombList10by10[5][0] + "] [" +
zbombList10by10[5][1] + "] [" + zbombList10by10[5][2] + "] [" + zbombList10by10[5]
[3] + "] [" + zbombList10by10[5][4] + "] [" + zbombList10by10[5][5] + "] [" +
zbombList10by10[5][6] + "] [" + zbombList10by10[5][7] + "] [" + zbombList10by10[5]
[8] + "] [" + zbombList10by10[5][9] + "]");
System.out.println("[" + zbombList10by10[6][0] + "] [" +
zbombList10by10[6][1] + "] [" + zbombList10by10[6][2] + "] [" + zbombList10by10[6]
[3] + "] [" + zbombList10by10[6][4] + "] [" + zbombList10by10[6][5] + "] [" +
zbombList10by10[6][6] + "] [" + zbombList10by10[6][7] + "] [" + zbombList10by10[6]
[8] + "] [" + zbombList10by10[6][9] + "]");
System.out.println("[" + zbombList10by10[7][0] + "] [" +
zbombList10by10[7][1] + "] [" + zbombList10by10[7][2] + "] [" + zbombList10by10[7]
[3] + "] [" + zbombList10by10[7][4] + "] [" + zbombList10by10[7][5] + "] [" +
zbombList10by10[7][6] + "] [" + zbombList10by10[7][7] + "] [" + zbombList10by10[7]
[8] + "] [" + zbombList10by10[7][9] + "]");
System.out.println("[" + zbombList10by10[8][0] + "] [" +
zbombList10by10[8][1] + "] [" + zbombList10by10[8][2] + "] [" + zbombList10by10[8]
[3] + "] [" + zbombList10by10[8][4] + "] [" + zbombList10by10[8][5] + "] [" +
zbombList10by10[8][6] + "] [" + zbombList10by10[8][7] + "] [" + zbombList10by10[8]
[8] + "] [" + zbombList10by10[8][9] + "]");
System.out.println("[" + zbombList10by10[9][0] + "] [" +
zbombList10by10[9][1] + "] [" + zbombList10by10[9][2] + "] [" + zbombList10by10[9]
[3] + "] [" + zbombList10by10[9][4] + "] [" + zbombList10by10[9][5] + "] [" +
zbombList10by10[9][6] + "] [" + zbombList10by10[9][7] + "] [" + zbombList10by10[9]
[8] + "] [" + zbombList10by10[9][9] + "]");

if (y == 76)
{
System.out.println("Congratulation You beat The
Minesweeper! ");
}
}

}
}

}
public static void display5by5()
{
for(int x=1; x<=5; x++)
{
for(int z=1; z<=5; z++)
{
System.out.print("[]");
}
System.out.println("");
}
}
public static void display10by10()
{
for(int k=1; k<=10; k++)
{
for(int i=1; i<=10 ;i++)
{
System.out.print("[]");
}
System.out.println("");
}
}
public static void makeMove(int[][] bombList5by5,int[][] bombList10by10,int
row_max,int col_max, String[][] display10by10,String[][] display5by5)
{
int bomb_row=0;
int bomb_col=0;
int bombrowcol = bomb_row+bomb_col;
String bombN = String.valueOf(bombrowcol);
for(int i=0; i<5; i++)
{
if(bombList5by5[row_max][i]==1)
{
++bomb_row;
}
if(bombList5by5[col_max][i]==1)
{
++bomb_col;
}

}
display5by5[row_max][col_max]="["+bombN+"]";

for(int k=0; k<10; k++)


{
if(bombList10by10[row_max][k]==1)
{
++bomb_row;
}
if(bombList10by10[col_max][k]==1)
{
++bomb_col;
}
}//for

display10by10[row_max][col_max]="["+bombN+"]";

Das könnte Ihnen auch gefallen