扫雷——生成地雷(Java)
描述:生成地雷图,保存在int型二维数组中,-2表示灰色区域,-1表示地雷,数字1~8表示提示数字,用于说明数字周围的地雷数。输出中‘~’表示灰色区域,‘*’表示地雷,数字1~8表示提示数字。
说明:通过新建对象传递参数输入行、列、地雷数,其中最大行不超过24,最大列不超过30,地雷数根据行列的数学关系限制。结果可调用 printRes()函数查看。
注:该结果仅作后台判断使用!
源代码:
/**
* 布置地雷
* 输出:*(-1)-->地雷 (~)-2-->灰色区域 1~8-->提示数字
*
* 与SaoLei2相配,主函数中调用new SaoLei2();
*
* @author lixiang
*
*/
public class SaoLei {
public int rows; // 行
public int columns; // 列
public int count; // 地雷数
public int[][] data; // 存放数据信息
static int tipNum = 0; // 提示数字
public SaoLei(int rows, int columns, int count) {
this.rows = rows>24 ? 24 : rows; // 最大24行
this.columns = columns>30 ? 30 : columns; // 最大30列
this.count = count;
// 布置地雷
run();
// 输出
// printRes();