用eclipse编的游戏___连连看,是参加大学生编程竞赛的作品.
源代码在线查看: control.java
package control;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import model.Model;
import view.GamePanel;
public class Control extends MouseAdapter implements ActionListener , WindowListener{
private Model model;
public Control(Model model){
this.model=model;
}
public void actionPerformed(ActionEvent e) {
String cmd=e.getActionCommand().toLowerCase();
if(cmd.equals("refresh"))
model.refresh();
else if(cmd.equals("start"))
model.restartGame();
else if(cmd.equals("set")){
}
else if(cmd.equals("remind"))
model.showTip();
else if(cmd.equals("demo")){
JButton btn=(JButton) e.getSource();
if(btn.getText().equals("演示")){
model.startDemo();
btn.setText("停止");
}
else{
model.stopDemo();
btn.setText("演示");
model.restartGame();
}
}
else if(cmd.equals("about"))
model.about();
else if(e.getSource() instanceof JComboBox){
JComboBox cbo=(JComboBox) e.getSource();
String sltString=cbo.getSelectedItem().toString();
if(sltString.equals("随机"))
model.setLevel(0);
else
model.setLevel(Integer.parseInt(sltString));
}
}
@Override
public void mousePressed(MouseEvent e) {
Object src=e.getSource();
if(src instanceof GamePanel){
GamePanel gp=(GamePanel) src;
if(e.getButton()==MouseEvent.BUTTON3)
model.cancelSelect();
else
model.clickMatrix(gp.PointToMetrix(e.getPoint()));
}
}
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowClosing(WindowEvent e) {
//LoadAndSave.saveLevel(model.getLevel());
model.setFrameLocation(e.getWindow().getLocation());
model.saveSet();
}
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
}