shapefactory.java
来自「这是一个贪食蛇的游戏源代码 代码的设计模式室调停者」· Java 代码 · 共 113 行
JAVA
113 行
package com.zhanggang.teris.entities;
import java.util.Random;
import com.zhang.teris.listener.ShapeListener;
public class ShapeFactory {
private static Random m = new Random();
private static int[][][] shapes = new int[][][] {
{//条子
{
1,1,1,1,
0,0,0,0,
0,0,0,0,
0,0,0,0,},
{
1,0,0,0,
1,0,0,0,
1,0,0,0,
1,0,0,0}
},
{//方块
{
1,1,0,0,
1,1,0,0,
0,0,0,0,
0,0,0,0}
},
{//土
{
0,1,0,0,
1,1,1,0,
0,0,0,0,
0,0,0,0},
{
0,1,0,0,
0,1,1,0,
0,1,0,0,
0,0,0,0,},
{
0,0,0,0,
1,1,1,0,
0,1,0,0,
0,0,0,0},
{
0,1,0,0,
1,1,0,0,
0,1,0,0,
0,0,0,0}
},
{
{
1,1,0,0,
1,0,0,0,
1,0,0,0,
0,0,0,0},
{
1,1,1,0,
0,0,1,0,
0,0,0,0,
0,0,0,0},
{
0,1,0,0,
0,1,0,0,
1,1,0,0,
0,0,0,0},
{
1,0,0,0,
1,1,1,0,
0,0,0,0,
0,0,0,0},
},
{
{
1,1,0,0,
0,1,1,0,
0,0,0,0,
0,0,0,0},
{
0,1,0,0,
1,1,0,0,
1,0,0,0,
0,0,0,0}
},
{
{
0,1,1,0,
1,1,0,0,
0,0,0,0,
0,0,0,0},
{
1,0,0,0,
1,1,0,0,
0,1,0,0,
0,0,0,0}
}
};
public static Shape getShape(ShapeListener shapeListener) {
System.out.println("ShapeFactory's getShape");
Shape shape = new Shape();
int type = m.nextInt(shapes.length);
shape.setBody(shapes[type]);
shape.setStatus(m.nextInt(shapes[type].length));
shape.addShapeListener(shapeListener);
shape.runShapeDirver();
return shape;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?