首页>代码>java swing开发的俄罗斯方块游戏,包含完整代码+详细注释>/ItcastTetris1.02_final/src/cn/itcast/tetris/entities/UnitType.java
package cn.itcast.tetris.entities; import java.awt.Color; /** * 可以表示地面里面的障碍物, 不可消除的障碍物, 空白<BR> * <BR> * 外部不可以直接new 一个实例, 而应该用 clone() 方法产生实例(防止产生不能识别的类型)<BR> * 例如产生一个障碍物:<BR> * <code><BR> UnitType aObstacle = UnitType.OBSTACLE.clone();<BR> * </code><BR> * */ public class UnitType implements Cloneable { /* 定义一些要用到的常量 */ /** * 空白类型的值 */ private static final int BLANK_VALUE = 0; /** * 边框类型的值 */ private static final int STUBBORN_OBSTACLE_VALUE = 1; /** * 障碍物类型的值 */ private static final int OBSTACLE_VALUE = 2; /** * 空白类型 */ public static final UnitType BLANK = new UnitType(BLANK_VALUE, Color.WHITE); /** * 边框类类型 */ public static final UnitType STUBBORN_OBSTACLE = new UnitType( STUBBORN_OBSTACLE_VALUE, new Color(0x808000)); /** * 障碍物类型 */ public static final UnitType OBSTACLE = new UnitType(OBSTACLE_VALUE, Color.DARK_GRAY); /** * 类型值 */ private int value; /** * 颜色 */ private Color color; /** * 得到类型值 * * @return */ public int getValue() { return value; } /** * 设置类型值 * * @param value */ public void setValue(int value) { this.value = value; } /** * 得到颜色 * * @return */ public Color getColor() { return color; } /** * 设置颜色 * * @param color */ public void setColor(Color color) { this.color = color; } /** * 接受类型的私有的构造方法<BR> * * @param value */ private UnitType(int value) { super(); this.value = value; } /** * 接受类型和颜色的私有的构造方法 * * @param value * @param color */ private UnitType(int value, Color color) { super(); this.value = value; this.color = color; } /** * 返回一个新的,和自己有一样的颜色并且类型相同的UnitType */ @Override public UnitType clone() { // TODO Auto-generated method stub return new UnitType(this.value, this.color); } /** * 把自己克隆成和指定的UnitType 相同的 UnitType, value 和 Color 都会被克隆 * * @param ut */ public void cloneProperties(UnitType ut) { this.color = ut.color; this.value = ut.value; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + value; return result; } /** * 相同的类型就是相等, 不比较颜色 */ @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final UnitType other = (UnitType) obj; if (value != other.value) return false; return true; } }

chy520 LV1
2024年6月2日
ClydeSon LV5
2023年12月18日
微信网友_6770780673069056 LV2
2023年12月9日
npc也有忧伤 LV3
2022年3月19日
guzhiguo0313 LV5
2022年2月12日
闫小玥 LV8
2021年12月22日
秒速一千米 LV2
2021年9月4日
jnagri LV6
2021年7月6日
zhangjian800 LV1
2021年5月25日
ybc629 LV3
2020年12月23日

dushine LV3
4月10日
luoyanglin LV2
2024年9月14日
2824163870szy
2024年7月1日
暂无贡献等级
zr20050503 LV2
2024年6月27日
hainabian1977 LV2
2024年6月24日
bill1234 LV1
2024年6月23日
chy520 LV1
2024年5月29日
douxing
2024年3月5日
暂无贡献等级
crapcrap LV2
2024年2月1日
zhaoyunlong36987
2024年1月23日
暂无贡献等级