📄 explode.java
字号:
package gameoflife;
import static java.lang.System.out;
import java.awt.Color;
import java.util.Random;
import java.util.Stack;
/**************************************
* Acts as a factory.
**************************************/
public abstract class Explode
{
protected Point[][] pics;
int x_center, y_center;
public static int EXPLODING = 1;
public static int OVER = 2;
int state;
int life;
public Explode(int xc, int yc) {
x_center = xc;
y_center = yc;
life = 0;
state = EXPLODING;
}
public Point[] getIthPic(int i) {
return pics[i];
}
public static Explode createGunBullet(int x_center, int y_center)
{
return new GunExplode(x_center, y_center);
}
public static Explode createQuickBullet(int x_center, int y_center)
{
return new QuickExplode(x_center, y_center);
}
public static Explode createSlowerBullet(int x_center, int y_center)
{
return new SlowExplode(x_center, y_center);
}
public static Explode createAroundBullet(int x_center, int y_center)
{
return new AroundExplode(x_center, y_center);
}
abstract public void passOneTimeSlice();
public String toString() {
return "Explode : (" + (int)this.x_center + ", " + (int)this.y_center + ")";
}
}
/**
*
*/
class GunExplode extends Explode {
public GunExplode(int x, int y) {
super(x, y);
/** x,y of point is offset to the center of the explode **/
pics = new Point[][] {
{
new Point(1,1)
/** ......
* ......
..o...
...x..
......
...... */
},
{
new Point(0,0), new Point(1,0),
new Point(0,1), new Point(1,1),
/** ......
* ......
..ox..
..xx..
......
...... */
},
{
new Point(-1,-1), new Point(2,-1),
new Point(0,0), new Point(1,0),
new Point(0,1), new Point(1,1),
new Point(-1,2), new Point(2,2),
/** ......
* .x..x.
..ox..
..xx..
.x..x.
...... */
},
{
new Point(-2,-2), new Point(3,-2),
new Point(-1,-1), new Point(2,-1),
new Point(-1, 2), new Point(2, 2),
new Point(-2, 3), new Point(3, 3)
/** x....x
* .x..x.
..o...
......
.x..x.
x....x */
},
{
new Point(-2,-2), new Point(3,-2),
new Point(-2, 3), new Point(3, 3)
/** x....x
* ......
..o...
......
......
x....x */
}
};
for(Point[] pic : pics) {
for(Point p : pic)
p.color = Color.YELLOW;
}
}
public void passOneTimeSlice() {
if(life >= pics.length) {
state = OVER;
}
}
}
/**
*
*/
class QuickExplode extends Explode
{
public QuickExplode(int x, int y) {
super(x, y);
/** x,y of point is offset to the center of the explode **/
pics = new Point[][] {
{
new Point(1,1)
/** ......
* ......
..o...
...x..
......
...... */
},
{
new Point(0,0), new Point(1,0),
new Point(0,1), new Point(1,1),
/** ......
* ......
..ox..
..xx..
......
...... */
},
{
new Point(-1,-1), new Point(2,-1),
new Point(0,0), new Point(1,0),
new Point(0,1), new Point(1,1),
new Point(-1,2), new Point(2,2),
/** ......
* .x..x.
..ox..
..xx..
.x..x.
...... */
},
{
new Point(-2,-2), new Point(3,-2),
new Point(-1,-1), new Point(2,-1),
new Point(-1, 2), new Point(2, 2),
new Point(-2, 3), new Point(3, 3)
/** x....x
* .x..x.
..o...
......
.x..x.
x....x */
},
{
new Point(-2,-2), new Point(3,-2),
new Point(-2, 3), new Point(3, 3)
/** x....x
* ......
..o...
......
......
x....x */
}
};
for(Point[] pic : pics) {
for(Point p : pic)
p.color = Color.YELLOW;
}
}
public void passOneTimeSlice() {
if(life >= pics.length) {
state = OVER;
}
}
}
class SlowExplode extends Explode
{
public SlowExplode(int x, int y)
{
super(x, y);
/** x,y of point is offset to the center of the explode **/
pics = new Point[][] {
{
new Point(1,1)
/** ......
* ......
..o...
...x..
......
...... */
},
{
new Point(0,0), new Point(1,0),
new Point(0,1), new Point(1,1),
/** ......
* ......
..ox..
..xx..
......
...... */
},
{
new Point(-1,-1), new Point(2,-1),
new Point(0,0), new Point(1,0),
new Point(0,1), new Point(1,1),
new Point(-1,2), new Point(2,2),
/** ......
* .x..x.
..ox..
..xx..
.x..x.
...... */
},
{
new Point(-2,-2), new Point(3,-2),
new Point(-1,-1), new Point(2,-1),
new Point(-1, 2), new Point(2, 2),
new Point(-2, 3), new Point(3, 3)
/** x....x
* .x..x.
..o...
......
.x..x.
x....x */
},
{
new Point(-2,-2), new Point(3,-2),
new Point(-2, 3), new Point(3, 3)
/** x....x
* ......
..o...
......
......
x....x */
}
};
for(Point[] pic : pics) {
for(Point p : pic)
p.color = Color.YELLOW;
}
}
public void passOneTimeSlice() {
if(life >= pics.length) {
state = OVER;
}
}
}
class AroundExplode extends Explode
{
public AroundExplode(int x, int y)
{
super(x, y);
/** x,y of point is offset to the center of the explode **/
pics = new Point[][] {
{
new Point(1,1)
/** ......
* ......
..o...
...x..
......
...... */
},
{
new Point(0,0), new Point(1,0),
new Point(0,1), new Point(1,1),
/** ......
* ......
..ox..
..xx..
......
...... */
},
{
new Point(-1,-1), new Point(2,-1),
new Point(0,0), new Point(1,0),
new Point(0,1), new Point(1,1),
new Point(-1,2), new Point(2,2),
/** ......
* .x..x.
..ox..
..xx..
.x..x.
...... */
},
{
new Point(-2,-2), new Point(3,-2),
new Point(-1,-1), new Point(2,-1),
new Point(-1, 2), new Point(2, 2),
new Point(-2, 3), new Point(3, 3)
/** x....x
* .x..x.
..o...
......
.x..x.
x....x */
},
{
new Point(-2,-2), new Point(3,-2),
new Point(-2, 3), new Point(3, 3)
/** x....x
* ......
..o...
......
......
x....x */
}
};
for(Point[] pic : pics) {
for(Point p : pic)
p.color = Color.YELLOW;
}
}
public void passOneTimeSlice() {
if(life >= pics.length) {
state = OVER;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -