资源描述:
《java小游戏连连看源代码》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、Java小游戏——连连看源码连连看java源代码importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;publicclasslianliankanimplementsActionListener{JFramemainFrame;//主面板ContainerthisContainer;JPanelcenterPanel,southPanel,northPanel;//子面板JButtondiamondsButton[][]=newJButton[6][5];//游戏按钮数组JButtonexitButton,resetB
2、utton,newlyButton;//退出,重列,重新开始按钮JLabelfractionLable=newJLabel("0");//分数标签JButtonfirstButton,secondButton;//分别记录两次被选中的按钮intgrid[][]=newint[8][7];//储存游戏按钮位置staticbooleanpressInformation=false;//判断是否有按钮被选中intx0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV;//游戏按钮的位置坐标inti,j,k,n;//消除方法控制publicvo
3、idinit(){mainFrame=newJFrame("JKJ连连看");thisContainer=mainFrame.getContentPane();thisContainer.setLayout(newBorderLayout());centerPanel=newJPanel();southPanel=newJPanel();northPanel=newJPanel();thisContainer.add(centerPanel,"Center");thisContainer.add(southPanel,"South");thisContainer.add(northP
4、anel,"North");centerPanel.setLayout(newGridLayout(6,5));for(intcols=0;cols<6;cols++){for(introws=0;rows<5;rows++){diamondsButton[cols][rows]=newJButton(String.valueOf(grid[cols+1][rows+1]));diamondsButton[cols][rows].addActionListener(this);centerPanel.add(diamondsButton[cols][rows]);}}exitButt
5、on=newJButton("退出");exitButton.addActionListener(this);resetButton=newJButton("重列");resetButton.addActionListener(this);newlyButton=newJButton("再来一局");newlyButton.addActionListener(this);southPanel.add(exitButton);southPanel.add(resetButton);southPanel.add(newlyButton);fractionLable.setText(Str
6、ing.valueOf(Integer.parseInt(fractionLable.getText())));northPanel.add(fractionLable);mainFrame.setBounds(280,100,500,450);mainFrame.setVisible(true);}publicvoidrandomBuild(){intrandoms,cols,rows;for(inttwins=1;twins<=15;twins++){randoms=(int)(Math.random()*25+1);for(intalike=1;alike<=2;alike++
7、){cols=(int)(Math.random()*6+1);rows=(int)(Math.random()*5+1);while(grid[cols][rows]!=0){cols=(int)(Math.random()*6+1);rows=(int)(Math.random()*5+1);}this.grid[cols][rows]=randoms;}}}publicvoidfraction(){fractionLable.setText(Stri