文档说明
程序的主体类是Game类,它调用Table类建立游戏桌面,然后创建One,Two,Three,Four,Five,Six,Seven七个方块类。Shape类是各个方块的根类。About类显示作者及相关信息。
操作按键:方向键左、右、下代表方块相应移动方向,方向按键“上”,代表方块的形状转换,空格键暂停。
速度可选为9档,隐藏第十档。初始速度为500,当消去50行后,速度加快一档。当消去450行时,速度升至十档。当消去第500行时,游戏通关。
速度加快一次,主界面内的方块颜色变化一次。
积分:消去一行,加10分,消去2行,加30,消去3行,加60,消去四行,加100分
程序源码
主体类:Game
package russia;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.Timer;
public class Game extends JApplet {//游戏主程序
JPanel panel;
Table gameTable;//桌面类
Shape shape;//方块类
JButton startButton,restartButton;
Label scoreLabel;
Label bestScore;
Label about;
Choice speedChoice;
int speed=500;初始速度
int which;//标志哪一个要下落的方块
int nextWhich;//标志下一个要下落的方块
int score=0;//记录总分数
int row=0;//记录总行数
int mainColor=1;//方块主体颜色
boolean passAll=false;//标志是否通关
boolean isLast=false;//标志是否是最后一级
boolean canMove=false;//标志是否响应键盘
Timer timer;//记时器,用于控制下落时间间隔
StartListener startListener;//开始按钮事件监听器
RestartListener restartListener;//重新开始按钮事件监听器
SpeedChoiceListener speedChoiceListener;//速度监听器
public Game() {
panel=(JPanel)getContentPane();
}
public void init() {初始化各个变量
panel.setLayout(null);//不用布局管理器,以便自己定义位置
about=new Label("关于作者");
scoreLabel=new Label("0");
bestScore=new Label();
startButton=new JButton("开始");
restartButton=new JButton("重玩");