俄罗斯方块
一、 背景描述
在完成 Swing 和线程课程后,考虑开始本项目的实施。
二、 实现要求
制作一个简单的俄罗斯方块,拥有 7 种方块的变换。游戏可以随时暂停、停止。游戏
还有成绩记录方式。
三、 实现技术
a) 使用 Graphics、Graphics2D 完成方块的绘制。
b) 使用多线程的方式控制游戏的执行。
c) 方块的碰撞的逻辑问题。
四、 类图
a) 类图
I nf oPane
scor e : i nt
l evel : i nt
l i nes : i nt
bi gBl ock : Bl ock
smal l Bl ock : Bl ock
setScore(score : i nt ) : voi d
setLevel ( l evel : i nt) : voi d
setLi nes(l i nes : i nt ) : voi d
previ ewBl ock( creator : Bl ockCreat or) : voi d
pai nt(g : Graphi cs2D) : voi d
Tetri sFrame
Bl ock
type : i nt
al l shape : i nt[][][4][4]
di r : i nt
col or : Col or
gri dx : i nt
gri dy : i nt
changeDi r(di r : i nt ) : voi d
col l i deWi t hSi de( gri ds : Col or[][]) : bool ean
col l i deWi t hBot tom( gri ds : Col or[][] ) : bool ean
pai nt(g : Graphi cs2D) : voi d
GamePane
gri dw : i nt
gri dh : i nt
gri ds : Col or[][]
pai nt ( g : Graphi cs2D) : voi d
Bl ockCreat or
bl ock : Queue
get Next Bl ock( )
b) 类图说明
类名称
TetrisMain
类描述 俄罗斯方块主程序类。
包描述
main
函数描述
public static void main(String[] args)
俄罗斯方块主程序类。
类名称
BlockPane
类描述 显示下两个块类。
包描述
frm
函数描述
public BlockPane()
显示下 2 个方块的缺省构造函数。
public void paint(Graphics g)
完成下 2 个方块的绘制。
类名称
GamePane
类描述
游戏面板类。
练习使用 Swing 组件、ActionListener、内部类的使用。
包描述
frm
函数描述
public GamePane()
缺省构造一个宽 10,高 20,每个格子高度