当前位置:首页 » 操作系统 » 扫雷班源码

扫雷班源码

发布时间: 2022-06-25 09:44:21

① C语言扫雷源代码 用到图形函数 并且能用鼠标玩

看看这个如何!

#include <graphics.h>
#include <stdlib.h>
#include <dos.h>
#define LEFTPRESS 0xff01
#define LEFTCLICK 0xff10
#define LEFTDRAG 0xff19
#define MOUSEMOVE 0xff08
int num[10][10];/*范围*/
int p[10][10];/*统计雷的数组*/
int loop;/*重新来的标志*/
int again=0;/*是否重来的变量*/
int scorenum;/*一开始统计有几个雷*/
char score[3];/*输出一共有几个地雷*/
int Keystate;
int MouseExist;
int MouseButton;
int MouseX;
int MouseY;
/*鼠标光标形状定义*/
typedef struct
{
unsigned int shape[32];
char hotx;
char hoty;
}SHAPE;

/*箭头型*/
SHAPE ARROW={
{
0x3fff,0x1fff,0x0fff,0x07ff,
0x03ff,0x01ff,0x00ff,0x007f,
0x003f,0x00ff,0x01ff,0x10ff,
0x30ff,0xf87f,0xf87f,0xfc3f,
0x0000,0x7c00,0x6000,0x7000,
0x7800,0x7c00,0x7e00,0x7f00,
0x7f80,0x7e00,0x7c00,0x4600,
0x0600,0x0300,0x0300,0x0180
},
0,0,
};

/*鼠标光标显示*/
void MouseOn()
{
_AX=0x01;
geninterrupt(0x33);
}

/*鼠标光标掩示*/
void MouseOff()/*鼠标光标隐藏*/
{
_AX=0x02;
geninterrupt(0x33);
}
void MouseSetXY(int x,int y)/*设置当前位置*/
{
_CX=x;
_DX=y;
_AX=0x04;
geninterrupt(0x33);
}
int LeftPress()/*左键按下*/
{
_AX=0x03;
geninterrupt(0x33);
return(_BX&1);
}
void MouseGetXY()/*得到当前位置*/
{
_AX=0x03;
geninterrupt(0x33);
MouseX=_CX;
MouseY=_DX;
}
begain()/*游戏开始画面*/
{
int i,j;
loop: cleardevice();
MouseOn();
MouseSetXY(180,30);
MouseX=180;
MouseY=30;
scorenum=0;
setfillstyle(SOLID_FILL,7);
bar(190,60,390,290);
setfillstyle(SOLID_FILL,8);
for(i=100;i<300;i+=20)/*画格子*/
for(j=200;j<400;j+=20)
bar(j-8,i+8,j+8,i-8);
setcolor(7);
setfillstyle(SOLID_FILL,YELLOW);/*画脸*/
fillellipse(290,75,10,10);
setcolor(YELLOW);
setfillstyle(SOLID_FILL,0);
fillellipse(285,75,2,2);
fillellipse(295,75,2,2);
setcolor(0);
bar(287,80,293,81);
randomize();
for(i=0;i<10;i++)
for(j=0;j<10;j++)
{
num[i][j]=random(7)+10;/*用10代表地雷算了*/
if(num[i][j]==10)
scorenum++;
}
sprintf(score,"%d",scorenum);
setcolor(1);
settextstyle(0,0,2);
outtextxy(210,70,score);
scorenum=100-scorenum;/*为了后面判断胜利*/
}
gameove()/*游戏结束画面*/
{
int i,j;
setcolor(0);
for(i=0;i<10;i++)
for(j=0;j<10;j++)
if(num[i][j]==10)/*是地雷的就显示出来*/
{
setfillstyle(SOLID_FILL,RED);
bar(200+j*20-8,100+i*20-8,200+j*20+8,100+i*20+8);
setfillstyle(SOLID_FILL,0);
fillellipse(200+j*20,100+i*20,7,7);
}
}
int tongji(int i,int j)/*计算有几个雷*/
{
int x=0;/*10代表地雷*/
if(i==0&&j==0)
{
if(num[0][1]==10)
x++;
if(num[1][0]==10)
x++;
if(num[1][1]==10)
x++;
}
else if(i==0&&j==9)
{
if(num[0][8]==10)
x++;
if(num[1][9]==10)
x++;
if(num[1][8]==10)
x++;
}
else if(i==9&&j==0)
{
if(num[8][0]==10)
x++;
if(num[9][1]==10)
x++;
if(num[8][1]==10)
x++;
}
else if(i==9&&j==9)
{
if(num[9][8]==10)
x++;
if(num[8][9]==10)

java 扫雷源代码

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.Timer;

public class ScanLei1 extends JFrame implements ActionListener{

private static final long serialVersionUID = 1L;
private Container contentPane;
private JButton btn;
private JButton[] btns;
private JLabel b1;
private JLabel b2;
private JLabel b3;
private Timer timer;
private int row=9;
private int col=9;
private int bon=10;
private int[][] a;
private int b;
private int[] a1;
private JPanel p,p1,p2,p3;

public ScanLei1(String title){
super(title);
contentPane=getContentPane();
setSize(297,377);
this.setBounds(400, 100, 400, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
timer =new Timer(1000,(ActionListener) this);
a = new int[row+2][col+2];
initGUI();
}

public void initGUI(){
p3=new JPanel();
b=bon;
JMenuBar menuBar=new JMenuBar();
JMenu menu1=new JMenu("游戏");
JMenu menu2=new JMenu("帮助");
JMenuItem mi1=new JMenuItem("初级");
JMenuItem mi2 = new JMenuItem("中级");
JMenuItem mi3 =new JMenuItem("高级");
mi1.addActionListener(this);
menu1.add(mi1);
mi2.addActionListener(this);
menu1.add(mi2);
mi3.addActionListener(this);
menu1.add(mi3);
menuBar.add(menu1);
menuBar.add(menu2);
p3.add(menuBar);
b1=new JLabel(bon+"");
a1=new int[bon];
btn =new JButton("开始");
btn.addActionListener(this);
b2=new JLabel("0");
b3=new JLabel("");
btns=new JButton[row*col];
p=new JPanel();
p.setLayout(new BorderLayout());
contentPane.add(p);
p.add(p3,BorderLayout.NORTH);
//combo=new JComboBox(new Object[]{"初级","中级","高级"} );
//加监听
/*combo.addItemListener(new ItemListener(){
}});*/
p1=new JPanel();
//在那个位置
//(( FlowLayout)p1.getLayout()).setAlignment( FlowLayout.RIGHT);
p1.add(b1);
p1.add(btn);
p1.add(b2);
p1.add(b3);
p.add(p3,BorderLayout.NORTH);
p.add(p1,BorderLayout.CENTER);
p2=new JPanel();
p2.setLayout(new GridLayout(row,col,0,0));
for(int i=0;i<row*col;i++){
btns[i]=new JButton("");
btns[i].setMargin(new Insets(0,0,0,0));
btns[i].setFont(new Font(null,Font.BOLD,25));
btns[i].addActionListener(this);
btns[i].addMouseListener(new NormoreMouseEvent());
p2.add(btns[i]);
}
contentPane.add(p,BorderLayout.NORTH);
contentPane.add(p2,BorderLayout.CENTER);
}
public void go(){
setVisible(true);
}
public static void main(String[] args){
new ScanLei1("扫雷").go();
}
public void out(int[][] a,JButton[] btns,ActionEvent e,int i,int x,int y){
int p=1;
if(a[x][y]==0){
a[x][y]=10;
btns[i].setEnabled(false); //33
for(int l=y-1;l<=y+1;l++){
int m=x-1-1;
int n=l-1;
p=1;
System.out.println(a[1][2]);
if(n>-1&&n<col&&m>-1&&m<row)
{
for(int q=0;q<row&&p==1;q++){//col-->row;
if(((n+col*q)>=(m*col))&&((n+col*q)<(m+1)*col)){
if(a[x-1][l]!=0&&a[x-1][l]!=10){
btns[n+col*q].setText(a[x-1][l]+"");
a[x-1][l]=10;
btns[n+col*q].setEnabled(false);
}
else if(a[x-1][l]==0){
//a[x-1][l]=10;
btns[n+col*q].setEnabled(false);
out(a,btns,e,n+col*q,x-1,l); ////55////
a[x-1][l]=10;
btns[n+col*q].setEnabled(false);
}
p=0;

}
}
}
p=1;
m=x;
if(n>-1&&n<col&&m>-1&&m<col)
{
for(int q=0;q<row&&p==1;q++){
if(((n+col*q)>=(m*col))&&((n+col*q)<(m+1)*col)){
if(a[x+1][l]!=0&&a[x+1][l]!=10){
btns[n+col*q].setText(a[x+1][l]+"");
a[x+1][l]=10;
btns[n+col*q].setEnabled(false);
}
else if(a[x+1][l]==0){

out(a,btns,e,n+col*q,x+1,l);///55////
a[x+1][l]=10;
btns[n+col*q].setEnabled(false);
}
p=0;
}
}

}
}
int m=x-1;
int n=y-1-1;
p=1;
if(n>-1&&n<col&&m>-1&&m<col)
{
for(int q=0;q<row&&p==1;q++){
if(((n+col*q)>=(m*col))&&((n+col*q)<(m+1)*col)){
if(a[x][y-1]!=0&&a[x][y-1]!=10){
btns[n+col*q].setText(a[x][y-1]+"");
a[x][y-1]=10;
btns[n+col*q].setEnabled(false);
}
else if(a[x][y-1]==0){

out(a,btns,e,n+col*q,x,y-1);

a[x][y-1]=10;
btns[n+col*q].setEnabled(false);
}
p=0;
}
}
}
p=1;
m=x-1;
n=y+1-1;
if(n>-1&&n<col&&m>-1&&m<col)
{
for(int q=0;q<row&&p==1;q++){
if(((n+col*q)>=(m*col))&&((n+col*q)<(m+1)*col)){
if(a[x][y+1]!=0&&a[x][y+1]!=10){
btns[n+col*q].setText(a[x][y+1]+"");
a[x][y+1]=10;
btns[n+col*q].setEnabled(false);
}
else if(a[x][y+1]==0){
out(a,btns,e,n+col*q,x,y+1);
a[x][y+1]=10;
btns[n+col*q].setEnabled(false);
}
p=0;
}
}
}
}
}
public void actionPerformed(ActionEvent e) {

if(e.getActionCommand()=="初级"){
row=9;
col=9;
bon=10;
a1=new int[bon];
b=bon;
//setSize(297,377);
a = new int[row+2][col+2];
this.remove(p2);
timer.stop();
b1.setText("10");
b2.setText("0");
b3.setText("");
btns=new JButton[row*col];
p2=new JPanel();
p2.setLayout(new GridLayout(row,col,0,0));
for(int i=0;i<row*col;i++){
btns[i]=new JButton(" ");
btns[i].setMargin(new Insets(0,0,0,0));
btns[i].setFont(new Font(null,Font.BOLD,25));
btns[i].addActionListener(this);
btns[i].addMouseListener(new NormoreMouseEvent());
p2.add(btns[i]);
}
contentPane.add(p2,BorderLayout.CENTER);
//setSize(297,377);
this.pack();
for(int i=0;i<row*col;i++){
btns[i].setText(" ");
btns[i].setEnabled(true);
}
for(int i=0;i<row+2;i++){
for(int j=0;j<col+2;j++){
a[i][j]=0;
}
}

}else if(e.getActionCommand()=="中级"){
row=16;
col=16;
bon=40;
//setSize(33*col,33*row+80);
a1=new int[bon];
a = new int[row+2][col+2];
b=bon;
this.remove(p2);
timer.stop();
b1.setText("40");
b2.setText("0");
b3.setText("");
btns=new JButton[row*col];

p2=new JPanel();
p2.setLayout(new GridLayout(row,col,0,0));
for(int i=0;i<row*col;i++){
btns[i]=new JButton(" ");
btns[i].setMargin(new Insets(0,0,0,0));
btns[i].setFont(new Font(null,Font.BOLD,25));
btns[i].addActionListener(this);
btns[i].addMouseListener(new NormoreMouseEvent());
p2.add(btns[i]);
}
contentPane.add(p2,BorderLayout.CENTER);
this.pack();
//setSize(33*col,33*row+80);
for(int i=0;i<row*col;i++){
btns[i].setText("");
btns[i].setEnabled(true);
}
for(int i=0;i<row+2;i++){
for(int j=0;j<col+2;j++){
a[i][j]=0;
}
}
}else if(e.getActionCommand()=="高级"){
row=16;
col=32;
bon=99;
setSize(33*col,33*row+80);
a1=new int[bon];
a = new int[row+2][col+2];
b=bon;
this.remove(p2);
timer.stop();
b1.setText("99");
b2.setText("0");
b3.setText("");
btns=new JButton[row*col];
p2=new JPanel();
p2.setLayout(new GridLayout(row,col,0,0));
for(int i=0;i<row*col;i++){
btns[i]=new JButton(" ");
btns[i].setMargin(new Insets(0,0,0,0));
btns[i].setFont(new Font(null,Font.BOLD,25));
btns[i].addActionListener(this);
btns[i].addMouseListener(new NormoreMouseEvent());
p2.add(btns[i]);
}
contentPane.add(p2,BorderLayout.CENTER);
//setSize(33*col,33*row+80);
this.pack();
for(int i=0;i<row*col;i++){
btns[i].setText("");
btns[i].setEnabled(true);
}
for(int i=0;i<row+2;i++){
for(int j=0;j<col+2;j++){
a[i][j]=0;
}
}

}
if(e.getSource()==btn){
timer.start();
b=bon;
b3.setText("");
//System.out.println(bon);
//清空
for(int i=0;i<row*col;i++){
btns[i].setText("");
btns[i].setEnabled(true);
}
for(int i=0;i<row+2;i++){
for(int j=0;j<col+2;j++){
a[i][j]=0;
}
}
//产生随机数
for(int i=0;i<bon;i++)
{ int p=1;
int m=(int)(Math.random()*row*col);
while(p==1){
int l=1;
int j;
for( j=0;j<i&&l==1;j++){

if(a1[j]==m){
m=(int)(Math.random()*row*col);
l=0;
}
}
if(j==i){
a1[i]=m;
p=0;
}
}
}
b1.setText(bon+"");
b2.setText("0");
//布雷
for(int i=0;i<bon;i++){
int x=(a1[i]/col+1);
int y=(a1[i]%col+1);
a[x][y]=100;
}
for(int i=0;i<row+2;i++){
for(int j=0;j<col+2;j++){
if(i==0||j==0||i==row+1||j==col+1){
a[i][j]=0;
}
}
}
for(int i=1;i<=row;i++){
for(int j=1;j<=col;j++){
if(a[i][j]!=100){
for(int l=j-1;l<=j+1;l++){
if(a[i-1][l]==100){
a[i][j]++;
}
if(a[i+1][l]==100){
a[i][j]++;
}
}
if(a[i][j-1]==100){
a[i][j]++;
}
if(a[i][j+1]==100){
a[i][j]++;
}
}
}
}
}
if(e.getSource()==timer)
{
String time=b2.getText().trim();

int t=Integer.parseInt(time);
//System.out.println(t);
if(t>=600){
timer.stop();
}else{

t++;
b2.setText(t+"");
}
}
for(int i=0;i<col*row;i++){
if(btns[i].getText()!="★")
{
int x=i/col+1;
int y=i%col+1;
if(e.getSource()==btns[i]&&a[x][y]==100){
btns[i].setText("★");
btns[i].setEnabled(false);
a[x][y]=10;
for(int k=0;k<col*row;k++){
int m1=k/col+1;
int n1=k%col+1;
if(a[m1][n1]!=10&&btns[k].getText()=="★"){
btns[k].setText("*o*");
}
}
for(int j=0;j<col*row;j++){
int m=j/col+1;
int n=j%col+1;
if(a[m][n]==100){
btns[j].setText("★");
btns[j].setEnabled(false);
b3.setText("你输了 !!");
}
btns[j].setEnabled(false);
a[m][n]=10;
}
timer.stop();
}
else if(e.getSource()==btns[i]){
if(a[x][y]==0){
out(a,btns,e,i,x,y);
a[x][y]=10;
btns[i].setEnabled(false);
}
if(a[x][y]!=0&&a[x][y]!=10){
btns[i].setText(a[x][y]+"");
btns[i].setEnabled(false);
a[x][y]=10;
}
}
}else if(btns[i].getText()=="★"){
}
}
}
class NormoreMouseEvent extends MouseAdapter{
public void mouseClicked(MouseEvent e) {
System.out.println(b);
for(int i=0;i<col*row;i++){
int x1=i/col+1;
int y1=i%col+1;
if(e.getSource()==btns[i]&&btns[i].getText()!="★"&&a[x1][y1]!=10)
{
if(e.getButton()==MouseEvent.BUTTON3){
btns[i].setText("★");
b--;
if(b==0){
int flag=0;
for(int j=0;j<col*row;j++){
int x=j/col+1;
int y=j%col+1;
if(a[x][y]==100&&btns[j].getText()=="★"){
flag++;
}
}
if(flag==bon){
timer.stop();
b3.setText("你赢了!");
}
}
b1.setText(b+"");
}
}else if(e.getSource()==btns[i]&&btns[i].getText()=="★"&&a[x1][y1]!=-1){
if(e.getButton()==MouseEvent.BUTTON3){
btns[i].setText("");
b++;
if(b>bon){
b1.setText(bon+"");
}
else{
b1.setText(b+"");
}
btns[i].setEnabled(true);
}
}
}
}
}
}

③ 急求C语言扫雷源代码

有比较简单的扫雷游戏,但没有计时计分功能

④ 求助Java扫雷源码注释

import java.awt.*;
import java.util.*;
import java.io.*;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.event.*;
import javax.swing.border.*;
/**
* <p>Title:扫雷</p>
*
* <p>Description:学JAVA以来做的第一个游戏,程序中可能还有些BUG,希望大家提出来供一起探讨,
* 如果要测试记录文件,可以把雷的数量改的少一点,
* arithmetic中的while(landmintTally<99), button_mouseClicked中的
* if((landmineNum-1)==0),有3处,表示还剩的雷数.completeGame中的
* for (int i=0; i<99; i++)</p>
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: private </p>
*
* @author cqp
* @version demo
*/
public class shaolei extends JFrame {

/**类的属性和控件实例化*/
ImageIcon ButtonIcon; //按钮的图片;
HashMap map = new HashMap(); //雷和数字的状态,键为位置(0-479),值为状态,0-6为数字,7为雷;
HashMap flag_landmine = new HashMap(); //按钮上打的标记,如问号,对勾和取消,8为标记雷,9为问号,10为默认值空;
JMenuBar file = new JMenuBar(); //菜单栏;
JMenu game = new JMenu(); //菜单按钮;
JMenuItem start = new JMenuItem(); //菜单项;
JMenuItem record = new JMenuItem(); //菜单项;
JMenuItem quit = new JMenuItem(); //菜单项;
JMenuItem clearReocrd = new JMenuItem();//菜单项;
JMenu help = new JMenu(); //菜单按钮;
JButton[] cardsBtn = new JButton[480]; //480个按钮;
JButton beginBtn = new JButton(); //开始按钮;
JPanel pane = new JPanel(); //雷区面板;
JPanel paneTime = new JPanel(); //记数器所在的面板;
JOptionPane saveRecord = new JOptionPane(); //保存记录对话框;
JTextField landmineTally = new JTextField("99");//所剩雷的计数器;
JTextField timeTally = new JTextField("0"); //时间计数器;
GridLayout gridLayout1 = new GridLayout(); //网格布局;
Timer timer; //线程设施;
String[] landmine = new String[99]; //存放雷的位置,用来判断雷的位置是否重复;
slFrame_button_actionAdatper[] buttonClick =new slFrame_button_actionAdatper[480];//雷区按钮的事件类;
int mouseKey=0; //得到鼠标先按下的哪个键,用来判断鼠标是否同时按下了左右键;
int timeCount = 0; //时间计数器;

/**构造方法*/
public shaolei() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}

/**界面设置*/
private void jbInit() throws Exception {
getContentPane().setLayout(null);
this.setJMenuBar(file);
game.setText("游戏");
start.setText("开局");
start.addActionListener(new slFrame_start_actionAdapter(this));
record.setText("排行榜");
record.addActionListener(new slFrame_record_actionAdapter(this));
quit.setText("退出");
quit.addActionListener(new slFrame_quit_actionAdapter(this));
help.setText("帮助");
clearReocrd.setText("清除记录");
clearReocrd.addActionListener(new slFrame_clearReocrd_actionAdapter(this));
landmineTally.setBounds(new Rectangle(5, 5, 40, 25));
landmineTally.setBackground(new Color(0,0,0));
landmineTally.setForeground(new Color(255,0,0));
landmineTally.setFont(new java.awt.Font("Times New Roman", Font.BOLD, 20));
landmineTally.setBorder(BorderFactory.createBevelBorder(1));
landmineTally.setEditable(false);
timeTally.setBounds(new Rectangle(520, 5, 50, 25));
timeTally.setBackground(new Color(0,0,0));
timeTally.setForeground(new Color(255,0,0));
timeTally.setHorizontalAlignment(4);
timeTally.setFont(new java.awt.Font("Times New Roman", Font.BOLD, 20));
timeTally.setBorder(BorderFactory.createBevelBorder(0));
timeTally.setEditable(false);
beginBtn.setBounds(new Rectangle(250, 5, 25, 25));
beginBtn.setBorder(BorderFactory.createBevelBorder(0));
beginBtn.addActionListener(new slFrame_beginBtn_actionAdatper(this));
beginBtn.setIcon(createImageIcon("images/laugh.jpg"));
paneTime.setBounds(new Rectangle(0, 0, 585, 35));
paneTime.setBorder(BorderFactory.createEtchedBorder());
paneTime.setLayout(null);
paneTime.add(landmineTally);
paneTime.add(timeTally);
paneTime.add(beginBtn);
pane.setBounds(new Rectangle(0, 35, 590, 320));
pane.setLayout(gridLayout1);
gridLayout1.setColumns(30);
gridLayout1.setRows(16);
file.add(game);
file.add(help);
game.add(start);
game.add(record);
game.add(quit);
help.add(clearReocrd);
this.getContentPane().add(pane);
this.getContentPane().add(paneTime);

ActionListener listener = new ActionListener(){ //自定义线程
public void actionPerformed(ActionEvent e){
timeCount++;
timeTally.setText(Integer.toString(timeCount));
}
};
timer = new Timer(1000, listener); //增加线程,并每1秒执行一次;

for (int i=0;i<480;i++) //实例化480个小按钮加到面板pane中
{
cardsBtn[i] = new JButton();
cardsBtn[i].setText(""); //按钮上的文字去掉;
cardsBtn[i].setBorder(null); //按钮的边框去掉;
pane.add(cardsBtn[i]);
}
}

/**主方法*/
public static void main(String[] args) {
shaolei frame = new shaolei();
frame.setSize(580,410);
frame.setTitle("扫雷");
frame.show();
frame.setResizable(false); //不能修改窗体大小
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //点关闭按钮时直
}

/**自定义方法,用来给按钮增加图片*/
protected static ImageIcon createImageIcon(String path){
java.net.URL imgURL = shaolei.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}

/**菜单按钮的事件,开始游戏*/
public void start_actionPerformed(ActionEvent e) {
start(); //初始化;
arithmetic(); //计算雷的位置;
calculate(); //计算雷的分布情况;
timer.start(); //时间线程开始;
}

/**开始游戏按钮的事件*/
public void beginBtn_mouseClicked(ActionEvent e){
start_actionPerformed(e); //直接调用菜单的事件;
}

/**自定义方法,游戏从这里开始,方法里对按钮的属性和状态进行初始化;*/
void start(){
timeCount=0; //时间从0开始;
landmineTally.setText("99");//所剩雷数为99;
for (int i = 0; i<480; i++){
cardsBtn[i].setIcon(null); //清除按钮上的图片;
map.put( Integer.toString(i),Integer.toString(10)); //分布状态全为10,表示为空;
flag_landmine.put( Integer.toString(i),Integer.toString(10)); //标记状态全为10;
cardsBtn[i].removeMouseListener(buttonClick[i]); //去除雷区所有按钮的鼠标事件;
}
}

/**自定义方法,用来计算雷的分布位置*/
void arithmetic(){
Calendar time = Calendar.getInstance(); //日历类,得到当前时间;
int leed = time.get(Calendar.SECOND); //得到当前时间的秒;
Random rand = new Random(leed); //把秒数当个随机数的种子;
int tempRand; //临时随机数;
int landmintTally=0; //得到多少雷的计数器;
boolean flag=false; //标记是否重复;
int tempNum;
while(landmintTally < 99){ //最多只能有99颗雷;
tempRand = (int)(rand.nextFloat()*480); //得随机数;
tempNum = Integer.parseInt(map.get(Integer.toString(tempRand)).toString());
if (tempNum == 7) continue; //如果重复执行一个数字;
landmine[landmintTally] = Integer.toString(tempRand); //把得到的位置放进字符串;
map.put(Integer.toString(tempRand),Integer.toString(7)); //把得到的位置放到map集合里,值为7,表示有雷;
landmintTally++; //计数器加1;
}
}

/**计算雷的分部情况,指一个按钮周围有多少雷;*/
void calculate()
{
int num; //按钮的状态;
int sum=0; //计数器,计算周围有几颗雷;
int leftUp, up, rightUp, left, right, leftDown, down, rightDown; //定义了8个位置
for (int i = 0; i<480; i++)
{
leftUp = i-31;
up = i-30;
rightUp = i-29;
left = i-1;
right = i+1;
leftDown = i+29;
down = i+30;
rightDown= i+31;
cardsBtn[i].setBorder(BorderFactory.createBevelBorder(0)); //设置按钮的边框样式;
buttonClick[i] = new slFrame_button_actionAdatper(this,i); //实例化事件类;
cardsBtn[i].addMouseListener(buttonClick[i]); //给当前按钮添加鼠标事件;
num = Integer.parseInt(map.get(Integer.toString(i)).toString());//得到当前按钮的状态;
if (num == 7){
continue; //如果这个按钮的状态为雷,跳到下个按钮;
}

if (i == 0) { //左上角第一颗雷;
num = Integer.parseInt(map.get(Integer.toString(i)).toString());
if ( Integer.parseInt(map.get(Integer.toString(right)).toString()) == 7 ) sum++; //如果是雷计数器加1;
if ( Integer.parseInt(map.get(Integer.toString(down)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(rightDown)).toString()) == 7 ) sum++;
map.put(Integer.toString(0),Integer.toString(sum)); //把得到的数字放到当前的位置;
sum=0; //计数器清零;
continue; //下个按钮;
}else if (i == 29) { //右上角第一颗雷;
if ( Integer.parseInt(map.get(Integer.toString(left)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(leftDown)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(down)).toString()) == 7 ) sum++;
map.put(Integer.toString(i),Integer.toString(sum));
sum=0;
continue;
}else if (i == 450) { //左下角第一颗雷;
if ( Integer.parseInt(map.get(Integer.toString(right)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(up)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(rightUp)).toString()) == 7 ) sum++;
map.put(Integer.toString(i),Integer.toString(sum));
sum=0;
continue;
}else if (i == 479) { //右下角第一颗雷;
if ( Integer.parseInt(map.get(Integer.toString(left)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(leftUp)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(up)).toString()) == 7 ) sum++;
map.put(Integer.toString(i),Integer.toString(sum));
sum=0;
return;
}else if (i<29){ //第一行;
if ( Integer.parseInt(map.get(Integer.toString(left)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(leftDown)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(down)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(right)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(rightDown)).toString()) == 7 ) sum++;
map.put(Integer.toString(i),Integer.toString(sum));
sum=0;
continue;
}else if (i>450){ //最后一行;
if ( Integer.parseInt(map.get(Integer.toString(leftUp)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(up)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(rightUp)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(left)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(right)).toString()) == 7 ) sum++;
map.put(Integer.toString(i),Integer.toString(sum));
sum=0;
continue;
}else if ( (i%30) == 0 ){ //第一列;
if ( Integer.parseInt(map.get(Integer.toString(up)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(rightUp)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(right)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(down)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(rightDown)).toString()) == 7 ) sum++;
map.put(Integer.toString(i),Integer.toString(sum));
sum=0;
continue;
}else if ( ((i+1)%30) == 0 ){ //最后一列;
if ( Integer.parseInt(map.get(Integer.toString(leftUp)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(up)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(left)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(leftDown)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(down)).toString()) == 7 ) sum++;
map.put(Integer.toString(i),Integer.toString(sum));
sum=0;
continue;
}else{ //除去四周剩下的;
if ( Integer.parseInt(map.get(Integer.toString(leftUp)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(up)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(rightUp)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(left)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(right)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(leftDown)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(down)).toString()) == 7 ) sum++;
if ( Integer.parseInt(map.get(Integer.toString(rightDown)).toString()) == 7 ) sum++;
map.put(Integer.toString(i),Integer.toString(sum));
sum=0;
continue;
}
}
}

/**鼠标点击事件,参数i为点击按钮的位置 */
public void button_mouseClicked(MouseEvent e,int i){
int mKey = e.getButton(); //点击的哪个键;
int landmineNum = Integer.parseInt(landmineTally.getText().toString()); //所剩的雷数;
int num = Integer.parseInt(map.get(Integer.toString(i)).toString()); //当前按钮的状态;
int flag = Integer.parseInt(flag_landmine.get(Integer.toString(i)).toString());//当前按钮的标记状态;

if ( (mKey == 3) && ( cardsBtn[i].getBorder()!= null)){ //点击为鼠标右键,并且边框不为空(空的表示已按亮开的);
if (flag == 10){ //如果没有标记,则改为标记状态;
flag_landmine.put(Integer.toString(i),Integer.toString(8));
ButtonIcon = createImageIcon("images/8.jpg");
cardsBtn[i].setIcon(ButtonIcon);
landmineTally.setText( Integer.toString(landmineNum - 1) );
if ( (landmineNum-1) == 0) //如果标记的雷数为99;
completeGame(); //完成游戏;
}else if (flag == 8){ //如果为标记状态,则改为问号;
flag_landmine.put(Integer.toString(i),Integer.toString(9));
ButtonIcon = createImageIcon("images/9.jpg");
cardsBtn[i].setIcon(ButtonIcon);
landmineTally.setText( Integer.toString(landmineNum + 1) );
if ( (landmineNum+1) == 0) //如果标记的雷数为99;
completeGame(); //完成游戏;
}else if (flag == 9){ //如果为问号,则取消标记;
flag_landmine.put(Integer.toString(i),Integer.toString(10));
cardsBtn[i].setIcon(null);
}
}else if (mKey == 1){ //如果点击为鼠标左键;
flag_landmine.put(Integer.toString(i),Integer.toString(10)); //先清除所点击按钮的标记状态;
if ( (landmineNum+1) == 0) //如果标记的雷数为99;
completeGame(); //完成游戏;
if (num == 7){ //如果铵钮的状态为雷,则结束游戏;
overGame(i);
}else if (num == 0){ //如果雷数为空
if ( flag == 8 ){ //如果已经标记为雷,计数器加1;
landmineTally.setText( Integer.toString(landmineNum + 1) );
}
ButtonIcon = createImageIcon("images/0.jpg");
cardsBtn[i].setIcon(ButtonIcon);
cardsBtn[i].setBorder(null);
display(i); //亮开周围的按钮;
}else { //数字为1-6之间,亮开按钮,并显示数字所对应的图片;
if ( flag == 8 ){ //如果已经标记为雷,计数器加1;
landmineTally.setText( Integer.toString(landmineNum + 1) );
}
ButtonIcon = createImageIcon("images/"+num+".jpg");
cardsBtn[i].setIcon(ButtonIcon);
cardsBtn[i].setBorder(null);
}
}
if ( (mouseKey==1 && mKey == 3) || (mouseKey==3 && mKey == 1) ){ //鼠标左右键同时点按下;
open(i); //亮开周围的按钮(先判断);

}
mouseKey = 0;
}

/**自定义方法,用来判断是否要亮开周围的按钮*/
void open(int i){
int landmineAmount = 0; //实际的雷数;
int flagAmount=0; //标记的雷数;
int landmine_leftUp=0, landmine_up=0, landmine_rightUp=0, landmine_left=0, landmine_right=0,
landmine_leftDown=0, landmine_down=0, landmine_rightDown=0; //定义了实际雷的8个位置
int flag_leftUp=0, flag_up=0, flag_rightUp=0, flag_left=0, flag_right=0,
flag_leftDown=0, flag_down=0, flag_rightDown=0; //定义了标记雷的8个位置

//实际雷所在的8个位置和标记雷的8个位置,如果不加判断则hashMap集合会越界;
if (i > 31) landmine_leftUp = Integer.parseInt(map.get(Integer.toString(i-31)).toString());
if (i > 30) landmine_up = Integer.parseInt(map.get(Integer.toString(i-30)).toString());
if (i > 29) landmine_rightUp = Integer.parseInt(map.get(Integer.toString(i-29)).toString());
if (i > 1) landmine_left = Integer.parseInt(map.get(Integer.toString(i-1)).toString());
if (i < 479) landmine_right = Integer.parseInt(map.get(Integer.toString(i+1)).toString());
if (i < 450) landmine_leftDown = Integer.parseInt(map.get(Integer.toString(i+29)).toString());
if (i < 449) landmine_down = Integer.parseInt(map.get(Integer.toString(i+30)).toString());
if (i < 448) landmine_rightDown = Integer.parseInt(map.get(Integer.toString(i+31)).toString());

if (i > 31) flag_leftUp = Integer.parseInt(flag_landmine.get(Integer.toString(i-31)).toString());
if (i > 30) flag_up = Integer.parseInt(flag_landmine.get(Integer.toString(i-30)).toString());
if (i > 29) flag_rightUp = Integer.parseInt(flag_landmine.get(Integer.toString(i-29)).toString());
if (i > 1) flag_left = Integer.parseInt(flag_landmine.get(Integer.toString(i-1)).toString());
if (i < 479) flag_right = Integer.parseInt(flag_landmine.get
太长了写不完,我把压缩包发给你吧,49905518注意查收

⑤ C语言扫雷源代码 不用鼠标 操作 急求!!!

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <conio.h>
#include <windows.h>

#define N 3

struct mine_box {
char type; // '*'代表地雷,n代表周围有地雷的地雷数(n=0-8)
char bMarked; // 是否被标记
char bOpened; // 是否被打开
} mine_array[N][N];

int CurrentRow, CurrentCol; // 记录当前光标的位置
int openedBlank = 0; // 记录被掀开的格子数

/*将光标定位到屏幕上的某个指定位置的坐标上*/

void gotoxy(int x,int y)
{ CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
HANDLE hConsoleOut;
hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsoleOut,&csbiInfo);
csbiInfo.dwCursorPosition.X = x;
csbiInfo.dwCursorPosition.Y = y;
SetConsoleCursorPosition(hConsoleOut,csbiInfo.dwCursorPosition);
}

// 显示一个格子的内容
void printBox(struct mine_box mb)
{
// 格子没被掀开也没做标记
if(mb.bOpened == 0 && mb.bMarked == 0)
printf("□");
// 格子被标记一次
else if(mb.bMarked == 1)
printf("√");
// 格子被标记两次
else if(mb.bMarked == 2)
printf("?");
// 格子被掀开,显示格子中的内容
else
switch(mb.type) {
// 格子中有地雷
case '*':
printf("⊕");
break;
// 格子没有地雷并且四周也没有地雷
case 0:
printf("");
break;
case 1:
printf("1");
break;
case 2:
printf("2");
break;
case 3:
printf("3");
break;
case 4:
printf("4");
break;
case 5:
printf("5");
break;
case 6:
printf("6");
break;
case 7:
printf("7");
break;
case 8:
printf("8");
break;
}
}

// 将光标移动到第row行第col列的格子上
void MoveTo(int row, int col)
{
CurrentRow = row;
CurrentCol = col;
gotoxy(CurrentCol*4+2,CurrentRow*2+1);
}

// 刷新屏幕
void refreshScreen(int state)
{
int i, j;
gotoxy(0, 0);
printf("┏━");
for(i = 1; i < N; i++)
printf("┳━");
printf("┓\n");
for(i = 0; i < N; i++) {
printf("┃");
for(j = 0; j < N; j++) {
if(state == -1 && mine_array[i][j].bMarked == 1 && mine_array[i][j].type != '*') {
printf("¤"); // 标记错了地雷
continue;
}
if(state != 0) { // 游戏结束,将所有的盒子掀开显示其中内容
mine_array[i][j].bOpened = 1;
mine_array[i][j].bMarked = 0;
}
printBox(mine_array[i][j]);
printf("┃");
}
if(i < N-1) {
printf("\n┣");
for(j = 1; j < N; j++) {
printf("━╋");
}
printf("━┫\n");
}
else {
printf("\n┗");
for(j = 1; j < N; j++) {
printf("━┻");
}
printf("━┛\n");
}
}
printf("按键指南:A左移,D右移,W上移,S下移,X翻开,C标记,Q退出\n");
}

void MoveUp()
{
if(CurrentRow > 0) {
CurrentRow --;
MoveTo(CurrentRow, CurrentCol);
}
}

void MoveDown()
{
if(CurrentRow < N-1) {
CurrentRow ++;
MoveTo(CurrentRow, CurrentCol);;
}
}

void MoveLeft()
{
if(CurrentCol > 0) {
CurrentCol --;
MoveTo(CurrentRow, CurrentCol);
}
}

void MoveRight()
{
if(CurrentCol < N-1) {
CurrentCol ++;
MoveTo(CurrentRow, CurrentCol);
}
}

int openMine()
{
int saveRow = CurrentRow, saveCol = CurrentCol;
if(mine_array[CurrentRow][CurrentCol].bOpened)
return 0;

mine_array[CurrentRow][CurrentCol].bOpened = 1;
mine_array[CurrentRow][CurrentCol].bMarked = 0;
if(mine_array[CurrentRow][CurrentCol].type == '*') {
refreshScreen(-1);
MoveTo(N+1, 0);
printf("失败!游戏结束)\n");
exit(2);
}
printBox(mine_array[CurrentRow][CurrentCol]);
MoveTo(CurrentRow, CurrentCol);
// 进一步要做的是当掀开一个type=0的空格子时,将其周围没有地雷的空格子自动掀开
return 1;
}

void markMine()
{
if(mine_array[CurrentRow][CurrentCol].bOpened == 1)
return;
if(mine_array[CurrentRow][CurrentCol].bMarked == 0)
mine_array[CurrentRow][CurrentCol].bMarked = 1;
else if(mine_array[CurrentRow][CurrentCol].bMarked == 1)
mine_array[CurrentRow][CurrentCol].bMarked = 2;
else if(mine_array[CurrentRow][CurrentCol].bMarked ==2)
mine_array[CurrentRow][CurrentCol].bMarked = 0;
printBox(mine_array[CurrentRow][CurrentCol]);
MoveTo(CurrentRow, CurrentCol);
}

main()
{
int num, i, j, row, col, count;
printf("输入地雷数: ");
scanf("%u", &num);

if(num > N*N) {
printf("地雷数超限\n");
return -1;
}

memset((void*)mine_array, 0, N*N*sizeof(struct mine_box));
//随机设置num个地雷的位置
srand((unsigned)time(NULL));
for(i=0; i<num; i++) {
row = rand()%N;
col = rand()%N;
if(mine_array[row][col].type == 0)
mine_array[row][col].type = '*';
else // 已经有雷了,重新取下一个格子
i--;
}
// 计算每个非雷格子周围的地雷数
for(row=0; row<N; row++)
{
for(col = 0; col < N; col++) {
if(mine_array[row][col].type == '*') {
for(i = row-1; i <= row+1; i++) {
for(j = col-1; j <= col+1; j++) {
if(i >= 0 && j >= 0 && i < N && j < N && mine_array[i][j].type != '*')
mine_array[i][j].type ++;
}
}
}
}
}

refreshScreen(0);
MoveTo(N/2, N/2); // 将光标移到中央的位置
do {
switch(getch()) {
case 'a':
case 'A':
MoveLeft();
break;
case 's':
case 'S':
MoveDown();
break;
case 'd':
case 'D':
MoveRight();
break;
case 'w':
case 'W':
MoveUp();
break;
case 'x':
case 'X':
if(openMine() == 1) {
if(++openedBlank == N*N-num) { //所有的空格都被掀开
refreshScreen(1);
MoveTo(N+1, 0);
printf("成功!游戏结束。\n");
exit(0);
}
}
break;
case 'c':
case 'C':
markMine();
break;
case 'q':
case 'Q':
MoveTo(N+1, 0);
printf("是否退出?(y/n)");
if(getch() == 'y')
return 0;
}
} while(1);
}

⑥ 求C#编写的扫雷游戏源代码包(用VS2005编写的!!),

网上好像有

⑦ C++扫雷源代码

这是字符界面的扫雷:

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <windows.h>
#include <conio.h>

// defines
#define KEY_UP 0xE048
#define KEY_DOWN 0xE050
#define KEY_LEFT 0xE04B
#define KEY_RIGHT 0xE04D
#define KEY_ESC 0x001B
#define KEY_1 '1'
#define KEY_2 '2'
#define KEY_3 '3'
#define GAME_MAX_WIDTH 100
#define GAME_MAX_HEIGHT 100

// Strings Resource
#define STR_GAMETITLE "ArrowKey:MoveCursor Key1:Open \
Key2:Mark Key3:OpenNeighbors"
#define STR_GAMEWIN "Congratulations! You Win! Thank you for playing!\n"
#define STR_GAMEOVER "Game Over, thank you for playing!\n"
#define STR_GAMEEND "Presented by yzfy . Press ESC to exit\n"

//-------------------------------------------------------------
// Base class
class CConsoleWnd
{
public:
static int TextOut(const char*);
static int GotoXY(int, int);
static int CharOut(int, int, const int);
static int TextOut(int, int, const char*);
static int GetKey();
public:
};

//{{// class CConsoleWnd
//
// int CConsoleWnd::GetKey()
// Wait for standard input and return the KeyCode
//
int CConsoleWnd::GetKey()
{
int nkey=getch(),nk=0;
if(nkey>=128||nkey==0)nk=getch();
return nk>0?nkey*256+nk:nkey;
}

//
// int CConsoleWnd::GotoXY(int x, int y)
// Move cursor to (x,y)
// Only Console Application
//
int CConsoleWnd::GotoXY(int x, int y)
{
COORD cd;
cd.X = x;cd.Y = y;
return SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),cd);
}

//
// int CConsoleWnd::TextOut(const char* pstr)
// Output a string at current position
//
int CConsoleWnd::TextOut(const char* pstr)
{
for(;*pstr;++pstr)putchar(*pstr);
return 0;
}

//
// int CConsoleWnd::CharOut(int x, int y, const int pstr)
// Output a char at (x,y)
//
int CConsoleWnd::CharOut(int x, int y, const int pstr)
{
GotoXY(x, y);
return putchar(pstr);
}

//
// int CConsoleWnd::TextOut(const char* pstr)
// Output a string at (x,y)
//
int CConsoleWnd::TextOut(int x, int y, const char* pstr)
{
GotoXY(x, y);
return TextOut(pstr);
}
//}}

//-------------------------------------------------------------
//Application class
class CSLGame:public CConsoleWnd
{
private:
private:
int curX,curY;
int poolWidth,poolHeight;
int bm_gamepool[GAME_MAX_HEIGHT+2][GAME_MAX_WIDTH+2];
public:
CSLGame():curX(0),curY(0){poolWidth=poolHeight=0;}
int InitPool(int, int, int);
int MoveCursor(){return CConsoleWnd::GotoXY(curX, curY);}
int DrawPool(int);
int WaitMessage();
int GetShowNum(int, int);
int TryOpen(int, int);
private:
int DFSShowNum(int, int);
private:
const static int GMARK_BOOM;
const static int GMARK_EMPTY;
const static int GMARK_MARK;
};
const int CSLGame::GMARK_BOOM = 0x10;
const int CSLGame::GMARK_EMPTY= 0x100;
const int CSLGame::GMARK_MARK = 0x200;

//{{// class CSLGame:public CConsoleWnd
//
// int CSLGame::InitPool(int Width, int Height, int nBoom)
// Initialize the game pool.
// If Width*Height <= nBoom, or nBoom<=0,
// or Width and Height exceed limit , then return 1
// otherwise return 0
//
int CSLGame::InitPool(int Width, int Height, int nBoom)
{
poolWidth = Width; poolHeight = Height;
if(nBoom<=0 || nBoom>=Width*Height
|| Width <=0 || Width >GAME_MAX_WIDTH
|| Height<=0 || Height>GAME_MAX_HEIGHT
){
return 1;
}
// zero memory
for(int y=0; y<=Height+1; ++y)
{
for(int x=0; x<=Width+1; ++x)
{
bm_gamepool[y][x]=0;
}
}
// init seed
srand(time(NULL));
// init Booms
while(nBoom)
{
int x = rand()%Width + 1, y = rand()%Height + 1;
if(bm_gamepool[y][x]==0)
{
bm_gamepool[y][x] = GMARK_BOOM;
--nBoom;
}
}
// init cursor position
curX = curY = 1;
MoveCursor();
return 0;
}

//
// int CSLGame::DrawPool(int bDrawBoom = 0)
// Draw game pool to Console window
//
int CSLGame::DrawPool(int bDrawBoom = 0)
{
for(int y=1;y<=poolHeight;++y)
{
CConsoleWnd::GotoXY(1, y);
for(int x=1;x<=poolWidth;++x)
{
if(bm_gamepool[y][x]==0)
{
putchar('.');
}
else if(bm_gamepool[y][x]==GMARK_EMPTY)
{
putchar(' ');
}
else if(bm_gamepool[y][x]>0 && bm_gamepool[y][x]<=8)
{
putchar('0'+bm_gamepool[y][x]);
}
else if(bDrawBoom==0 && (bm_gamepool[y][x] & GMARK_MARK))
{
putchar('#');
}
else if(bm_gamepool[y][x] & GMARK_BOOM)
{
if(bDrawBoom)
putchar('*');
else
putchar('.');
}
}
}
return 0;
}

//
// int CSLGame::GetShowNum(int x, int y)
// return ShowNum at (x, y)
//
int CSLGame::GetShowNum(int x, int y)
{
int nCount = 0;
for(int Y=-1;Y<=1;++Y)
for(int X=-1;X<=1;++X)
{
if(bm_gamepool[y+Y][x+X] & GMARK_BOOM)++nCount;
}
return nCount;
}

//
// int CSLGame::TryOpen(int x, int y)
// Try open (x, y) and show the number
// If there is a boom, then return EOF
//
int CSLGame::TryOpen(int x, int y)
{
int nRT = 0;
if(bm_gamepool[y][x] & GMARK_BOOM)
{
nRT = EOF;
}
else
{
int nCount = GetShowNum(x,y);
if(nCount==0)
{
DFSShowNum(x, y);
}
else bm_gamepool[y][x] = nCount;
}
return nRT;
}

//
// int CSLGame::DFSShowNum(int x, int y)
// Private function, no comment
//
int CSLGame::DFSShowNum(int x, int y)
{
if((0<x && x<=poolWidth) &&
(0<y && y<=poolHeight) &&
(bm_gamepool[y][x]==0))
{
int nCount = GetShowNum(x, y);
if(nCount==0)
{
bm_gamepool[y][x] = GMARK_EMPTY;
for(int Y=-1;Y<=1;++Y)
for(int X=-1;X<=1;++X)
{
DFSShowNum(x+X,y+Y);
}
}
else bm_gamepool[y][x] = nCount;
}
return 0;
}

//
// int CSLGame::WaitMessage()
// Game loop, wait and process an input message
// return: 0: not end; 1: Win; otherwise: Lose
//
int CSLGame::WaitMessage()
{
int nKey = CConsoleWnd::GetKey();
int nRT = 0, nArrow = 0;
switch (nKey)
{
case KEY_UP:
{
if(curY>1)--curY;
nArrow=1;
}break;
case KEY_DOWN:
{
if(curY<poolHeight)++curY;
nArrow=1;
}break;
case KEY_LEFT:
{
if(curX>1)--curX;
nArrow=1;
}break;
case KEY_RIGHT:
{
if(curX<poolWidth)++curX;
nArrow=1;
}break;
case KEY_1:
{
nRT = TryOpen(curX, curY);
}break;
case KEY_2:
{
if((bm_gamepool[curY][curX]
& ~(GMARK_MARK|GMARK_BOOM))==0)
{
bm_gamepool[curY][curX] ^= GMARK_MARK;
}
}break;
case KEY_3:
{
if(bm_gamepool[curY][curX] & 0xF)
{
int nb = bm_gamepool[curY][curX] & 0xF;
for(int y=-1;y<=1;++y)
for(int x=-1;x<=1;++x)
{
if(bm_gamepool[curY+y][curX+x] & GMARK_MARK)
--nb;
}
if(nb==0)
{
for(int y=-1;y<=1;++y)
for(int x=-1;x<=1;++x)
{
if((bm_gamepool[curY+y][curX+x]
& (0xF|GMARK_MARK)) == 0)
{
nRT |= TryOpen(curX+x, curY+y);
}
}
}
}
}break;
case KEY_ESC:
{
nRT = EOF;
}break;
}
if(nKey == KEY_1 || nKey == KEY_3)
{
int y=1;
for(;y<=poolHeight;++y)
{
int x=1;
for(;x<=poolWidth; ++x)
{
if(bm_gamepool[y][x]==0)break;
}
if(x<=poolWidth) break;
}
if(! (y<=poolHeight))
{
nRT = 1;
}
}
if(nArrow==0)
{
DrawPool();
}
MoveCursor();
return nRT;
}
//}}

//-------------------------------------------------------------
//{{
//
// main function
//
int main(void)
{
int x=50, y=20, b=100,n; // define width & height & n_booms
CSLGame slGame;
// Init Game
{
CConsoleWnd::GotoXY(0,0);
CConsoleWnd::TextOut(STR_GAMETITLE);
slGame.InitPool(x,y,b);
slGame.DrawPool();
slGame.MoveCursor();
}
while((n=slGame.WaitMessage())==0) // Game Message Loop
;
// End of the Game
{
slGame.DrawPool(1);
CConsoleWnd::TextOut("\n");
if(n==1)
{
CConsoleWnd::TextOut(STR_GAMEWIN);
}
else
{
CConsoleWnd::TextOut(STR_GAMEOVER);
}
CConsoleWnd::TextOut(STR_GAMEEND);
}
while(CConsoleWnd::GetKey()!=KEY_ESC)
;
return 0;
}
//}}

⑧ 悬赏100元钱。注释一个java扫雷游戏源代码,就是把每行的意思写到后面就可以了!在线等。

import java.awt.*;
import javax.swing.*;
import java.util.Random;
import java.awt.event.*;

class Min extends JPanel //雷的类
{
//备注:鼠标的左键 = 1;右键 = 3;中键 = 2
private int flag = 0,statu = 0; //定义雷的属性 0:没有打开 1:打开 2:标示为雷 3:不确定
//flag = 0 不是雷 ; flag = 1是雷
private int but,count = 0; //but:哪一个鼠标键被按下去了 count:这个区域周围有多少个雷
private int mx = 0,my = 0,mw = 10; //定义雷的坐标和宽度

public Min() //构造函数
{
statu = 0;
}
public Min(int f,int x,int y,int w)
//构造函数
{
flag = f;
mx = x;
my = y;
mw = w;
}
public int getFlag(){return flag;}
public int getStatu(){return statu;}
public int getMx(){return mx;}
public int getMy(){return my;}
public int getMw(){return mw;}
public int getCount(){return count;}
public void setFlag(int f){flag = f;}
public void setCount(int c){count = c;}
public void setData(int f,int x,int y,int w,int s)
//传递值
{
flag = f;
mx = (x-1)*w;
my = (y-1)*w;
mw = w-1;
statu = s;
}
//根据你点击鼠标的不同来改变雷的属性
public int sendKey(int key)
{
//返回值,如果游戏结束则返回-1
int rtn = 1;
if(key == 3)
{
switch(statu)
{
case 1:
break;
case 2:
statu = 3;
break;
case 3:
statu = 0;
break;
case 0:
statu = 2;
break;
}
rtn = 1;
}
if(key == 1 && statu == 0)
{
switch(flag)
{
case 0:
statu = 1;
rtn = 2;
break;
case 1:
statu = 1;
rtn = -1;
break;
}
}
return rtn;
}
}

class DrawPanel extends JPanel
{
private int i,j;
private int f = 0; //if f = 1 then game over ,if f =2 then win
private int chx = 0,chy = 0; //专门记录坐标x,y的值
private int msum = 6,ksum = 0; //msum:雷的个数,ksum:标示雷的个数
private int bx = 10,by = 10,bw = 40; //bx,by:棋盘的大小,bw:棋子的大小
public Min board[][] = {
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
};
// 画坐标为ax,ay区域的雷的状态
public void draw(Graphics g,int ax,int ay)
{
int x,y,w; // 坐标x,y;和宽度:w
int s,c,flag; //状态;雷的个数;
int cx = bw/2 - 4;
int cy = bw/2 + 4;
x = board[ax][ay].getMx();
y = board[ax][ay].getMy();
w = board[ax][ay].getMw();
s = board[ax][ay].getStatu();
c = board[ax][ay].getCount();
flag= board[ax][ay].getFlag();

switch(s)
{
case 0: //没有打开状态
{
g.setColor(Color.black);
g.fillRect(x,y,w,w);
break;
}
case 1: //打开状态
{
g.setColor(Color.blue);
g.fillRect(x,y,w,w);
if(c != 0 && flag == 0) //此处没有雷
{
g.setColor(Color.red);
g.drawString(String.valueOf(c),x + cx,y + cy);
}
if(flag == 1) //此处有雷
{
g.setColor(Color.red);
g.fillRect(x,y,w,w);
g.setColor(Color.blue);
g.drawString(" 雷",x + cx,y + cy);
}
break;
}
case 2: //标雷状态
{
g.setColor(Color.green);
g.fillRect(x,y,w,w);
g.setColor(Color.blue);
g.drawString(" 旗",x + cx,y + cy);
break;
}
case 3: //不确定状态
{
g.setColor(Color.black);
g.fillRect(x,y,w,w);
g.setColor(Color.red);
g.drawString("?",x + cx,y + cy);
break;
}
default:
break;
}
}
// 没有图形器的绘图函数:画出坐标ax,ay的雷的状态和图形
public void draw(int ax,int ay)
{
Graphics g;
g = this.getGraphics();
draw(g,ax,ay);
}

//打开周围没有雷的地方,并且绘画所在区域点击左键触发
public int openNoMin(int ax,int ay)
{
int i,j;

if(ax<1||ay<1||ax>bx||ay>by) return 0; //鼠标点击的区域出界了
if(board[ax][ay].getStatu() != 0) return 0; //如果此区域打开了,返回
board[ax][ay].sendKey(1); //如果返回值等于-1,就说明游戏结束
draw(ax,ay);
if(board[ax][ay].getFlag() == 1)
//如果游戏结束,把所有的雷都显示出来
{
for(i = 1;i<=bx;i++)
{
for(j = 1;j <= by;j++)
{
if(board[i][j].getFlag() == 1)
{
board[i][j].sendKey(1);
draw(i,j);
}
}
}
return -1;
}
//如果游戏没有结束
if(board[ax][ay].getCount() > 0)
{
ksum ++;
return 1; //周围有雷,就不用打开周围地区
}
if(board[ax][ay].getCount() == 0 && board[ax][ay].getFlag() == 0)
//周围没有雷,打开周围地区,直到有雷的地区
{
openNoMin(ax-1,ay-1);openNoMin(ax,ay-1);openNoMin(ax+1,ay-1);
openNoMin(ax-1,ay ); openNoMin(ax+1,ay );
openNoMin(ax-1,ay+1);openNoMin(ax,ay+1);openNoMin(ax+1,ay+1);
}
ksum ++;
return 1;
}

//计算坐标x,y的周围雷的个数
public int getCount(int ai,int aj)
{
int sum = 0;
if(board[ai][aj].getFlag() == 1)
{
return sum;
}

if(ai>1&&aj>1&&ai<bx&&aj<by)
{
sum = board[ai-1][aj-1].getFlag()+ board[ai][aj-1].getFlag()+ board[ai+1][aj-1].getFlag()+
board[ai-1][aj ].getFlag()+ board[ai+1][aj ].getFlag()+
board[ai-1][aj+1].getFlag()+ board[ai][aj+1].getFlag()+ board[ai+1][aj+1].getFlag();
}
if(ai==1&&aj==1)
{
sum = board[ai+1][aj ].getFlag()+
board[ai][aj+1].getFlag()+ board[ai+1][aj+1].getFlag();
}
if(ai==1&&aj==by)
{
sum = board[ai][aj-1].getFlag()+ board[ai+1][aj-1].getFlag()+
board[ai+1][aj ].getFlag();
}
if(ai==bx&&aj==1)
{
sum = board[ai-1][aj ].getFlag()+
board[ai-1][aj+1].getFlag()+ board[ai][aj+1].getFlag();
}
if(ai==bx&&aj==by)
{
sum = board[ai-1][aj-1].getFlag()+ board[ai][aj-1].getFlag()+
board[ai-1][aj ].getFlag();
}
if(ai==1&&aj>1&&aj<by)
{
sum = board[ai][aj-1].getFlag()+ board[ai+1][aj-1].getFlag()+
board[ai+1][aj ].getFlag()+
board[ai][aj+1].getFlag()+ board[ai+1][aj+1].getFlag();
}
if(ai==bx&&aj>1&&aj<by)
{
sum = board[ai-1][aj-1].getFlag()+ board[ai][aj-1].getFlag()+
board[ai-1][aj ].getFlag()+
board[ai-1][aj+1].getFlag()+ board[ai][aj+1].getFlag();
}
if(ai>1&&ai<bx&&aj==1)
{
sum = board[ai-1][aj ].getFlag()+ board[ai+1][aj ].getFlag()+
board[ai-1][aj+1].getFlag()+ board[ai][aj+1].getFlag()+ board[ai+1][aj+1].getFlag();
}
if(ai>1&&ai<bx&&aj==by)
{
sum = board[ai-1][aj-1].getFlag()+ board[ai][aj-1].getFlag()+ board[ai+1][aj-1].getFlag()+
board[ai-1][aj ].getFlag()+ board[ai+1][aj ].getFlag();
}
return sum;
}

// 传入参数:几列,几行,宽度,雷数
public void initMin(int ax,int ay,int aw,int as)
{
int k = 1; //表明产生的第几个雷
Random r; //随机数

f = 0; //f=0表示游戏还没有结束
ksum = 0;
bx = ax;
by = ay;
bw = aw;
msum = as;
r = new Random();
//初始化底盘的值
for(i = 1;i <= bx;i++)
{
for(j=1;j<=by;j++)
{
board[i][j].setData(0,i,j,bw,0);
}
}
// 随机产生雷
while(k <= msum)
{
i = r.nextInt(bx)+1;
j = r.nextInt(by)+1;
if(board[i][j].getFlag() != 1)
{
board[i][j].setFlag(1);
k++;
}
}
// 非雷区的周围有几个雷,初始化其值
for(i = 1;i <= bx;i++)
{
for(j=1;j<=by;j++)
{
board[i][j].setCount(getCount(i,j));
}
}

setBackground(Color.white);
repaint();
}
// 构造函数
public DrawPanel(int ax,int ay,int aw,int as)
{
initMin(ax,ay,aw,as);
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent me)
{
int r;
if(f != 0) return; //如果游戏结束,返回
chx = me.getX();
chy = me.getY();
if(me.getButton() != 1)
{
board[chx/bw+1][chy/bw+1].sendKey(me.getButton());
draw(chx/bw+1,chy/bw+1);
}
else if(me.getButton() == 1)
{
if(openNoMin(chx/bw+1,chy/bw+1) == -1)
{
f = 1;
repaint();
}
else if ( ksum + msum == bx*by )
{
f = 2;
repaint();
}
}
}
}
);
}
// 重画所有的图形,包括一些修饰的图形
public void paint(Graphics g)
{
int x,y,w;
int s;
int cx = bw/2 - 4;
int cy = bw/2 + 4;

g.clearRect(0,0,600,600);
for(i=1;i<=bx;i++)
{
for(j=1;j<=by;j++)
{
draw(g,i,j);
}
}
if(f == 1)
{
Font f = new Font("11",1,70);
Font fo = g.getFont();
g.setColor(Color.white);
g.setFont(f);
//g.setSize();
g.drawString("Game Over",0,200);
g.setFont(fo);
}
if( f == 2 )
{
Font f = new Font("11",1,70);
Font fo = g.getFont();
g.setColor(Color.white);
g.setFont(f);
//g.setSize();
g.drawString("You win!",0,200);
g.setFont(fo);
}
}

};
// 主类和程序的入口
public class Mine extends JFrame implements ActionListener
{
Container cp = getContentPane();
JButton bt = new JButton("开局");
Label l1 = new Label("列:");
Label l2 = new Label("行:");
Label l3 = new Label("宽度:");
Label l4 = new Label("雷的个数:");
TextField tf1 = new TextField("10",2); //列
TextField tf2 = new TextField("10",2); //行
TextField tf3 = new TextField("40",2); //宽度
TextField tf4 = new TextField("15",2); //雷的个数
int x=10,y=10,w=40,sum=15;
DrawPanel dp = new DrawPanel(x,y,w,sum);

public Mine()
{
setBackground(Color.white);
cp.setLayout(null);
cp.add(dp);
cp.add(bt);
cp.add(tf1);
cp.add(tf2);
cp.add(tf3);
cp.add(tf4);
cp.add(l1);
cp.add(l2);
cp.add(l3);
cp.add(l4);

l1.setBounds(20 ,10,20,20);
tf1.setBounds(40,10,20,20);
l2.setBounds(70,10,20,20);
tf2.setBounds(90,10,20,20);
l3.setBounds(120,10,40,20);
tf3.setBounds(160,10,20,20);
l4.setBounds(190,10,60,20);
tf4.setBounds(250,10,20,20);
bt.setBounds(300,10,80,20);
dp.setBounds(20,40,x*w,y*w);
setResizable(false);
setSize(x*w+40,y*w+80);
setTitle(" 扫雷");
show();
bt.addActionListener(this);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{System.exit(0);}
}
);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == bt)
{
//x = Integer.parseInt(tf1.getText());
//y = Integer.parseInt(tf2.getText());
//w = Integer.parseInt(tf3.getText());
sum = Integer.parseInt(tf4.getText());
setSize(x*w+40,y*w+80);
dp.setBounds(20,40,x*w,y*w);
show();
dp.initMin(x,y,w,sum);
}
}
public static void main(String args[])
{
new Mine();
}
};

⑨ C语言扫雷游戏源代码

"扫雷"小游戏C代码

#include<stdio.h>
#include<math.h>
#include<time.h>
#include<stdlib.h>
main( )
{char a[102][102],b[102][102],c[102][102],w;
int i,j; /*循环变量*/
int x,y,z[999]; /*雷的位置*/
int t,s; /*标记*/
int m,n,lei; /*计数*/
int u,v; /*输入*/
int hang,lie,ge,mo; /*自定义变量*/
srand((int)time(NULL)); /*启动随机数发生器*/
leb1: /*选择模式*/
printf(" 请选择模式: 1.标准 2.自定义 ");
scanf("%d",&mo);
if(mo==2) /*若选择自定义模式,要输入三个参数*/
{do
{t=0; printf("请输入 行数 列数 雷的个数 ");
scanf("%d%d%d",&hang,&lie,&ge);
if(hang<2){printf("行数太少 "); t=1;}
if(hang>100){printf("行数太多 ");t=1;}
if(lie<2){printf("列数太少 ");t=1;}
if(lie>100){printf("列数太多 ");t=1;}
if(ge<1){printf("至少要有一个雷 ");t=1;}
if(ge>=(hang*lie)){printf("雷太多了 ");t=1;}
}while(t==1);
}
else{hang=10,lie=10,ge=10;} /*否则就是选择了标准模式(默认参数)*/
for(i=1;i<=ge;i=i+1) /*确定雷的位置*/
{do
{t=0; z[i]=rand( )%(hang*lie);
for(j=1;j<i;j=j+1){if(z[i]==z[j]) t=1;}
}while(t==1);
}
for(i=0;i<=hang+1;i=i+1) /*初始化a,b,c*/
{for(j=0;j<=lie+1;j=j+1) {a[i][j]='1'; b[i][j]='1'; c[i][j]='0';} }
for(i=1;i<=hang;i=i+1)
{for(j=1;j<=lie;j=j+1) {a[i][j]='+';} }
for(i=1;i<=ge;i=i+1) /*把雷放入c*/
{x=z[i]/lie+1; y=z[i]%lie+1; c[x][y]='#';}
for(i=1;i<=hang;i=i+1) /*计算b中数字*/
{for(j=1;j<=lie;j=j+1)
{m=48;
if(c[i-1][j-1]=='#')m=m+1; if(c[i][j-1]=='#')m=m+1;
if(c[i-1][j]=='#')m=m+1; if(c[i+1][j+1]=='#')m=m+1;
if(c[i][j+1]=='#')m=m+1; if(c[i+1][j]=='#')m=m+1;
if(c[i+1][j-1]=='#')m=m+1; if(c[i-1][j+1]=='#')m=m+1;
b[i][j]=m;
}
}
for(i=1;i<=ge;i=i+1) /*把雷放入b中*/
{x=z[i]/lie+1; y=z[i]%lie+1; b[x][y]='#';}

lei=ge; /*以下是游戏设计*/
do
{leb2: /*输出*/
system("cls");printf(" ");

printf(" ");
for(i=1;i<=lie;i=i+1)
{w=(i-1)/10+48; printf("%c",w);
w=(i-1)%10+48; printf("%c ",w);
}
printf(" |");
for(i=1;i<=lie;i=i+1){printf("---|");}
printf(" ");
for(i=1;i<=hang;i=i+1)
{w=(i-1)/10+48; printf("%c",w);
w=(i-1)%10+48; printf("%c |",w);
for(j=1;j<=lie;j=j+1)
{if(a[i][j]=='0')printf(" |");
else printf(" %c |",a[i][j]);
}
if(i==2)printf(" 剩余雷个数");
if(i==3)printf(" %d",lei);
printf(" |");
for(j=1;j<=lie;j=j+1){printf("---|");}
printf(" ");
}

scanf("%d%c%d",&u,&w,&v); /*输入*/
u=u+1,v=v+1;
if(w!='#'&&a[u][v]=='@')
goto leb2;
if(w=='#')
{if(a[u][v]=='+'){a[u][v]='@'; lei=lei-1;}
else if(a[u][v]=='@'){a[u][v]='?'; lei=lei+1;}
else if(a[u][v]=='?'){a[u][v]='+';}
goto leb2;
}
a[u][v]=b[u][v];

leb3: /*打开0区*/
t=0;
if(a[u][v]=='0')
{for(i=1;i<=hang;i=i+1)
{for(j=1;j<=lie;j=j+1)
{s=0;
if(a[i-1][j-1]=='0')s=1; if(a[i-1][j+1]=='0')s=1;
if(a[i-1][j]=='0')s=1; if(a[i+1][j-1]=='0')s=1;
if(a[i+1][j+1]=='0')s=1; if(a[i+1][j]=='0')s=1;
if(a[i][j-1]=='0')s=1; if(a[i][j+1]=='0')s=1;
if(s==1)a[i][j]=b[i][j];
}
}
for(i=1;i<=hang;i=i+1)
{for(j=lie;j>=1;j=j-1)
{s=0;
if(a[i-1][j-1]=='0')s=1; if(a[i-1][j+1]=='0')s=1;
if(a[i-1][j]=='0')s=1; if(a[i+1][j-1]=='0')s=1;
if(a[i+1][j+1]=='0')s=1; if(a[i+1][j]=='0')s=1;
if(a[i][j-1]=='0')s=1; if(a[i][j+1]=='0')s=1;
if(s==1)a[i][j]=b[i][j];
}
}
for(i=hang;i>=1;i=i-1)
{for(j=1;j<=lie;j=j+1)
{s=0;
if(a[i-1][j-1]=='0')s=1; if(a[i-1][j+1]=='0')s=1;
if(a[i-1][j]=='0')s=1; if(a[i+1][j-1]=='0')s=1;
if(a[i+1][j+1]=='0')s=1; if(a[i+1][j]=='0')s=1;
if(a[i][j-1]=='0')s=1; if(a[i][j+1]=='0')s=1;
if(s==1)a[i][j]=b[i][j];
}
}
for(i=hang;i>=1;i=i-1)
{for(j=lie;j>=1;j=j-1)
{s=0;
if(a[i-1][j-1]=='0')s=1; if(a[i-1][j+1]=='0')s=1;
if(a[i-1][j]=='0')s=1; if(a[i+1][j-1]=='0')s=1;
if(a[i+1][j+1]=='0')s=1;if(a[i+1][j]=='0')s=1;
if(a[i][j-1]=='0')s=1; if(a[i][j+1]=='0')s=1;
if(s==1)a[i][j]=b[i][j];
}
}

for(i=1;i<=hang;i=i+1) /*检测0区*/
{for(j=1;j<=lie;j=j+1)
{if(a[i][j]=='0')
{if(a[i-1][j-1]=='+'||a[i-1][j-1]=='@'||a[i-1][j-1]=='?')t=1;
if(a[i-1][j+1]=='+'||a[i-1][j+1]=='@'||a[i-1][j+1]=='?')t=1;
if(a[i+1][j-1]=='+'||a[i+1][j-1]=='@'||a[i+1][j-1]=='?')t=1;
if(a[i+1][j+1]=='+'||a[i+1][j+1]=='@'||a[i+1][j+1]=='?')t=1;
if(a[i+1][j]=='+'||a[i+1][j]=='@'||a[i+1][j]=='?')t=1;
if(a[i][j+1]=='+'||a[i][j+1]=='@'||a[i][j+1]=='?')t=1;
if(a[i][j-1]=='+'||a[i][j-1]=='@'||a[i][j-1]=='?')t=1;
if(a[i-1][j]=='+'||a[i-1][j]=='@'||a[i-1][j]=='?')t=1;
}
}
}
if(t==1)goto leb3;
}

n=0; /*检查结束*/
for(i=1;i<=hang;i=i+1)
{for(j=1;j<=lie;j=j+1)
{if(a[i][j]!='+'&&a[i][j]!='@'&&a[i][j]!='?')n=n+1;}
}
}
while(a[u][v]!='#'&&n!=(hang*lie-ge));

for(i=1;i<=ge;i=i+1) /*游戏结束*/
{x=z[i]/lie+1; y=z[i]%lie+1; a[x][y]='#'; }
printf(" ");
for(i=1;i<=lie;i=i+1)
{w=(i-1)/10+48; printf("%c",w);
w=(i-1)%10+48; printf("%c ",w);
}
printf(" |");
for(i=1;i<=lie;i=i+1){printf("---|");}
printf(" ");
for(i=1;i<=hang;i=i+1)
{w=(i-1)/10+48; printf("%c",w);
w=(i-1)%10+48; printf("%c |",w);
for(j=1;j<=lie;j=j+1)
{if(a[i][j]=='0')printf(" |");
else printf(" %c |",a[i][j]);
}
if(i==2)printf(" 剩余雷个数");
if(i==3)printf(" %d",lei); printf(" |");
for(j=1;j<=lie;j=j+1) {printf("---|");}
printf(" ");
}
if(n==(hang*lie-ge)) printf("你成功了! ");
else printf(" 游戏结束! ");
printf(" 重玩请输入1 ");
t=0;
scanf("%d",&t);
if(t==1)goto leb1;
}

/*注:在DEV c++上运行通过。行号和列号都从0开始,比如要确定第0行第9列不是“雷”,就在0和9中间加入一个字母,可以输入【0a9】三个字符再按回车键。3行7列不是雷,则输入【3a7】回车;第8行第5列是雷,就输入【8#5】回车,9行0列是雷则输入【9#0】并回车*/

热点内容
存储系统集成 发布:2024-11-14 11:14:54 浏览:584
云服务器搭建方法图解 发布:2024-11-14 11:14:53 浏览:309
挑战服务器吃鸡是什么 发布:2024-11-14 10:59:07 浏览:932
自缴社保算法 发布:2024-11-14 10:43:53 浏览:554
长安科尚哪个配置有电动滑门 发布:2024-11-14 10:37:10 浏览:198
随机策略算法 发布:2024-11-14 10:37:10 浏览:796
办公室电脑可以改无盘服务器吗 发布:2024-11-14 10:32:28 浏览:864
phpurl加密解密 发布:2024-11-14 10:27:38 浏览:334
什么是ewp服务器 发布:2024-11-14 10:27:33 浏览:200
16k存储器的地址范围 发布:2024-11-14 10:26:02 浏览:140