| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1797 人关注过本帖
标题:[分享][原创]Java & C# 版扫雷
只看楼主 加入收藏
au
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2005-6-9
收藏
 问题点数:0 回复次数:15 
[分享][原创]Java & C# 版扫雷
扫雷游戏,都会玩吧
u1icIZcg.rar (200.32 KB) [分享][原创]Java & C# 版扫雷



[此贴子已经被作者于2005-6-13 8:55:57编辑过]


搜索更多相关主题的帖子: Java 扫雷 游戏 分享 
2005-06-12 00:36
au
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2005-6-9
收藏
得分:0 
上传的东西怎么显示出来?  不会弄~~

2005-06-12 00:41
tempnetbar
Rank: 2
等 级:新手上路
威 望:4
帖 子:582
专家分:4
注 册:2004-5-5
收藏
得分:0 
不要用快速回复。点回复文章,应该能看到的

相信勤能补拙! 喜欢用好用的就永远学不到有用的。
2005-06-12 07:38
au
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2005-6-9
收藏
得分:0 
也不是这样搞?  哎 ~~   菜鸟~~  不会,算了

2005-06-12 10:06
au
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2005-6-9
收藏
得分:0 
文件Jbomb.java
========================== package jbomb; import javax.swing.*; public class Jbomb{ public static void main(String[] args){ JFrame.setDefaultLookAndFeelDecorated(true); JFrame fm = new Frame_Main(); fm.show(); } }
文件 Frame_About.java
================================ package jbomb; import java.awt.event.*; import javax.swing.*; public class Frame_About extends JFrame{ private Frame_Main fmn; private ImageIcon ico = new ImageIcon(""); private JLabel jlb_name = new JLabel("Java版扫雷"); private JLabel jlb_date_name = new JLabel("2004.12.29 泉."); private JPanel ContentPane = (JPanel)this.getContentPane(); public Frame_About(Frame_Main fm){ Frame_About_WindowListener faw = new Frame_About_WindowListener(this); this.fmn = fm; this.setSize(190,140); int intx = fmn.getX() + (fmn.getWidth()-this.getWidth())/2; int inty = fmn.getY() + (fmn.getHeight()-this.getHeight())/2; this.setLocation(intx,inty); this.addWindowListener(faw); this.setTitle("关于"); this.setIconImage(ico.getImage()); this.setResizable(false); this.setVisible(true); jlb_name.setFont(new java.awt.Font("Dialog", 3, 30)); jlb_name.setBounds(4,0,190,56); jlb_date_name.setBounds(10,57,160,24); jlb_date_name.setHorizontalAlignment(SwingConstants.CENTER); ContentPane.setLayout(null); ContentPane.add(jlb_name); ContentPane.add(jlb_date_name); } public void Frame_About_Closing(WindowEvent e){ if(fmn.thetime != 0) fmn.Set_timer_start(); fmn.setEnabled(true); } } class Frame_About_WindowListener extends WindowAdapter{ Frame_About fa; public Frame_About_WindowListener(Frame_About fa){ this.fa = fa; } public void windowClosing(WindowEvent e){ fa.Frame_About_Closing(e); } } 文件 Frame_Win.java
========================= package jbomb; import javax.swing.*; import java.awt.event.*; public class Frame_Win extends JFrame{ private ImageIcon ico = new ImageIcon(""); private JPanel ContentPane = (JPanel)this.getContentPane(); private Frame_Win_Listener fwl = new Frame_Win_Listener(this); private JLabel jlb_title = new JLabel("Java版扫雷"); private JLabel jlb_gx = new JLabel("恭喜你过关了!"); private JLabel jlb_lv = new JLabel(); private JLabel jlb_time = new JLabel(); private JLabel jlb_line = new JLabel("===================="); private Frame_Main fmn; public Frame_Win(Frame_Main fm){ this.fmn = fm; this.setSize(174,150); int intx = fmn.getX() + (fmn.getWidth()-this.getWidth())/2; int inty = fmn.getY() + (fmn.getHeight()-this.getHeight())/2; this.setLocation(intx,inty); this.setTitle("Java版扫雷"); this.setIconImage(ico.getImage()); this.setResizable(false); this.setVisible(true); this.addWindowListener(fwl); jlb_title.setBounds(8,8,144,24); jlb_title.setFont(new java.awt.Font("Dialog", 1, 15)); jlb_title.setHorizontalAlignment(SwingConstants.CENTER); jlb_gx.setBounds(8,36,152,16); jlb_gx.setHorizontalAlignment(SwingConstants.CENTER); jlb_lv.setBounds(8,56,136,16); jlb_lv.setText("游戏难度: " + fm.nowlv); jlb_time.setBounds(8,76,136,16); jlb_time.setText("过关所用时间: " + fm.thetime + " 秒"); jlb_line.setBounds(4,96,188,16); ContentPane.setLayout(null); ContentPane.add(jlb_title); ContentPane.add(jlb_gx); ContentPane.add(jlb_lv); ContentPane.add(jlb_time); ContentPane.add(jlb_line); } public void Frame_Win_Closing(WindowEvent e){ fmn.setEnabled(true); fmn.chushihua(); } public void jbtn_ok_actionPerformed(ActionEvent e){ this.setState(JFrame.EXIT_ON_CLOSE); } } class Frame_Win_Listener extends WindowAdapter{ Frame_Win fw; public Frame_Win_Listener(Frame_Win fw){ this.fw = fw; } public void windowClosing(WindowEvent e){ fw.Frame_Win_Closing(e); } }

2005-06-12 10:45
au
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2005-6-9
收藏
得分:0 
文件Frame_Main.java
============================
package jbomb;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class Frame_Main extends JFrame{
private JPanel ContentPane = (JPanel)this.getContentPane();
private JPanel jP_bomb = new JPanel();
private JPanel jP_btn = new JPanel();
private JButton jbtn_about = new JButton();
private JLabel jlb_bomb_num = new JLabel();
private JLabel jlb_time = new JLabel();
private JLabel jlb_lv = new JLabel();
private JLabel jlb_cblv = new JLabel();
private JComboBox jcb_lv = new JComboBox();
private JButton jbtn_restart = new JButton();
private Frame_Main_Listener fml = new Frame_Main_Listener(this);
private ImageIcon ico = new ImageIcon("F:\\10.ico");
private javax.swing.Timer timer;
private Color EnteredColor = new Color(192, 192, 255);
private Color LeftPressedColor = new Color(255, 255, 192);
private Color RightPressedColor = new Color(192, 255, 192);
private Color DefaultColor = Color.darkGray;
private Color ShowColor = new Color(192, 192, 192);
private boolean isbothdown = false;
private boolean isFail = false;
private boolean iswin = false; //用来限制只能弹出一个过关窗口
private int ismd; //判断鼠标按下状态
private int intzs; //左上角位置
private int intys; //右上角位置
private int intzx; //左下角位置
private int intyx; //右下角位置
private JLabel[] JlbList;
private int[] IntList;
private int[] OOList;
private int count; //方块总数
private int lnum; //列数;
private int hnum; //行数;
private int ln = 0; //雷总数;
public String nowlv = "初级";
public int thetime = 0;

public Frame_Main(){
jbtn_restart_ActionListener jra = new jbtn_restart_ActionListener(this);
jcl_lv_ItemListener jli = new jcl_lv_ItemListener(this);
timer_ActionListener ta = new timer_ActionListener(this);
jbtn_about_ActionListener jaa = new jbtn_about_ActionListener(this);
timer = new javax.swing.Timer(1000,ta);

this.setTitle("Java版扫雷");
this.setBounds(100,100,300,208);
this.setResizable(false);
this.setVisible(true);
this.setIconImage(ico.getImage());
this.addWindowListener(fml);

jbtn_about.setBounds(42,4,60,18);
jbtn_about.setText("关于");
jbtn_about.addActionListener(jaa);

jlb_time.setBounds(8,30,88,24);
jlb_time.setText("000");
jlb_time.setBorder(BorderFactory.createLineBorder(Color.black));
jlb_time.setHorizontalAlignment(SwingConstants.CENTER);

jlb_bomb_num.setBounds(8,60,88,24);
jlb_bomb_num.setText("000");
jlb_bomb_num.setBorder(BorderFactory.createLineBorder(Color.black));
jlb_bomb_num.setHorizontalAlignment(SwingConstants.CENTER);

jlb_lv.setBounds(8,90,36,24);
jlb_lv.setText("难度:");

jlb_cblv.setBounds(40,90,56,24);
jlb_cblv.setBorder(BorderFactory.createLineBorder(Color.black));
jlb_cblv.setHorizontalAlignment(SwingConstants.CENTER);
jlb_cblv.setVisible(false);

jcb_lv.setBounds(40,90,56,24);
jcb_lv.addItem("初级");
jcb_lv.addItem("中级");
jcb_lv.addItem("高级");
jcb_lv.addItemListener(jli);

jbtn_restart.setBounds(8,120,88,30);
jbtn_restart.setText("重新开始");
jbtn_restart.addActionListener(jra);

jP_bomb.setBounds(8,8,156,156);
jP_bomb.setBorder(BorderFactory.createLineBorder(Color.black));
jP_bomb.setLayout(null);

jP_btn.setBounds(176,8,104,156);
jP_btn.setBorder(BorderFactory.createLineBorder(Color.black));
jP_btn.setLayout(null);
jP_btn.add(jbtn_about);
jP_btn.add(jlb_time);
jP_btn.add(jlb_bomb_num);
jP_btn.add(jlb_lv);
jP_btn.add(jcb_lv);
jP_btn.add(jlb_cblv);
jP_btn.add(jbtn_restart);

ContentPane.setLayout(null);
ContentPane.add(jP_bomb);
ContentPane.add(jP_btn);

chushihua();
}

public void chushihua(){
int i = 0;
int j = 0;
int tmpnum = 0;
int zwln = 0;
boolean[] iscz;
ismd = 0;
isbothdown = false;
isFail = false;
thetime = 0;
iswin = false;
jP_bomb.removeAll();
jbtn_restart.setEnabled(false);
jlb_cblv.setVisible(false);
jcb_lv.setVisible(true);
jlb_time.setText("000");
timer.stop();
Random rnd = new Random();
JLabel jlb;
jlb_MouseListener jml = new jlb_MouseListener(this);
if(nowlv.equals("初级")){
lnum = 9;
hnum = 9;
intzs = 0;
intys = 8;
intzx = 72;
intyx = 80;
ln = 10;
this.setSize(300,208);
jP_bomb.setSize(156,156);
jP_btn.setLocation(176,8);
}
else if(nowlv.equals("中级")){
lnum = 16;
hnum = 16;
intzs = 0;
intys = 15;
intzx = 240;
intyx = 255;
ln = 40;
this.setSize(419,327);
jP_bomb.setSize(275,275);
jP_btn.setLocation(42,4);
jP_btn.setLocation(295,8);
}
else if(nowlv.equals("高级")){
lnum = 30;
hnum = 16;
intzs = 0;
intys = 29;
intzx = 450;
intyx = 479;
ln = 99;
this.setSize(659,327);
jP_bomb.setSize(513,275);
jP_btn.setLocation(535,8);
}
jlb_bomb_num.setText("0"+ln);
count = lnum * hnum;
JlbList = new JLabel[count];
IntList = new int[count];
OOList = new int[count];
iscz = new boolean[count];
for(i = 0;i < hnum;i++){
for(j = 0;j < lnum;j++ ){
jlb = new JLabel();
jlb.setBorder(BorderFactory.createLineBorder(Color.black));
jlb.setBounds(17*j+1,17*i+1,18,18);
jlb.setOpaque(true);
jlb.setBackground(DefaultColor);
jlb.setHorizontalAlignment(SwingConstants.CENTER);
jlb.addMouseListener(jml);
JlbList[tmpnum] = jlb;
IntList[tmpnum] = 0;
OOList[tmpnum] = 0;
iscz[tmpnum] = false;
jP_bomb.add(jlb);
tmpnum ++;
}
}
this.repaint();
for(int n = 0;n < ln;n++){
int rndint = (int)(rnd.nextInt(count));
if(iscz[rndint] == false){
IntList[rndint] = 9;
iscz[rndint] = true;
}
else{
n--;
}
}

for(i = 0;i < count;i++){
if(IntList[i] == 0){
if(i == intzs){
if(IntList[i+1] == 9) zwln++;
if(IntList[i+lnum] == 9) zwln++;
if(IntList[i+lnum+1] == 9) zwln++;
}
else if(i == intys){
if(IntList[i-1] == 9) zwln++;
if(IntList[i+lnum-1] == 9) zwln++;
if(IntList[i+lnum] == 9) zwln++;
}
else if(i == intzx){
if(IntList[i-lnum] == 9) zwln++;
if(IntList[i-lnum+1] == 9) zwln++;
if(IntList[i+1] == 9) zwln++;
}
else if(i == intyx){
if(IntList[i-lnum-1] == 9) zwln++;
if(IntList[i-lnum] == 9) zwln++;
if(IntList[i-1] == 9) zwln++;
}
else if(i > intzs && i < intys){
if(IntList[i-1] == 9) zwln++;
if(IntList[i+1] == 9) zwln++;
if(IntList[i+lnum-1] == 9) zwln++;
if(IntList[i+lnum] == 9) zwln++;
if(IntList[i+lnum+1] == 9) zwln++;
}
else if(i > intzx && i < intyx){
if(IntList[i-lnum-1] == 9) zwln++;
if(IntList[i-lnum] == 9) zwln++;
if(IntList[i-lnum+1] == 9) zwln++;
if(IntList[i-1] == 9) zwln++;
if(IntList[i+1] == 9) zwln++;
}
else if(i > intzs && i < intzx && i % lnum == 0){
if(IntList[i-lnum] == 9) zwln++;
if(IntList[i-lnum+1] == 9) zwln++;
if(IntList[i+1] == 9) zwln++;
if(IntList[i+lnum] == 9) zwln++;
if(IntList[i+lnum+1] == 9) zwln++;
}
else if(i > intys && i < intyx && (i+1) % lnum == 0){
if(IntList[i-lnum-1] == 9) zwln++;
if(IntList[i-lnum] == 9) zwln++;
if(IntList[i-1] == 9) zwln++;
if(IntList[i+lnum-1] == 9) zwln++;
if(IntList[i+lnum] == 9) zwln++;
}
else if(i < intyx - lnum){
if(IntList[i-lnum-1] == 9) zwln++;
if(IntList[i-lnum] == 9) zwln++;
if(IntList[i-lnum+1] == 9) zwln++;
if(IntList[i-1] == 9) zwln++;
if(IntList[i+1] == 9) zwln++;
if(IntList[i+lnum-1] == 9) zwln++;
if(IntList[i+lnum] == 9) zwln++;
if(IntList[i+lnum+1] == 9) zwln++;
}
IntList[i] = zwln;
zwln = 0;
}
}
}

public void jlb_mouseExited(MouseEvent e){
if(isFail == false){
if(ismd == 0){
JLabel jlb = (JLabel)e.getSource();
int n = (int)(jlb.getX() / 17) + (int)(jlb.getY() / 17) * lnum;
if(IntList[n] == 10){
jlb.setBackground(ShowColor);
}
else{
jlb.setBackground(DefaultColor);
}
}
}
}

public void jlb_mouseEntered(MouseEvent e){
if(isFail == false){
if(ismd == 0){
JLabel jlb = (JLabel)e.getSource();
jlb.setBackground(EnteredColor);
}
}
}

public void jlb_mousePressed(MouseEvent e){
if(isFail == false){
ismd++;
jbtn_restart.setEnabled(true);
jcb_lv.setVisible(false);
jlb_cblv.setVisible(true);
jlb_cblv.setText(nowlv+"");
if(ismd == 2) isbothdown = true;
JLabel jlb = (JLabel)e.getSource();
int n = (int)(jlb.getX() / 17) + (int)(jlb.getY() / 17) * lnum;
int l = 0;
JLabel tmpjlb = new JLabel();
int m;
timer.start();
if(isbothdown == true){
jlb.setBackground(LeftPressedColor);
if(n == intzs){
for(m = 0;m <= 2;m++){
switch (m){
case 0 :
l = n + 1;
break;
case 1 :
l= n + lnum;
break;
case 2 :
l = n + lnum + 1;
break;
}
tmpjlb = (JLabel)JlbList[l];
if(tmpjlb.getBackground() == DefaultColor && OOList[l] == 0)
tmpjlb.setBackground(LeftPressedColor);
}
}
else if(n == intys){
for(m = 0;m <= 2;m++){
switch (m){
case 0 :
l = n - 1;
break;
case 1 :
l = n + lnum- 1;
break;
case 2 :
l = n + lnum;
break;
}
tmpjlb = (JLabel)JlbList[l];
if(tmpjlb.getBackground() == DefaultColor && OOList[l] == 0)
tmpjlb.setBackground(LeftPressedColor);
}
}
else if(n == intzx){
for(m = 0;m <= 2;m++){
switch (m){
case 0 :
l = n - lnum;
break;
case 1 :
l = n - lnum + 1;
break;
case 2 :
l = n + 1;
break;
}
tmpjlb = (JLabel)JlbList[l];
if(tmpjlb.getBackground() == DefaultColor && OOList[l] == 0)
tmpjlb.setBackground(LeftPressedColor);
}
}
else if(n == intyx){
for(m = 0;m <= 2;m++){
switch (m){
case 0 :
l = n - lnum - 1;
break;
case 1 :
l = n - lnum;
break;
case 2 :
l = n - 1;
break;
}
tmpjlb = (JLabel)JlbList[l];
if(tmpjlb.getBackground() == DefaultColor && OOList[l] == 0)
tmpjlb.setBackground(LeftPressedColor);
}
}
else if(n > intzs && n < intys){
for(m = 0;m <= 4;m++){
switch (m){
case 0 :
l = n - 1;
break;
case 1 :
l = n + 1;
break;
case 2 :
l = n + lnum - 1;
break;
case 3 :
l = n + lnum;
break;
case 4 :
l = n + lnum + 1;
break;
}
tmpjlb = (JLabel)JlbList[l];
if(tmpjlb.getBackground() == DefaultColor && OOList[l] == 0)
tmpjlb.setBackground(LeftPressedColor);
}
}
else if(n > intzx && n < intyx){
for(m = 0;m <= 4;m++){
switch (m){
case 0 :
l = n - lnum - 1;
break;
case 1 :
l = n - lnum;
break;
case 2 :
l = n - lnum + 1;
break;
case 3 :
l = n - 1;
break;
case 4 :
l = n + 1;
break;
}
tmpjlb = (JLabel)JlbList[l];
if(tmpjlb.getBackground() == DefaultColor && OOList[l] == 0)
tmpjlb.setBackground(LeftPressedColor);
}
}
else if(n > intzs && n < intzx && n % lnum == 0){
for(m = 0;m <= 4;m++){
switch (m){
case 0 :
l = n - lnum;
break;
case 1 :
l = n - lnum + 1;
break;
case 2 :
l = n + 1;
break;
case 3 :
l = n + lnum;
break;
case 4 :
l = n + lnum + 1;
break;
}
tmpjlb = (JLabel)JlbList[l];
if(tmpjlb.getBackground() == DefaultColor && OOList[l] == 0)
tmpjlb.setBackground(LeftPressedColor);
}
}
else if(n > intys && n < intyx && (n+1) % lnum == 0){
for(m = 0;m <= 4;m++){
switch (m){
case 0 :
l = n - lnum - 1;
break;
case 1 :
l = n - lnum;
break;
case 2 :
l = n - 1;
break;
case 3 :
l = n + lnum - 1;
break;
case 4 :
l = n + lnum;
break;
}
tmpjlb = (JLabel)JlbList[l];
if(tmpjlb.getBackground() == DefaultColor && OOList[l] == 0)
tmpjlb.setBackground(LeftPressedColor);
}
}
else if(n < intyx){
for(m = 0;m <= 7;m++){
switch (m){
case 0 :
l = n - lnum - 1;
break;
case 1 :
l = n - lnum;
break;
case 2 :
l = n - lnum + 1;
break;
case 3 :
l = n - 1;
break;
case 4 :
l = n + 1;
break;
case 5 :
l = n + lnum - 1;
break;
case 6 :
l = n + lnum;
break;
case 7 :
l = n + lnum + 1;
break;
}
tmpjlb = (JLabel)JlbList[l];
if(tmpjlb.getBackground() == DefaultColor && OOList[l] == 0)
tmpjlb.setBackground(LeftPressedColor);
}
}
}
else if(e.getButton() == MouseEvent.BUTTON1){
jlb.setBackground(LeftPressedColor);
}
else if(e.getButton() == MouseEvent.BUTTON3){
if(IntList[n] != 10){
jlb.setBackground(RightPressedColor);
if(OOList[n] == 0){
OOList[n] = 2;
jlb.setText("△");
ln--;
if(ln >= 0){
jlb_bomb_num.setText(ln+"");
while (jlb_bomb_num.getText().length() < 3){
jlb_bomb_num.setText("0"+jlb_bomb_num.getText());
}
}
}
else if(OOList[n] == 2){
OOList[n] = 3;
jlb.setText("?");
}
else if(OOList[n] == 3){
OOList[n] = 0;
jlb.setText("");
ln++;
if(ln >= 0){
jlb_bomb_num.setText(ln+"");
while (jlb_bomb_num.getText().length() < 3){
jlb_bomb_num.setText("0"+jlb_bomb_num.getText());
}
}
}
}
if(ln == 0) Iswin();
}
}
}


(这个文件未完续下)

2005-06-12 10:47
au
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2005-6-9
收藏
得分:0 
(续上)
public void jlb_mouseReleased(MouseEvent e){
if(isFail == false){
int opd = 0;
JLabel jlb = (JLabel)e.getSource();
int n = (int)(jlb.getX() / 17) + (int)(jlb.getY() / 17) * lnum;
ismd--;

if(e.getButton() == MouseEvent.BUTTON1 && isbothdown == false){
if(IntList[n] == 10){
jlb.setBackground(EnteredColor);
}
else if(OOList[n] == 2 || OOList[n] == 3){
jlb.setBackground(DefaultColor);
}
else if(OOList[n] == 0){
OOList[n] = 1;
ShowResult();
}
}
else if(e.getButton() == MouseEvent.BUTTON3 && isbothdown == false){
if(IntList[n] == 10){
jlb.setBackground(EnteredColor);
}
else{
jlb.setBackground(DefaultColor);
}
}

if(ismd == 0) isbothdown = false;

JLabel tmpjlb = new JLabel();
if(isbothdown == true){
if(IntList[n] == 10){
if(n == intzs){
if(OOList[n+1] == 2) opd++;
if(OOList[n+lnum] == 2) opd++;
if(OOList[n+lnum+1] == 2) opd++;
}
else if(n == intys){
if(OOList[n-1] == 2) opd++;
if(OOList[n+lnum-1] == 2) opd++;
if(OOList[n+lnum] == 2) opd++;
}
else if(n == intzx){
if(OOList[n-lnum] == 2) opd++;
if(OOList[n-lnum+1] == 2) opd++;
if(OOList[n+1] == 2) opd++;
}
else if(n == intyx){
if(OOList[n-lnum-1] == 2) opd++;
if(OOList[n-lnum] == 2) opd++;
if(OOList[n-1] == 2) opd++;
}
else if(n > intzs && n < intys){
if(OOList[n-1] == 2) opd++;
if(OOList[n+1] == 2) opd++;
if(OOList[n+lnum-1] == 2) opd++;
if(OOList[n+lnum] == 2) opd++;
if(OOList[n+lnum+1] == 2) opd++;
}
else if(n > intzx && n < intyx){
if(OOList[n-lnum-1] == 2) opd++;
if(OOList[n-lnum] == 2) opd++;
if(OOList[n-lnum+1] == 2) opd++;
if(OOList[n-1] == 2) opd++;
if(OOList[n+1] == 2) opd++;
}
else if(n > intzs && n < intzx && n % lnum == 0){
if(OOList[n-lnum] == 2) opd++;
if(OOList[n-lnum+1] == 2) opd++;
if(OOList[n+1] == 2) opd++;
if(OOList[n+lnum] == 2) opd++;
if(OOList[n+lnum+1] == 2) opd++;
}
else if(n > intys && n < intyx && (n+1) % lnum == 0){
if(OOList[n-lnum-1] == 2) opd++;
if(OOList[n-lnum] == 2) opd++;
if(OOList[n-1] == 2) opd++;
if(OOList[n+lnum-1] == 2) opd++;
if(OOList[n+lnum] == 2) opd++;
}
else if(n < intyx - lnum){
if(OOList[n-lnum-1] == 2) opd++;
if(OOList[n-lnum] == 2) opd++;
if(OOList[n-lnum+1] == 2) opd++;
if(OOList[n-1] == 2) opd++;
if(OOList[n+1] == 2) opd++;
if(OOList[n+lnum-1] == 2) opd++;
if(OOList[n+lnum] == 2) opd++;
if(OOList[n+lnum+1] == 2) opd++;
}

if(jlb.getText().equals(opd+"")){
if(n == intzs){
if(OOList[n+1] == 0) OOList[n+1] = 1;
if(OOList[n+lnum] == 0) OOList[n+lnum] = 1;
if(OOList[n+lnum+1] == 0) OOList[n+lnum+1] = 1;
}
else if(n == intys){
if(OOList[n-1] == 0) OOList[n-1] = 1;
if(OOList[n+lnum-1] == 0) OOList[n+lnum-1] = 1;
if(OOList[n+lnum] == 0) OOList[n+lnum] = 1;
}
else if(n == intzx){
if(OOList[n-lnum] == 0) OOList[n-lnum] = 1;
if(OOList[n-lnum+1] == 0) OOList[n-lnum+1] = 1;
if(OOList[n+1] == 0) OOList[n+1] = 1;
}
else if(n == intyx){
if(OOList[n-lnum-1] == 0) OOList[n-lnum-1] = 1;
if(OOList[n-lnum] == 0) OOList[n-lnum] = 1;
if(OOList[n-1] == 0) OOList[n-1] = 1;
}
else if(n > intzs && n < intys){
if(OOList[n-1] == 0) OOList[n-1] = 1;
if(OOList[n+1] == 0) OOList[n+1] = 1;
if(OOList[n+lnum-1] == 0) OOList[n+lnum-1] = 1;
if(OOList[n+lnum] == 0) OOList[n+lnum] = 1;
if(OOList[n+lnum+1] == 0) OOList[n+lnum+1] = 1;
}
else if(n > intzx && n < intyx){
if(OOList[n-lnum-1] == 0) OOList[n-lnum-1] = 1;
if(OOList[n-lnum] == 0) OOList[n-lnum] = 1;
if(OOList[n-lnum+1] == 0) OOList[n-lnum+1] = 1;
if(OOList[n-1] == 0) OOList[n-1] = 1;
if(OOList[n+1] == 0) OOList[n+1] = 1;
}
else if(n > intzs && n < intzx && n % lnum == 0){
if(OOList[n-lnum] == 0) OOList[n-lnum] = 1;
if(OOList[n-lnum+1] == 0) OOList[n-lnum+1] = 1;
if(OOList[n+1] == 0) OOList[n+1] = 1;
if(OOList[n+lnum] == 0) OOList[n+lnum] = 1;
if(OOList[n+lnum+1] == 0) OOList[n+lnum+1] = 1;
}
else if(n > intys && n < intyx && (n+1) % lnum == 0){
if(OOList[n-lnum-1] == 0) OOList[n-lnum-1] = 1;
if(OOList[n-lnum] == 0) OOList[n-lnum] = 1;
if(OOList[n-1] == 0) OOList[n-1] = 1;
if(OOList[n+lnum-1] == 0) OOList[n+lnum-1] = 1;
if(OOList[n+lnum] == 0) OOList[n+lnum] = 1;
}
else if(n < intyx - lnum){
if(OOList[n-lnum-1] == 0) OOList[n-lnum-1] = 1;
if(OOList[n-lnum] == 0) OOList[n-lnum] = 1;
if(OOList[n-lnum+1] == 0) OOList[n-lnum+1] = 1;
if(OOList[n-1] == 0) OOList[n-1] = 1;
if(OOList[n+1] == 0) OOList[n+1] = 1;
if(OOList[n+lnum-1] == 0) OOList[n+lnum-1] = 1;
if(OOList[n+lnum] == 0) OOList[n+lnum] = 1;
if(OOList[n+lnum+1] == 0) OOList[n+lnum+1] = 1;
}
ShowResult();
}
}
}

for(int i=0;i < count;i++){
tmpjlb = (JLabel)JlbList[i];
if(tmpjlb.getBackground() != ShowColor || tmpjlb.getBackground() != DefaultColor){
if(IntList[i] == 10)
tmpjlb.setBackground(ShowColor);
else
tmpjlb.setBackground(DefaultColor);
}
}

if(ln == 0 && iswin == false) Iswin();
}
}

public void jbtn_restart_actionPerformed(ActionEvent e){
timer.stop();
if(isFail == false){
int n = JOptionPane.showConfirmDialog(null,"确定要重新开始游戏吗?",
this.getTitle(),JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);
if(n == JOptionPane.YES_OPTION)
chushihua();
else{
timer.start();
}
}
else{
chushihua();
}
}

public void jcb_lv_itemStateChanged(ItemEvent e){
if(!(e.getItem().toString().equals(nowlv))){
nowlv = e.getItem().toString();
chushihua();
}
}

public void ShowResult(){
JLabel jlb;
boolean isagn = true;
while (isagn == true){
isagn = false;
for(int i = 0;i < count; i++){
if(IntList[i] == 0 && OOList[i] == 1){
jlb = (JLabel)JlbList[i];
jlb.setBackground(ShowColor);
IntList[i] = 10;
if(i == intzs){
OOList[i+1] = 1;
OOList[i+lnum] = 1;
OOList[i+lnum+1] = 1;
isagn = true;
}
else if(i == intys){
OOList[i-1] = 1;
OOList[i+lnum-1] = 1;
OOList[i+lnum] = 1;
isagn = true;
}
else if(i == intzx){
OOList[i-lnum] = 1;
OOList[i-lnum+1] = 1;
OOList[i+1] = 1;
isagn = true;
}
else if(i == intyx){
OOList[i-lnum-1] = 1;
OOList[i-lnum] = 1;
OOList[i-1] = 1;
isagn = true;
}
else if(i > intzs && i < intys){
OOList[i-1] = 1;
OOList[i+1] = 1;
OOList[i+lnum-1] = 1;
OOList[i+lnum] = 1;
OOList[i+lnum+1] = 1;
isagn = true;
}
else if(i > intzx && i < intyx){
OOList[i-lnum-1] = 1;
OOList[i-lnum] = 1;
OOList[i-lnum+1] = 1;
OOList[i-1] = 1;
OOList[i+1] = 1;
isagn = true;
}
else if(i > intzs && i < intzx && i % lnum == 0){
OOList[i-lnum] = 1;
OOList[i-lnum+1] = 1;
OOList[i+1] = 1;
OOList[i+lnum] = 1;
OOList[i+lnum+1] = 1;
isagn = true;
}
else if(i > intys && i < intyx && (i+1) % lnum == 0){
OOList[i-lnum-1] = 1;
OOList[i-lnum] = 1;
OOList[i-1] = 1;
OOList[i+lnum-1] = 1;
OOList[i+lnum] = 1;
isagn = true;
}
else if(i < intyx - lnum){
OOList[i-lnum-1] = 1;
OOList[i-lnum] = 1;
OOList[i-lnum+1] = 1;
OOList[i-1] = 1;
OOList[i+1] = 1;
OOList[i+lnum-1] = 1;
OOList[i+lnum] = 1;
OOList[i+lnum+1] = 1;
isagn = true;
}
}
}
}

for(int j = 0;j < count;j++){
if(IntList[j] >= 1 && IntList[j] <= 8 && OOList[j] == 1){
jlb = (JLabel)JlbList[j];
jlb.setText(IntList[j]+"");
jlb.setBackground(ShowColor);
IntList[j] = 10;
}
}

for(int k = 0;k < count;k++){
if(IntList[k] == 9 && OOList[k] == 1){
for(int s = 0;s < count;s++){
jlb = (JLabel)JlbList[s];
if(IntList[s] == 9 && OOList[s] == 2){
jlb.setText("√");
jlb.setForeground(Color.green);
}
else if(IntList[s] != 9 && OOList[s] == 2){
jlb.setText("×");
jlb.setForeground(Color.red);
}
else if(IntList[s] == 9 && OOList[s] == 1){
jlb.setText("¤");
jlb.setForeground(Color.red);
}
else if(IntList[s] == 9 && OOList[s] == 0){
jlb.setText("●");
jlb.setForeground(Color.black);
}
}
jlb_cblv.setVisible(false);
jcb_lv.setVisible(true);
jbtn_restart.setEnabled(true);
isFail = true;
timer.stop();
break;
}
}
}


public void jbtn_about_actionPerformed(ActionEvent e){
Frame_About fa = new Frame_About(this);
timer.stop();
this.setEnabled(false);
fa.show();
}
public void Set_timer_start(){
this.timer.start();
}

public void timer_Tick(ActionEvent e){
thetime ++;
if(thetime < 1000){
jlb_time.setText(thetime+"");
while (jlb_time.getText().length() < 3){
jlb_time.setText("0"+jlb_time.getText());
}
}
}

public void Frame_Win_Closing(WindowEvent e){
System.exit(0);
}

public void Iswin(){
int k = 0;
JLabel jlb;
for(k = 0;k < count;k++){
jlb = (JLabel)JlbList[k];
if(IntList[k] == 9 && jlb.getText() != "△" ||
IntList[k] != 9 && jlb.getBackground() != ShowColor){
break;
}
}

if(k == count){
timer.stop();
iswin = true;
Frame_Win fw = new Frame_Win(this);
this.setEnabled(false);
fw.show();
}
}
}


class jlb_MouseListener extends MouseAdapter{
Frame_Main fm;
public jlb_MouseListener(Frame_Main fm){
this.fm = fm;
}
public void mouseEntered(MouseEvent e){
fm.jlb_mouseEntered(e);
}
public void mouseExited(MouseEvent e){
fm.jlb_mouseExited(e);
}
public void mousePressed(MouseEvent e){
fm.jlb_mousePressed(e);
}
public void mouseReleased(MouseEvent e){
fm.jlb_mouseReleased(e);
}
}

class jbtn_restart_ActionListener implements ActionListener{
Frame_Main fm;
public jbtn_restart_ActionListener(Frame_Main fm){
this.fm = fm;
}

public void actionPerformed(ActionEvent e){
fm.jbtn_restart_actionPerformed(e);
}

}

class jcl_lv_ItemListener implements ItemListener{
Frame_Main fm;
public jcl_lv_ItemListener(Frame_Main fm){
this.fm = fm;
}
public void itemStateChanged(ItemEvent e){
fm.jcb_lv_itemStateChanged(e);
}
}


class timer_ActionListener implements ActionListener{
Frame_Main fm;
public timer_ActionListener(Frame_Main fm){
this.fm = fm;
}
public void actionPerformed(ActionEvent e){
fm.timer_Tick(e);
}
}

class jbtn_about_ActionListener implements ActionListener{
Frame_Main fm;
public jbtn_about_ActionListener(Frame_Main fm){
this.fm = fm;
}
public void actionPerformed(ActionEvent e){
fm.jbtn_about_actionPerformed(e);
}
}

class Frame_Main_Listener extends WindowAdapter{
Frame_Main fm;
public Frame_Main_Listener(Frame_Main fm){
this.fm = fm;
}

public void windowClosing(WindowEvent e){
fm.Frame_Win_Closing(e);
}
}

2005-06-12 10:48
au
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2005-6-9
收藏
得分:0 
这是Java版的,一共有4个文件(Jbomb.java , Frame_About.java , Frame_Win.java ,  Frame_Main.java)

2005-06-12 10:55
tempnetbar
Rank: 2
等 级:新手上路
威 望:4
帖 子:582
专家分:4
注 册:2004-5-5
收藏
得分:0 
佩服你啊,,贴得累死了吧?给你加点分犒劳一下!

相信勤能补拙! 喜欢用好用的就永远学不到有用的。
2005-06-12 12:08
au
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2005-6-9
收藏
得分:0 
原来用FireFox浏览器是上传不了的,5次上传都没了,最后一次上传我把源代码文件贴到C#论坛了

2005-06-12 12:50
快速回复:[分享][原创]Java & C# 版扫雷
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014751 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved