package lianliankan;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import java.net.URLClassLoader;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
public class MainFrame extends JFrame
implements ActionListener{
public final static int row=17;
public final static int clomu=10;
public int iconbuttonx;
public int iconbuttony;
public int tupianzhi;
public int upiconbuttonx;
public int upiconbuttony;
public int uptupianzhi;
public int iconbut=0;
public static int kongzhi=0;
public int n1=-1;
public int n2=-1;
public static boolean isEmp=false;
public static int score=0;
public static int refreshiconnum=0;
public static Map map = new Map();
public static Tishi tishi = new Tishi();
public Sound sound = new Sound();
SetUpDialog setupdialog = new SetUpDialog(this,"设置");
JButton start;
JButton setup;
JButton about;
JButton help;
JButton refresh;
JButton hint;
JButton bomb;
JButton demo;
static JButton top10 = new JButton("GO TO TOP10");
ImageIcon iconstart = new ImageIcon(getImage("images/start.gif"));
ImageIcon iconsetup = new ImageIcon(getImage("images/setup.gif"));
ImageIcon iconabout = new ImageIcon(getImage("images/about.gif"));
ImageIcon iconhelp = new ImageIcon(getImage("images/help.gif"));
ImageIcon iconrefresh = new ImageIcon(getImage("images/refresh.gif"));
ImageIcon iconhint = new ImageIcon(getImage("images/hint.gif"));
ImageIcon iconbomb = new ImageIcon(getImage("images/bomb.gif"));
ImageIcon icondemo = new ImageIcon(getImage("images/demo.gif"));
ImageIcon[] icon = new ImageIcon[40];
static JButton[] iconbutton = new JButton[row*clomu];
static JLabel xianshi = new JLabel("欢迎你玩此游戏!!");
static JLabel scorelb = new JLabel("分数:"+score);
static JLabel timelb = new JLabel("时间:0");
public static int[][] black = new int [row][clomu];
public MainFrame(){
super("连连看 v1.0.0");
Pane panel = new Pane();
setContentPane(panel);
setSize(770,510);
panel.setLayout(null);
setResizable(false);
Image iconmain = getImage("images/kyodai16.gif");
setIconImage(iconmain);
URLClassLoader urlLoader = (URLClassLoader)this.getClass().getClassLoader();
URL url = urlLoader.findResource("images/cursor.gif");
Image animateImage = new ImageIcon(url).getImage();
Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(
animateImage, new Point(0, 0), "cursor");
this.setCursor(cursor);
start = new JButton(iconstart);
start.setBounds(new Rectangle(602,110,156,48));
start.setBorder(BorderFactory.createLineBorder(Pane.LightColor,1));
refresh = new JButton(iconrefresh);
refresh.setBounds(new Rectangle(602,158,156,48));
refresh.setBorder(BorderFactory.createLineBorder(Pane.LightColor,1));
hint = new JButton(iconhint);
hint.setBounds(new Rectangle(602,206,156,48));
hint.setBorder(BorderFactory.createLineBorder(Pane.LightColor,1));
bomb = new JButton(iconbomb);
bomb.setBounds(new Rectangle(602,254,156,48));
bomb.setBorder(BorderFactory.createLineBorder(Pane.LightColor,1));
demo = new JButton(icondemo);
demo.setBounds(new Rectangle(602,302,156,48));
demo.setBorder(BorderFactory.createLineBorder(Pane.LightColor,1));
top10.setBounds(new Rectangle(620,447,120,25));
top10.setEnabled(false);
setup = new JButton(iconsetup);
setup.setBounds(new Rectangle(10,10,87,30));
help = new JButton(iconhelp);
help.setBounds(new Rectangle(120,10,87,30));
about = new JButton(iconabout);
about.setBounds(new Rectangle(230,10,87,30));
xianshi.setBounds(new Rectangle(0,447,600,25));
xianshi.setForeground(Color.RED);
scorelb.setBounds(new Rectangle(600,56,170,40));
scorelb.setForeground(Color.YELLOW);
Font font48 = new Font("serif", Font.PLAIN, 28);
scorelb.setFont(font48);
timelb.setBounds(new Rectangle(600,384,170,40));
timelb.setFont(font48);
timelb.setForeground(Color.cyan);
panel.add(timelb);
panel.add(bomb);
panel.add(hint);
panel.add(refresh);
panel.add(xianshi);
panel.add(scorelb);
panel.add(start);
panel.add(setup);
panel.add(help);
panel.add(about);
panel.add(top10);
panel.add(demo);
for(int i=0;i<39;i++)
icon[i] = new ImageIcon(getImage("images/"+(i+1)+".gif"));
for(int i=0;i<row*clomu;i++){
iconbutton[i] = new JButton();
iconbutton[i].setBorder(BorderFactory.createRaisedBevelBorder());
}
int n=0;
for(int j=0;j<clomu;j++){
for(int i=0;i<row;i++){
iconbutton[n].setBounds(new Rectangle(5+(35*i),57+(38*j),31,34));
panel.add(iconbutton[n]);
iconbutton[n].addActionListener(this);
iconbutton[n].setVisible(false);
iconbutton[n].setOpaque(false);
n++;
}
}
start.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
refreshiconnum=map.iconnum;
System.out.println(refreshiconnum);
isEmp=true;
yanshi(1000);
top10.setEnabled(false);
xianshi.setText("图片个数:"+map.iconnum+"你应该在"+map.iconnum*4+"秒内完成!!");
for(int i=0;i<row*clomu;i++){
iconbutton[i].setVisible(false);
iconbutton[i].setBorder(BorderFactory.createRaisedBevelBorder());
}
map.chushihua();
map.buttonblack(map.iconnum);
map.iconblack(map.iconnum);
for(int i=0;i<map.iconnum;i++){
iconbutton[map.buttonblack[i]].setVisible(true);
iconbutton[map.buttonblack[i]].setIcon(icon[map.iconblack[i]]);
}
chushihuablack();
score=0;
scorelb.setText("分数:"+score);
Time time = new Time();
time.start(time);
isEmp=false;
}
}
);
refresh.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
if(refreshiconnum==0){
JOptionPane.showMessageDialog(null,"你还没开始游戏呢!");
}else{
sound.refresh();
kongzhi=0;
// map.iconnum=refreshiconnum;
for(int i=0;i<row*clomu;i++){
iconbutton[i].setVisible(false);
iconbutton[i].setBorder(BorderFactory.createRaisedBeve