import java.util.Scanner;
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("\t欢迎进入扫雷游戏v1.0");
System.out.println("\t\t\t作者:木 木");
System.out.println();
//Map.start();
int step = 0;
while (Map.isGameOn) {
System.out.println("请输入要查看的行数和列数,还剩"+(61-step)+"安全");
int a = sc.nextInt();
if(a==100) {
Map.fun();
break;
}
int b = a%10;
a = a/10;
Map.upMap(a,b);
step++;
if (step>60) {
System.out.println("你赢了!你居然赢了!你一定是作弊了!");
break;
}
}
if (!Map.isGameOn) {
step--;
System.out.println("你踩到地雷了!");
}
System.out.println("获得分数:"+step);
}
}
-----------------------------------------------------------------------
class Map {
private static int[][] map =new int[10][10];
static boolean isGameOn = true;
static {
bitMap();
boom();
showMap();
}
private static void bitMap(){
map[0][0] = 0;
for (int i = 1;i<10 ;i++ ) {
map[0][i] = i;
map[i][0] = i;
}
}
private static void boom() {
int n = 0;
int p = 0;
int q = 0;
while (n<20) {
p = (int)(Math.random()*10);
q = (int)(Math.random()*10);
if (p!=0&&q!=0&&map[p][q]!= -2) {
map[p][q] = -2;
n++;
} else {
continue;
}
}
}
private static void showMap() {
for (int i = 0;i<10 ;i++ ) {
for (int j = 0;j<10 ;j++ ) {
if (i==0&&j==0) {
System.out.print(" ");
} else if(map[i][j]==0||map[i][j]==-2) {
System.out.print("囧 ");
} else if (map[i][j]==-1) {
System.out.print(" ");
} else if (map[i][j]==-3) {
System.out.println("X ");
} else {
System.out.print(map[i][j]+" ");
}
}
System.out.println();
System.out.println();
}
}
static void upMap(int a,int b) {
if (a>0&&a<10&&b>0&&b<10) {
if (map[a][b]==-2) {
map[a][b] = -3;
isGameOn = false;
return;
}
map[a][b] = check(a,b);
if (map[a][b]==0) {
map[a][b]=-1;
}
} else {
System.out.println("你只能在这控制选择");
}
showMap();
}
public static void fun(){
for (int i=0;i<10 ;i++ ) {
for (int j=0;j<10 ;j++ ) {
if (map[i][j]!=-2) {
upMap(i,j);
}
}
}
}
private static int check(int a,int b) {
int n = 0;
if (map[a-1][b]==-2) {
n++;
}
if (map[a][b-1]==-2) {
n++;
}
if (a+1<10&&map[a+1][b]==-2) {
n++;
}
if (b+1<10&&map[a][b+1]==-2) {
n++;
}
if (map[a-1][b-1]==-2) {
n++;
}
if (b+1<10&&map[a-1][b+1]==-2) {
n++;
}
if (a+1<10&&b+1<10&&map[a+1][b+1]==-2) {
n++;
}
if (a+1<10&&map[a+1][b-1]==-2) {
n++;
}
return n;
}
}
|