资源描述:
《java小游戏连连看源代码.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、JAVA小游戏报告院别电子信息工程专业计算机科学与技术班级01班学号121040210116姓名姚银杰西安思源学院教务处制二零一四年连连看java源代码importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;publicclasslianliankanimplementsActionListener{JFramemainFrame;//主面板ContainerthisContainer;JPanelcenterPanel,southPanel,northPanel;//子面板JButtondiamonds
2、Button[][]=newJButton[6][5];//游戏按钮数组JButtonexitButton,resetButton,newlyButton;//退出,重列,重新开始按钮JLabelfractionLable=newJLabel("0");//分数标签JButtonfirstButton,secondButton;//分别记录两次被选中的按钮intgrid[][]=newint[8][7];//储存游戏按钮位置staticbooleanpressInformation=false;//判断是否有按钮被选中intx0=0,y0=0,x=0,y=0,fris
3、tMsg=0,secondMsg=0,validateLV;//游戏按钮的位置坐标inti,j,k,n;//消除方法控制publicvoidinit(){mainFrame=newJFrame("JKJ连连看");thisContainer=mainFrame.getContentPane();thisContainer.setLayout(newBorderLayout());centerPanel=newJPanel();southPanel=newJPanel();northPanel=newJPanel();thisContainer.add(centerPa
4、nel,"Center");thisContainer.add(southPanel,"South");thisContainer.add(northPanel,"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][
5、rows].addActionListener(this);centerPanel.add(diamondsButton[cols][rows]);}}exitButton=newJButton("退出");exitButton.addActionListener(this);resetButton=newJButton("重列");resetButton.addActionListener(this);newlyButton=newJButton("再来一局");newlyButton.addActionListener(this);southPanel.add(e
6、xitButton);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);}publicvoidrandomBuild(){intrandoms,cols,rows
7、;for(inttwins=1;twins<=15;twins++){randoms=(int)(Math.random()*25+1);for(intalike=1;alike<=2;alike++){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]=random