首页>代码>java swing开发的俄罗斯方块游戏>/MyTetris/src/entities/BlockFactory.java
package entities;

import java.awt.Color;
import java.util.Random;

import util.Global;

public class BlockFactory
{
	protected int blockpattern1[][][] =
		{
			{
				{1,1,0,0},
				{1,1,0,0},
				{0,0,0,0},
				{0,0,0,0}},
			{
				{1,1,0,0},
				{1,1,0,0},
				{0,0,0,0},
				{0,0,0,0}},
			{
				{1,1,0,0},
				{1,1,0,0},
				{0,0,0,0},
				{0,0,0,0}},
			{
				{1,1,0,0},
				{1,1,0,0},
				{0,0,0,0},
				{0,0,0,0}}};

	protected int blockpattern2[][][] =
		{
			{
				{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},
				{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}}};

	protected int blockpattern3[][][] =
		{
			{
				{1,0,0,0},
				{1,0,0,0},
				{1,1,0,0},
				{0,0,0,0}},
			{
				{1,1,1,0},
				{1,0,0,0},
				{0,0,0,0},
				{0,0,0,0}},
			{
				{1,1,0,0},
				{0,1,0,0},
				{0,1,0,0},
				{0,0,0,0}},
			{
				{0,0,1,0},
				{1,1,1,0},
				{0,0,0,0},
				{0,0,0,0}}};

	protected int blockpattern4[][][] =
		{
			{
				{1,0,0,0},
				{1,0,0,0},
				{1,0,0,0},
				{1,0,0,0}},
			{
				{1,1,1,1},
				{0,0,0,0},
				{0,0,0,0},
				{0,0,0,0}},
			{
				{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}}};

	protected int blockpattern5[][][] =
		{
			{
				{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}},
			{
				{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}}};

	protected int blockpattern6[][][] =
		{
			{
				{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}},
			{
				{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}}};

	protected int blockpattern7[][][] =
		{
			{
				{1,1,1,0},
				{0,1,0,0},
				{0,0,0,0},
				{0,0,0,0}},
			{
				{0,1,0,0},
				{1,1,0,0},
				{0,1,0,0},
				{0,0,0,0}},
			{
				{0,1,0,0},
				{1,1,1,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}}};

	protected Random random = new Random();

	/** 产生一个方块 */
	public Block getBlock()
	{
		int[][][] blockpattern = null;
		int randomPattern = random.nextInt(7) + 1;
		int randomRotate = random.nextInt(4);
		switch (randomPattern)
		{
			case 1:
				blockpattern = blockpattern1;
			break;
			case 2:
				blockpattern = blockpattern2;
			break;
			case 3:
				blockpattern = blockpattern3;
			break;
			case 4:
				blockpattern = blockpattern4;
			break;
			case 5:
				blockpattern = blockpattern5;
			break;
			case 6:
				blockpattern = blockpattern6;
			break;
			case 7:
				blockpattern = blockpattern7;
			break;
		}
		Color color = Global.getRandomColor();
		Block block = new Block(blockpattern, randomRotate, color);
		return block;

	}

}
最近下载更多
lhm789  LV6 2024年9月23日
luoyanglin  LV2 2024年9月14日
微信网友_7062902643691520  LV1 2024年7月2日
caojiaxuan  LV1 2024年6月20日
鬼屋报道  LV3 2024年6月4日
yx666666  LV1 2024年1月5日
ClydeSon  LV5 2023年12月27日
1351408674  LV1 2023年12月27日
1112WHQ  LV7 2023年11月3日
ggl163163eel  LV2 2023年10月18日
最近浏览更多
lhm789  LV6 2024年9月23日
luoyanglin  LV2 2024年9月14日
54ty1212 2024年8月6日
暂无贡献等级
微信网友_7062902643691520  LV1 2024年7月2日
feelinfer  LV1 2024年6月27日
qqqww11  LV2 2024年6月26日
azzzz1  LV2 2024年6月26日
hainabian1977  LV2 2024年6月24日
caojiaxuan  LV1 2024年6月20日
鬼屋报道  LV3 2024年6月1日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友