📄 bombermap.java
字号:
b = (Bonus)bonuses.elementAt(i);
if (b.r == r && b.c == c) {
bonuses.removeElementAt(i);
bonusGrid[b.r][b.c].kill();
bonusGrid[b.r][b.c] = null;
paintImmediately(b.r << BomberMain.shiftCount,
b.c << BomberMain.shiftCount, BomberMain.size,
BomberMain.size);
break;
}
i += 1;
k = bonuses.size();
}
}
/**
* Creates a bomb.
* @param x x-coordinate
* @param y y-coordinate
* @param owner owner
*/
public synchronized void createBomb(int x, int y, int owner) {
int _x = (x >> BomberMain.shiftCount) << BomberMain.shiftCount;
int _y = (y >> BomberMain.shiftCount) << BomberMain.shiftCount;
bombGrid[_x >> BomberMain.shiftCount][_y >> BomberMain.shiftCount] =
new BomberBomb(this, _x, _y, owner);
bombs.addElement(new Bomb(_x, _y));
}
/**
* Removes a bomb.
* @param x x-coordinate
* @param y y-coordinate
*/
public synchronized void removeBomb(int x, int y) {
int i = 0, k = bombs.size();
int r = (x >> BomberMain.shiftCount);
int c = (y >> BomberMain.shiftCount);
Bomb b = null;
while (i < k) {
b = (Bomb)bombs.elementAt(i);
if (b.r == r & b.c == c) {
bombs.removeElementAt(i);
break;
}
i += 1;
k = bombs.size();
}
}
/**
* Creates a fire.
* @param x x-coordinate
* @param y y-coordinate
* @param owner owner
* @param type fire type
*/
public void createFire(int x, int y, int owner, int type)
{
int _x = (x >> BomberMain.shiftCount) << BomberMain.shiftCount;
int _y = (y >> BomberMain.shiftCount) << BomberMain.shiftCount;
boolean createFire = false;
/** if there's a bomb here */
if (grid[_x >> BomberMain.shiftCount][_y >> BomberMain.shiftCount] ==
BOMB) {
/** then short the bomb */
if (bombGrid[_x >> BomberMain.shiftCount][_y
>> BomberMain.shiftCount] != null)
bombGrid[_x >> BomberMain.shiftCount][_y
>> BomberMain.shiftCount].shortBomb();
}
/** if there's no fire there already */
else if (!fireGrid[_x >>
BomberMain.shiftCount][_y >> BomberMain.shiftCount]) {
createFire = true;
/** create a fire there */
BomberFire f = new BomberFire(this, _x, _y, type);
}
/** if this is a center */
if (createFire && type == FIRE_CENTER) {
int shiftCount = BomberMain.shiftCount;
int size = BomberMain.size;
/** then create a chain of fire */
int northStop = 0, southStop = 0, westStop = 0, eastStop = 0,
northBlocks = 0, southBlocks = 0, westBlocks = 0, eastBlocks = 0;
/** see how long the fire can be */
for (int i = 1; i <= BomberGame.players[owner].fireLength; i++) {
/** if it can still go south */
if (southStop == 0) { if (((_y >> shiftCount) + i) < 17) {
/** if there isnt't a wall there */
if (grid[_x >> shiftCount][(_y >> shiftCount) + i] != WALL) {
/** if there's something there though */
if (grid[_x >> shiftCount][(_y >> shiftCount) + i]
!= NOTHING)
/** then create a tail fire there */
{ southStop = grid[_x >> shiftCount]
[(_y >> shiftCount) + i]; }
/** increase fire chain */
southBlocks += 1;
} else southStop = -1; }
}
/** if it can still go north */
if (northStop == 0) { if (((_y >> shiftCount) - 1) >= 0) {
/** if there isn't a wall there */
if (grid[_x >> shiftCount][(_y >> shiftCount) - i] != WALL) {
/** if there's something there though */
if (grid[_x >> shiftCount][(_y >> shiftCount) - i]
!= NOTHING)
/** then create a tail fire there */
{ northStop = grid[_x >> shiftCount]
[(_y >> shiftCount) - i]; }
/** increaes fire chain */
northBlocks += 1;
} else northStop = -1; }
}
/** if it can still go east */
if (eastStop == 0) { if (((_x >> shiftCount) + i) < 17) {
/** if there isn't a wall there */
if (grid[(_x >> shiftCount) + i][_y >> shiftCount] != WALL) {
/** if there's somethign there though */
if (grid[(_x >> shiftCount) + i][_y >> shiftCount]
!= NOTHING)
/** then create a tail fire there */
{ eastStop = grid[(_x >> shiftCount) + i]
[_y >> shiftCount]; }
/** increase fire chain */
eastBlocks += 1;
} else eastStop = -1; }
}
/** if it can still go west */
if (westStop == 0) { if (((_x >> shiftCount) - i) >= 0) {
/** if there isn't a wall there */
if (grid[(_x >> shiftCount) - i][_y >> shiftCount] != WALL) {
/** if there's something there through */
if (grid[(_x >> shiftCount) - i]
[_y >> shiftCount] != NOTHING)
/** then create a tail fire there */
{ westStop = grid[(_x >> shiftCount) - i]
[_y >> shiftCount]; }
/** increase fire chain */
westBlocks += 1;
} else westStop = -1; }
}
}
/** create the north chain */
for (int i = 1; i <= northBlocks; i++) {
/** if this is a tail */
if (i == northBlocks) {
/** if there's a brick */
if (northStop == BRICK)
/** then create a burning brick sprite */
createFire(_x, _y - (i * size), owner, FIRE_BRICK);
/** if it's not a brick then create a tail */
else createFire(_x, _y - (i * size), owner, FIRE_NORTH);
}
/** if it's not a tail then create a normal fire */
else createFire(_x, _y - (i * size), owner, FIRE_VERTICAL);
}
for (int i = 1; i <= southBlocks; i++) {
/** if this is a tail */
if (i == southBlocks) {
/** if there's a brick */
if (southStop == BRICK)
/** then create a burning brick sprite */
createFire(_x, _y + (i * size), owner, FIRE_BRICK);
/** if it's not a brick then create a tail */
else createFire(_x, _y + (i * size), owner, FIRE_SOUTH);
}
/** if it's not a tail then create a normal fire */
else createFire(_x, _y + (i * size), owner, FIRE_VERTICAL);
}
for (int i = 1; i <= eastBlocks; i++) {
/** if this is a tail */
if (i == eastBlocks) {
/** if there's a brick */
if (eastStop == BRICK)
/** then create a burning brick sprite */
createFire(_x + (i * size), _y, owner, FIRE_BRICK);
/** if it's not a brick then create a tail */
else createFire(_x + (i * size), _y, owner, FIRE_EAST);
}
/** if it's not a tail then create a normal fire */
else createFire(_x + (i * size), _y, owner, FIRE_HORIZONTAL);
}
for (int i = 1; i <= westBlocks; i++) {
/** if this is a tail */
if (i == westBlocks) {
/** if there's a brick */
if (westStop == BRICK)
/** then create a burning brick sprite */
createFire(_x - (i * size), _y, owner, FIRE_BRICK);
/** if it's not a brick then create a tail */
else createFire(_x - (i * size), _y, owner, FIRE_WEST);
}
/** if it's not a tail then create a normal fire */
else createFire(_x - (i * size), _y, owner, FIRE_HORIZONTAL);
}
}
}
/**
* Drawing method.
* @param graphics graphics handle
*/
public synchronized void paint(Graphics graphics) {
Graphics g = graphics;
/** if java runtime is Java 2 */
if (Main.J2) { paint2D(graphics); }
/** if java runtime isn't Java 2 */
else {
/** if game is over */
if (gameOver) {
/** fill the screen with black color */
g.setColor(Color.black);
g.fillRect(0, 0, 17 << BomberMain.shiftCount,
17 << BomberMain.shiftCount);
}
/** if game isn't over yet */
else {
/** fill window with background color */
g.setColor(backgroundColor);
g.fillRect(0, 0, 17 << BomberMain.shiftCount,
17 << BomberMain.shiftCount);
/** draw the map */
for (int r = 0; r < 17; r++) for (int c = 0; c < 17; c++) {
/** if there's something in the block */
if (grid[r][c] > NOTHING &&
grid[r][c] != BOMB && grid[r][c] != FIRE_BRICK &&
mapImages[level][grid[r][c]] != null) {
g.drawImage(mapImages[level][grid[r][c]],
r << BomberMain.shiftCount, c << BomberMain.shiftCount,
BomberMain.size, BomberMain.size, null);
}
/** if the block is empty */
else {
if (mapImages[level][2] != null) {
/** draw the floor */
g.drawImage(mapImages[level][2],
r << BomberMain.shiftCount, c <<
BomberMain.shiftCount, BomberMain.size,
BomberMain.size, null);
}
}
}
}
}
if (!gameOver) {
/** draw the bonuses */
Bonus bb = null;
int i = 0, k = bonuses.size();
while (i < k) {
bb = (Bonus)bonuses.elementAt(i);
if (bonusGrid[bb.r][bb.c] != null)
bonusGrid[bb.r][bb.c].paint(g);
i += 1;
k = bonuses.size();
}
/** draw the bombs */
Bomb b = null;
i = 0; k = bombs.size();
while (i < k)
{
b = (Bomb)bombs.elementAt(i);
if (bombGrid[b.r][b.c] != null)
bombGrid[b.r][b.c].paint(g);
i += 1;
k = bombs.size();
}
}
}
/**
* Drawing method for Java 2's Graphics2D
* @param graphics graphics handle
*/
public void paint2D(Graphics graphics) {
Graphics2D g2 = (Graphics2D)graphics;
/** set the rendering hints */
g2.setRenderingHints((RenderingHints)hints);
/** if game is over */
if (gameOver) {
/** fill the screen with black color */
g2.setColor(Color.black);
g2.fillRect(0, 0, 17 << BomberMain.shiftCount,
17 << BomberMain.shiftCount);
}
/** if game isn't over yet */
else {
/** fill window with background color */
g2.setColor(backgroundColor);
g2.fillRect(0, 0, 17 << BomberMain.shiftCount,
17 << BomberMain.shiftCount);
/** draw the map */
for (int r = 0; r < 17; r++) for (int c = 0; c < 17; c++) {
/** if there's something in the block */
if (grid[r][c] > NOTHING &&
grid[r][c] != BOMB && grid[r][c] != FIRE_BRICK &&
mapImages[level][grid[r][c]] != null) {
g2.drawImage(mapImages[level][grid[r][c]],
r << BomberMain.shiftCount, c << BomberMain.shiftCount,
BomberMain.size, BomberMain.size, null);
}
/** if the block is empty */
else {
if (mapImages[level][2] != null) {
/** draw the floor */
g2.drawImage(mapImages[level][2],
r << BomberMain.shiftCount, c <<
BomberMain.shiftCount, BomberMain.size,
BomberMain.size, null);
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -