资源预览内容
第1页 / 共10页
第2页 / 共10页
第3页 / 共10页
第4页 / 共10页
第5页 / 共10页
第6页 / 共10页
第7页 / 共10页
第8页 / 共10页
第9页 / 共10页
第10页 / 共10页
亲,该文档总共10页全部预览完了,如果喜欢就下载吧!
资源描述
/连连看java源代码mport javax.swing.*; import java.awt.*; import java.awt.event.*; public class lianliankan implements ActionListener JFrame mainFrame; /主面板 Container thisContainer; JPanel centerPanel,southPanel,northPanel; /子面板 JButton diamondsButton = new JButton65;/游戏按钮数组 JButton exitButton,resetButton,newlyButton; /退出,重列,重新开始按钮 JLabel fractionLable=new JLabel(0); /分数标签 JButton firstButton,secondButton; /分别记录两次被选中的按钮 int grid = new int87;/储存游戏按钮位置 static boolean pressInformation=false; /判断是否有按钮被选中 int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; /游戏按钮的位置坐标 int i,j,k,n;/消除方法控制 public void init() /开始方法mainFrame=new JFrame(JKJ连连看); /字符thisContainer = mainFrame.getContentPane(); thisContainer.setLayout(new BorderLayout(); centerPanel=new JPanel(); southPanel=new JPanel(); northPanel=new JPanel(); thisContainer.add(centerPanel,Center); thisContainer.add(southPanel,South); thisContainer.add(northPanel,North); centerPanel.setLayout(new GridLayout(6,5); for(int cols = 0;cols 6;cols+) for(int rows = 0;rows 5;rows+ ) diamondsButtoncolsrows=new JButton(String.valueOf(gridcols+1rows+1); diamondsButtoncolsrows.addActionListener(this); centerPanel.add(diamondsButtoncolsrows); exitButton=new JButton(退出); /退出按钮exitButton.addActionListener(this); resetButton=new JButton(重列); /重列按钮resetButton.addActionListener(this); newlyButton=new JButton(再来一局); /再来一局按钮newlyButton.addActionListener(this); southPanel.add(exitButton); southPanel.add(resetButton); southPanel.add(newlyButton); fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText(); northPanel.add(fractionLable); mainFrame.setBounds(280,100,500,450); mainFrame.setVisible(true); public void randomBuild() /产生随机数 int randoms,cols,rows; for(int twins=1;twins=15;twins+) randoms=(int)(Math.random()*25+1); for(int alike=1;alike=2;alike+) cols=(int)(Math.random()*6+1); rows=(int)(Math.random()*5+1); while(gridcolsrows!=0) cols=(int)(Math.random()*6+1); rows=(int)(Math.random()*5+1); this.gridcolsrows=randoms; public void fraction()/计数 fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText()+100); public void reload() int save = new int30; int n=0,cols,rows; int grid= new int87; for(int i=0;i=6;i+) for(int j=0;j=0) cols=(int)(Math.random()*6+1); rows=(int)(Math.random()*5+1); while(gridcolsrows!=0) cols=(int)(Math.random()*6+1); rows=(int)(Math.random()*5+1); this.gridcolsrows=saven; n-; mainFrame.setVisible(false); pressInformation=false; /这里一定要将按钮点击信息归为初始 init(); for(int i = 0;i 6;i+) for(int j = 0;j 5;j+ ) if(gridi+1j+1=0) diamondsButtonij.setVisible(false); public void estimateEven(int placeX,int placeY,JButton bz) /判断所单击的两次是否相同 if(pressInformation=false) x=placeX; y=placeY; secondMsg=gridxy; secondButton=bz; pressInformation=true; else x0=x; y0=y; fristMsg=secondMsg; firstButton=secondButton; x=placeX; y=placeY; secondMsg=gridxy; secondButton=bz; if(fristMsg=secondMsg & secondButton!=firstButton) xiao(); public void xiao() /相同的情况下能不能消去。if(x0=x &(y0=y+1|y0=y-1) | (x0=x+1|x0=x-1)&(y0=y) /判断是否相邻 remov
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号