源代码
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.*;
import java.io.*;
public class MineGame extends JFrame implements ActionListener{
JMenuBar bar;
JMenu fileMenu;
JMenuItem 初级 ,中级 ,高级 ,扫雷英雄榜 ;
MineArea mineArea=null;
File 英雄榜 =new File(" 英雄榜 .txt");
Hashtable hashtable=null;
ShowRecord showHeroRecord=null;
MineGame(){
mineArea=new MineArea(16,16,40,1);
add(mineArea,BorderLayout.CENTER);
bar=new JMenuBar();
fileMenu=new JMenu(" 游戏 ");
初级 =new JMenuItem(" 初级 ");
中级 =new JMenuItem(" 中级 ");
高级 =new JMenuItem(" 高级 ");
扫雷英雄榜 =new JMenuItem(" 扫雷英雄榜 ");
fileMenu.add( 初级 );
fileMenu.add( 中级 );
fileMenu.add( 高级 );
fileMenu.add( 扫雷英雄榜 );
bar.add(fileMenu);
setJMenuBar(bar);
初级 .addActionListener(this);
中级 .addActionListener(this);
高级 .addActionListener(this);
扫雷英雄榜 .addActionListener(this);
hashtable=new Hashtable();
hashtable.put("初级 "," 初级 #"+999+"# 匿名 ");
hashtable.put("中级 "," 中级 #"+999+"# 匿名 ");
hashtable.put("高级 "," 高级 #"+999+"# 匿名 ");
if(! 英雄榜 .exists()) {
try{ FileOutputStream out=new FileOutputStream( 英雄榜 );
ObjectOutputStream objectOut=new ObjectOutputStream(out);
objectOut.writeObject(hashtable);
objectOut.close();
out.close();
}
catch(IOException e){}
}
showHeroRecord=new ShowRecord(this,hashtable);
setBounds(100,100,280,380);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
validate();
}
public void actionPerformed(ActionEvent e){
if(e.getSource()== 初级 ){
mineArea.initMineArea(8,8,10,1);
setBounds(100,100,200,280);
}
if(e.getSource()== 中级 ){
mineArea.initMineArea(16,16,40,2);
setBounds(100,100,280,380);
}
if(e.getSource()== 高级 ){
mineArea.initMineArea(22,22,99,3);
setBounds(100,100,350,390);
}
if(e.getSource()== 扫雷英雄榜 ){
if(showHeroRecord!=null)
showHeroRecord.setVisible(true);
}
validate();
}
public static void main(String args[]){
new MineGame();
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MineArea extends JPanel implements ActionListener,MouseListener{
JButton reStart;
Block [][] block;
BlockView [][] blockView;
LayMines lay;
int row,colum,mineCount,markMount;// 雷区的行数、列数以及地雷个数和用户给出的标
记数
ImageIcon mark;
int grade;
JPanel pCenter,pNorth;
JTextField showTime,showMarkedMineCount; // 显示用时以及标记数
Timer time; //计时器
int spendTime=0;
Record record;
public MineArea(int row,int colum,int mineCount,int grade) {
reStart=new JButton(" 重新开始 ");
mark=new ImageIcon("mark.gif"); //探雷标记
time=new Timer(1000,this);
showTime=new JTextField(5);
showMarkedMineCount=new JTextField(5);
showTime.setHorizontalAlignment(JTextField.CENTER);
showMarkedMineCount.setHorizontalAlignment(JTextField.CENTER);
showMarkedMineCount.setFont(new Font("Arial",Font.BOLD,16));
showTime.setFont(new Font("Arial",Font.BOLD,16));
pCenter=new JPanel();
pNorth=new JPanel();
lay=new LayMines();
initMineArea(row,colum,mineCount,grade); // 初始化雷区 ,见下面的 LayMines()
reStart.addActionListener(this);
pNorth.add(showMarkedMineCount);
pNorth.add(reStart);
pNorth.add(showTime);
setLayout(new BorderLayout());
add(pNorth,BorderLayout.NORTH);
add(pCenter,BorderLayout.CENTER);
}
public void initMineArea(int row,int colum,int mineCount,int grade){
pCenter.removeAll();
spendTime=0;
markMount=mineCount;
this.row=row;
this.colum=colum;
this.mineCount=mineCount;
this.grade=grade;
block=new Block[row][colum];
for(int i=0;i
0&&block[m][n].getIsOpen()==false){
blockView[m][n].seeBlockNameOrIcon();
block[m][n].setIsOpen(true);
return;
}
else if(block[m][n].getAroundMineNumber()==0&&block[m][n].getIsOpen()==false){
blockView[m][n].seeBlockNameOrIcon();
block[m][n].setIsOpen(true);
for(int k=Math.max(m-1,0);k<=Math.min(m+1,row-1);k++) {
for(int t=Math.max(n-1,0);t<=Math.min(n+1,colum-1);t++)
show(k,t);
}
}
}
public void mousePressed(MouseEvent e){
JButton source=(JButton)e.getSource();
for(int i=0;i=1)
blockNameOrIcon.setText(""+n);
else
blockNameOrIcon.setText(" ");
}
}
public void seeBlockNameOrIcon(){
card.show(this,"view");
validate();
}
public void seeBlockCover(){
card.show(this,"cover");
validate();
}
public JButton getBlockCover(){
return blockCover;
}
}
import java.util.*;
import javax.swing.*;
public class LayMines{
ImageIcon mineIcon;
LayMines() {
mineIcon=new ImageIcon("mine.gif");
}
public void layMinesForBlock(Block block[][],int mineCount){
int row=block.length;
int column=block[0].length;
LinkedList list=new LinkedList();
for(int i=0;i0){
int size=list.size(); // list 返回节点的个数
int randomIndex=(int)(Math.random()*size);
Block b=list.get(randomIndex);
b.setIsMine(true);
b.setName("雷 ");
b.setMineIcon(mineIcon);
list.remove(randomIndex); //list 删除索引值为 randomIndex 的节点
mineCount--;
}
for(int i=0;i
记录
混凝土 养护记录下载土方回填监理旁站记录免费下载集备记录下载集备记录下载集备记录下载
你的成绩 ");
this.time=time;
this.grade=grade;
setBounds(100,100,240,160);
setResizable(false);
setModal(true);
确定 =new JButton(" 确定 ");
取消 =new JButton(" 取消 ");
textName=new JTextField(8);
textName.setText(" 匿名 ");
确定 .addActionListener(this);
取消 .addActionListener(this);
setLayout(new GridLayout(2,1));
label=new JLabel(" 您现在是 ...高手 ,输入您的大名上榜 ");
add(label);
JPanel p=new JPanel();
p.add(textName);
p.add(确定 );
p.add(取消 );
add(p);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
public void setGrade(String grade){
this.grade=grade;
label.setText("您现在是 "+grade+" 高手 ,输入您的大名上榜 ");
}
public void setTime(int time){
this.time=time;
}
public void actionPerformed(ActionEvent e){
if(e.getSource()== 确定 ){
message=grade+"#"+time+"#"+" "+textName.getText();
key=grade;
writeRecord(key,message);
setVisible(false);
}
if(e.getSource()== 取消 ){
setVisible(false);
}
}
public void writeRecord(String key,String message){
File f=new File(" 英雄榜 .txt");
try{ FileInputStream in=new FileInputStream(f);
ObjectInputStream object_in=new ObjectInputStream(in);
Hashtable hashtable=(Hashtable)object_in.readObject();
object_in.close();
in.close();
String temp=(String)hashtable.get(key);
StringTokenizer fenxi=new StringTokenizer(temp,"#");
fenxi.nextToken();
int n=Integer.parseInt(fenxi.nextToken());
if(time
本文档为【扫雷源代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。