📄 lifeform.java
字号:
package gameoflife;
class Point
{
public int x, y;
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
}
/**************************************
* Acts as a LifeForm factory. Can create three different life forms.
**************************************/
public abstract class LifeForm
{
protected Point offset;
protected Point[] points;
public LifeForm(int x, int y)
{
offset = new Point(x,y);
}
public Point[] getPoints()
{
return points;
}
public Point getOffset()
{
return offset;
}
public static LifeForm createPulsar(int xOffset, int yOffset)
{
return new Pulsar(xOffset, yOffset);
}
public static LifeForm createGlider(int xOffset, int yOffset)
{
return new Glider(xOffset, yOffset);
}
public static LifeForm createLightweightSpaceship(int xOffset, int yOffset)
{
return new LightweightSpaceship(xOffset, yOffset);
}
}
class Glider extends LifeForm
{
public Glider(int x, int y)
{
super(x,y);
points = new Point[] { new Point(1,0), new Point(1,1), new Point(2,1),
new Point(0,2), new Point(2,2)
};
/** .xx
* .xx
..x */
}
}
class LightweightSpaceship extends LifeForm
{
public LightweightSpaceship(int x, int y)
{
super(x,y);
points = new Point[] { new Point(1,0), new Point(4,0),
new Point(0,1),
new Point(0,2), new Point(4,2), new Point(0,3), new Point(1,3),
new Point(2,3),new Point(3,3)
};
/** .x.xx
* x.xx.
* ...xx
...x. */
}
}
class Pulsar extends LifeForm
{
public Pulsar(int x, int y)
{
super(x,y);
points = new Point[] { new Point(1,0),
new Point(0,1),new Point(1,1), new Point(2,1),
new Point(0,2), new Point(2,2),
new Point(0,3),new Point(1,3), new Point(2,3),
new Point(1,4) };
}
/** .xxx
* xxxx
* ..xx
* ....
.x.. */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -