📄 map.java
字号:
import java.util.Random;
public class Map {
int i, j;
Random rd = new Random();
static final int BLANK = -1;
static final int SWIRL = -2;
static final int BONE = 99;
static final int SHIP = 0;
static final int ISLAND = 1;
static final int TREE = 2;
static final int BOTTLE = 3;
static final int HELPMAN = 4;
static final int BEAT = 5;
static final int ENEMY1 = 6;
static final int ENEMY2 = 7;
static final int ENEMY3 = 8;
static final int OBJECTS = 8;
static final int ROWCOL = 11;
static final int ALLLEVEL = 50; //总关数
int tmpRow, tmpCol;
int level[][] = { { 4, 2, 2, 1, 2, 4, 2, 0 }, { 5, 2, 1, 1, 1, 4, 3, 0 },
{ 6, 3, 2, 1, 1, 5, 2, 0 }, { 7, 3, 2, 1, 1, 5, 3, 0 },
{ 8, 4, 2, 0, 1, 6, 2, 0 }, { 9, 4, 1, 1, 1, 6, 3, 0 },
{ 10, 4, 1, 1, 1, 7, 2, 0 }, { 4, 3, 2, 1, 2, 4, 2, 0 },
{ 5, 3, 3, 1, 1, 4, 3, 0 }, { 6, 3, 3, 1, 1, 5, 2, 0 },//10
{ 7, 4, 2, 1, 1, 5, 3, 0 }, { 8, 4, 2, 0, 1, 6, 2, 0 },
{ 9, 5, 2, 1, 1, 6, 3, 0 }, { 10, 5, 3, 1, 1, 7, 2, 0 },
{ 6, 2, 1, 1, 1, 4, 3, 0 }, { 7, 3, 2, 1, 1, 5, 2, 0 },
{ 8, 3, 2, 1, 1, 5, 3, 0 }, { 9, 4, 2, 0, 1, 6, 2, 0 },
{ 10, 4, 1, 1, 1, 6, 3, 0 }, { 5, 2, 1, 1, 1, 7, 3, 0 }, //20
{ 6, 3, 2, 1, 1, 7, 3, 0 }, { 7, 3, 2, 1, 1, 8, 3, 0 },
{ 8, 4, 2, 0, 1, 8, 3, 0 }, { 9, 4, 1, 1, 1, 8, 4, 0 },
{ 10, 4, 1, 1, 1, 9, 4, 0 }, { 5, 2, 1, 1, 1, 7, 3, 0 },
{ 6, 3, 2, 1, 1, 7, 3, 0 }, { 7, 3, 2, 1, 1, 8, 3, 0 },
{ 8, 4, 2, 0, 1, 8, 3, 0 }, { 9, 4, 1, 1, 1, 8, 4, 0 },//30
{ 10, 4, 1, 1, 1, 9, 4, 0 }, { 11, 4, 1, 1, 1, 7, 2, 0 },
{ 5, 2, 1, 1, 1, 7, 3, 0 }, { 6, 3, 2, 1, 1, 7, 3, 0 },
{ 7, 3, 2, 1, 1, 8, 3, 0 }, { 8, 4, 2, 0, 1, 8, 3, 0 },
{ 9, 4, 1, 1, 1, 8, 4, 0 }, { 10, 4, 1, 1, 1, 9, 4, 0 },
{ 5, 2, 1, 1, 1, 7, 3, 0 }, { 6, 3, 2, 1, 1, 7, 3, 0 },//40
{ 7, 3, 2, 1, 1, 8, 3, 0 }, { 8, 4, 2, 0, 1, 8, 3, 0 },
{ 9, 4, 1, 1, 1, 8, 4, 0 }, { 10, 4, 1, 1, 1, 9, 4, 0 },
{ 11, 4, 1, 1, 1, 7, 5, 0 }, { 10, 4, 1, 1, 1, 9, 4, 0 },
{ 11, 5, 1, 1, 1, 7, 8, 0 }, { 11, 5, 1, 1, 1, 7, 8, 0 },
{ 10, 5, 1, 1, 1, 9, 9, 0 }, { 11, 5, 1, 1, 1, 7, 9, 0 },//50
};
public Map() {
}
public void createMap(int map[][], int levelNum) {
for (i = 0; i < ROWCOL; i++)
for (j = 0; j < ROWCOL; j++) {
map[i][j] = -1;
}
map[0][0] = -2;
map[0][10] = -2;
map[10][0] = -2;
map[10][10] = -2;
for (i = 0; i < OBJECTS; i++)
for (j = 0; j < level[levelNum - 1][i]; j++) {
tmpRow = getRandomInt(0, ROWCOL - 1);
switch (tmpRow) {
case 0:
case 10:
tmpCol = getRandomInt(1, 9);
while (map[tmpRow][tmpCol] != -1) {
tmpCol = getRandomInt(1, 9);
}
break;
case 1:
case 2:
case 8:
case 9:
tmpCol = getRandomInt(0, ROWCOL - 1);
while (map[tmpRow][tmpCol] != -1) {
tmpCol = getRandomInt(0, ROWCOL - 1);
}
break;
case 3:
case 4:
case 5:
case 6:
case 7:
tmpCol = getRandomInt(0, ROWCOL - 1);
while ((tmpCol >= 3 && tmpCol <= 7)
|| (map[tmpRow][tmpCol] != -1)) {
tmpCol = getRandomInt(0, ROWCOL - 1);
}
break;
}
switch (i) {
case 0:
map[tmpRow][tmpCol] = 1;
break;
case 1:
map[tmpRow][tmpCol] = 2;
break;
case 2:
map[tmpRow][tmpCol] = 3;
break;
case 3:
map[tmpRow][tmpCol] = 4;
break;
case 4:
map[tmpRow][tmpCol] = 5;
break;
case 5:
map[tmpRow][tmpCol] = 6;
break;
case 6:
map[tmpRow][tmpCol] = 7;
break;
case 7:
map[tmpRow][tmpCol] = 8;
break;
}
}
}
public int getEnemyNum(int levelNum) {
int nEnemy = level[levelNum - 1][4] + level[levelNum - 1][5]
+ level[levelNum - 1][6] + level[levelNum - 1][7];
return nEnemy;
}
public void createEnemy(int map[][], Anemy enemy[], int levelNum) {
int n = 0;
for (i = 0; i < ROWCOL; i++)
for (j = 0; j < ROWCOL; j++) {
if (map[i][j] == ENEMY1 || map[i][j] == ENEMY2
|| map[i][j] == ENEMY3 || map[i][j] == BEAT) {
enemy[n] = new Anemy(j, i, map[i][j]);
n++;
}
}
}
int getRandomInt(int min, int max) {
return Math.abs(rd.nextInt()) % (max - min + 1) + min;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -