基本信息
源码名称:基于java实现对对碰小游戏
源码大小:0.06M
文件格式:.zip
开发语言:Java
更新时间:2021-11-19
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 3 元×
微信扫码支付:3 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
对对碰小游戏
public MyFrame(){
actionPanel.setLayout(new FlowLayout());
actionPanel.add(buttonRestart,BorderLayout.CENTER);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(helpPanel,BorderLayout.NORTH);
this.getContentPane().add(gamePanel,BorderLayout.CENTER);
this.getContentPane().add(actionPanel,BorderLayout.SOUTH);
this.setSize(700,700);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("对对碰");
this.setVisible(true);
buttonRestart.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
if(flag)
return ;
flag = true;
gamePanel.addKeyListener(gamePanel);
gamePanel.addMouseListener(gamePanel);
gamePanel.startGame();
buttonRestart.setEnabled(false);
HelpPanel.score.setText(0 "");
new Thread(new Runnable(){
@Override
public void run() {
nowTime = 0;
while(true){
try {
Thread.currentThread().sleep(1000);
nowTime ;
HelpPanel.setTime(nowTime);
if(nowTime==100){
gamePanel.removeMouseListener(gamePanel);
gamePanel.removeKeyListener(gamePanel);
int score = Integer.parseInt(helpPanel.score.getText());
int record = Integer.parseInt(helpPanel.record.getText());
if(score>record){
JOptionPane.showMessageDialog(null, "游戏结束,你的得分是" score ",刷新了历史记录" record);
helpPanel.updateBestScore();
}else{
JOptionPane.showMessageDialog(null, "游戏结束,你的得分是" HelpPanel.score.getText());
}
buttonRestart.setEnabled(true);
flag = false;
break;
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();;
}
});
}
对对碰小游戏
public MyFrame(){
actionPanel.setLayout(new FlowLayout());
actionPanel.add(buttonRestart,BorderLayout.CENTER);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(helpPanel,BorderLayout.NORTH);
this.getContentPane().add(gamePanel,BorderLayout.CENTER);
this.getContentPane().add(actionPanel,BorderLayout.SOUTH);
this.setSize(700,700);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("对对碰");
this.setVisible(true);
buttonRestart.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
if(flag)
return ;
flag = true;
gamePanel.addKeyListener(gamePanel);
gamePanel.addMouseListener(gamePanel);
gamePanel.startGame();
buttonRestart.setEnabled(false);
HelpPanel.score.setText(0 "");
new Thread(new Runnable(){
@Override
public void run() {
nowTime = 0;
while(true){
try {
Thread.currentThread().sleep(1000);
nowTime ;
HelpPanel.setTime(nowTime);
if(nowTime==100){
gamePanel.removeMouseListener(gamePanel);
gamePanel.removeKeyListener(gamePanel);
int score = Integer.parseInt(helpPanel.score.getText());
int record = Integer.parseInt(helpPanel.record.getText());
if(score>record){
JOptionPane.showMessageDialog(null, "游戏结束,你的得分是" score ",刷新了历史记录" record);
helpPanel.updateBestScore();
}else{
JOptionPane.showMessageDialog(null, "游戏结束,你的得分是" HelpPanel.score.getText());
}
buttonRestart.setEnabled(true);
flag = false;
break;
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();;
}
});
}