當前位置:首頁 » 編程軟體 » 掃雷編程格式

掃雷編程格式

發布時間: 2022-04-25 21:36:56

1. 掃雷程序用c語言怎樣寫(附源代碼注釋)

LS寫的不錯.這里提一句,掃雷的規則是,你第一次點擊不會踩雷的。也就是在第一次點擊的時候,會把除了當前點擊位置的其餘所有格子隨機填充雷。第一次永遠不會踩雷。不信調到最密的時候試下。:)

2. 用VB編程實現掃雷的思路

'一個簡單掃雷游戲
Option Explicit
Dim Map() As Integer
Dim Row_Num, Col_Num As Integer '范圍,一個正方形的邊長
Dim Ant_Num As Long '白蟻數量
Const x0 = 30 '方框左上角坐標
Const y0 = 30
Const 小快寬度 = 9
Dim a As Integer '各個小塊的邊長

Private Sub Command1_Click()
'重設按鈕
Init_Form
End Sub

Private Sub Form_Load()
Init_Form
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim x1 As Integer, y1 As Integer
x1 = Fix((x - x0) / a): y1 = Fix((y - y0) / a)
If (x - x0) > ((Col_Num + 1) * a) Or (y - y0) > ((Col_Num + 1) * a) Then Exit Sub
If x < x0 Or y < y0 Then Exit Sub
If x < x0 + x1 * a + 2 Or _
x > x0 + x1 * a + a - 4 Or _
y < y0 + y1 * a + 2 Or _
y > y0 + y1 * a + a - 4 _
Then Exit Sub
If Button = 1 Then
If Map(x1, y1) = 0 Then
Call fan(x1, y1)
ElseIf Map(x1, y1) = 1 Then
Call lose
End If
ElseIf Button = 2 Then
Call draw_flg(x1, y1)
End If
Dim n As Integer
n = 0
Dim i As Integer, j As Integer
For i = 0 To Col_Num
For j = 0 To Row_Num
If Map(i, j) = -2 Then n = n + 1
Next j
Next i
If n = (Col_Num + 1) * (Row_Num + 1) - Ant_Num Then
Beep
CurrentX = (Col_Num / 2) * a + x0
CurrentY = (Row_Num / 2) * a + y0
Call sub1
a = Form1.FontSize
Form1.FontSize = 80
'Form1.ForeColor = vbBlack
Print "you win"
Form1.FontSize = a
End If
End Sub

Sub fan(x As Integer, y As Integer)
Dim i As Integer, j As Integer
Dim n As Integer
For i = -1 To 1
For j = -1 To 1
If j * i = 0 And Map(x + i, y + j) = 0 Then
Map(x + i, y + j) = -2
n = Counts(x + i, y + j)
Form1.Line (x0 + (i + x) * a + 2, y0 + (j + y) * a + 2)-Step(a - 4, a - 4), Form1.BackColor, BF

If n <> 0 Then
CurrentX = (x + i) * a + 2 + x0
CurrentY = (y + j) * a + 2 + y0
Select Case n
Case Is = 1
Form1.ForeColor = vbWhite
Case Is = 2
Form1.ForeColor = vbYellow
Case Is > 2
Form1.ForeColor = vbRed
End Select
Print n
ElseIf n = 0 Then

Call fan(x + i, y + j)
End If
End If
Next j
Next i
End Sub

Function Counts(x As Integer, y As Integer) As Integer
Dim i As Integer, j As Integer
For i = -1 To 1
For j = -1 To 1
If Map(x + i, y + j) = 1 Then Counts = Counts + 1
Next
Next
End Function
Sub lose()
Dim i As Integer, j As Integer
For i = 0 To Row_Num
For j = 0 To Col_Num
If Map(j, i) = 1 Then
Form1.FillColor = vbBlack
Form1.FillStyle = 0
Form1.Circle (x0 + j * a + a / 2, y0 + i * a + a / 2), a / 3, vbBlack, , , 0.8
Form1.Line (x0 + j * a, y0 + i * a)-Step(a, a), vbWhite
Form1.Line (x0 + j * a + a, y0 + i * a)-Step(-a, a), vbWhite

ElseIf Map(j, i) = 0 Then
Form1.Line (x0 + j * a + 2, y0 + i * a + 2)-Step(a - 4, a - 4), Form1.BackColor, BF
CurrentX = j * a + x0
CurrentY = i * a + y0
Print Counts(j, i)
End If
Next j

Next i
Beep
a = Form1.FontSize
Form1.FontSize = 80
'Form1.ForeColor = vbBlack
Print "you lose"
Form1.FontSize = a
End Sub
Sub draw_flg(x As Integer, y As Integer)
CurrentX = x * a + x0 + 2
CurrentY = y * a + y0 + 2
Print "?"
End Sub

Public Sub Init_Form()

Form1.Cls
Form1.ScaleMode = 3
Form1.Width = 8000
Form1.Height = 6000
Form1.BackColor = vbGreen
Form1.AutoRedraw = True
Form1.Caption = "一個簡單掃雷游戲 作者 zfc"
Col_Num = 10 '獲取列數
Row_Num = 10 '獲取行數
a = 20 '單元寬(高)度
Ant_Num = 40 '雷的數量
ReDim Map(-1 To Col_Num + 1, -1 To Row_Num + 1)
Dim i As Integer, j As Integer
For i = -1 To Row_Num + 1

For j = -1 To Col_Num + 1
Form1.Line (x0 + j * a, y0 + i * a)-Step(a, a), 0, B
Form1.Line (x0 + j * a + 2, y0 + i * a + 2)-Step(a - 4, a - 4), vbRed, BF
Map(j, i) = 0 '初始化位置標記為空格0
If i = -1 Or i = Row_Num + 1 Or j = -1 Or j = Row_Num + 1 Then
Form1.Line (x0 + j * a + 1, y0 + i * a + 1)-Step(a - 2, a - 2), RGB(100, 120, 100), BF '畫四周牆體
Map(j, i) = -1 '四周位置標記為牆體:-1
End If
Next j

Next i
Dim x As Integer, y As Integer
For i = 1 To Ant_Num
1000
Randomize
x = Rnd * Col_Num
y = Rnd * Row_Num
DoEvents
If Map(x, y) <> 0 Then GoTo 1000
Map(x, y) = 1
Next
End Sub

Sub sub1()

Dim i As Integer, j As Integer
For i = 0 To Row_Num
For j = 0 To Col_Num
If Map(j, i) = 1 Then
Form1.FillColor = vbBlack
Form1.FillStyle = 0
Form1.Circle (x0 + j * a + a / 2, y0 + i * a + a / 2), a / 3, vbBlack, , , 0.8
ElseIf Map(j, i) = 0 Then
Form1.Line (x0 + j * a + 2, y0 + i * a + 2)-Step(a - 4, a - 4), Form1.BackColor, BF
CurrentX = j * a + x0
CurrentY = i * a + y0
Print Counts(j, i)
End If
Next j

Next i
End Sub

3. 小白現在求一個掃雷最簡單的編程程序

我不懂IT但是可以告訴你掃雷是怎麼進行的。希望可以幫助你計算
掃雷就是九宮格粘貼復制,給你講下九宮格吧
PS:請在閱讀的時候點擊下面的【展開閱讀】才能看到完整的我舉的例子要不然你看不懂。
1、任意一個小格子點開,掃雷上就出現一些數字
2、選擇其中一個數字為九宮格的中間數字,九宮格就是把一個正方形分成九個小正方形,我們選擇一個為中間的小正方 形上的數字,這個數字代表了它所在的中間存在的雷數,不方便畫圖我就用數字給你排一下,例如
X X 1
X 3 2
1 1 1
3是中間數,X代表未知的。
3說明它周圍的八個數字【上三個,下三個,左右一個,正好成為一個大正方形】里有三個雷,數字肯定不是雷,那麼三個X就表示都是雷就不能點了哦!
3,以此類推。
我們還是以上面為例,把2作為中間數,說明2的周圍八個數里有2個雷,2的左邊3位置肯定不是雷,3個1也不是雷,左上角X位置,在上一題中已經確定是雷,那麼2的右邊3個數里肯定有一個雷,至於是哪一個是雷,要根據你點出來的一大片數字計算。!
再來一題,我們以三個1的這排中間的這個1為中間數,1表示它周圍的八個數字里只有一個雷。左上角X在上面兩題已經確認是雷,所以它周圍剩下的三個都是數字,不會有雷可以放心點!
——蘇蘇原創,不盡完美,只希望能幫助需要幫助的人,喜歡就採納吧ヾ(=・ω・=)o——
——(o゜▽゜)o☆縮略小圖壓縮畫質有點差,但是點擊大圖查看或者右鍵另存為畫質就恢復清晰啦,設計不易給個採納吧親!o(*^@^*)o——

4. 掃雷編程

事實上Win的原版掃雷是點擊第一次之後再隨機布置的.而且按合理性來說理應如此.但是不排除其他的掃雷游戲會一開始就確定局勢.

5. 如何用C語言編程 掃雷!~

C語言模擬掃雷的代碼如下:

#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int map[9][9] = {0};
int result[9][9] = {0};
int mine[10][2];

bool Check(int i)
{
int j;
for(j=0;j<i;j++)
if(mine[j][0] == mine[i][0] && mine[j][1] == mine[i][0]) return true;
return false;
}

int MineNum(int x,int y) //這個函數計算坐標(x,y)周圍地雷的數目
{
int sum = 0;
int i,j;
if(x-1>=0 && x+1<=8 && y-1>=0 && y+1<=8)
{//中間位置
for(i=x-1;i<=x+1;i++)
for(j=y-1;j<=y+1;j++) sum += map[i][j];
return (sum-map[x][y])/9;
}
if(x==0 && y==0) return (map[0][1]+map[1][0]+map[1][1])/9; //左上角
if(x==0 && y==8) return (map[0][7]+map[1][7]+map[1][8])/9; //右上角
if(x==8 && y==0) return (map[7][0]+map[7][1]+map[8][1])/9; //左下角
if(x==8 && y==8) return (map[7][7]+map[7][8]+map[8][7])/9; //右上角
if(x==0)
{//上邊界
for(i=x;i<=x+1;i++)
for(j=y-1;j<=y+1;j++) sum += map[i][j];
return (sum-map[x][y])/9;
}
if(x==8)
{//下邊界
for(i=x-1;i<=x;i++)
for(j=y-1;j<=y+1;j++) sum += map[i][j];
return (sum-map[x][y])/9;
}
if(y==0)
{//左邊界
for(i=x-1;i<=x+1;i++)
for(j=y;j<=y+1;j++) sum += map[i][j];
return (sum-map[x][y])/9;
}
if(y==8)
{//右邊界
for(i=x-1;i<=x+1;i++)
for(j=y-1;j<=y;j++) sum += map[i][j];
return (sum-map[x][y])/9;
}
}

void main()
{
int i,j,x,y;
srand((int)time(0));
for(i=0;i<10;i++)
{
do{
mine[i][0] = rand()%9;
mine[i][1] = rand()%9;
}while(Check(i));
printf("%d\t%d\n",mine[i][0],mine[i][1]);
}

//標識地雷
for(i=0;i<10;i++) map[mine[i][0]][mine[i][1]] = 9;

//計算地雷的數目
for(i=0;i<9;i++)
{
for(j=0;j<9;j++)
{
if(map[i][j] == 9) result[i][j] = 9;
else result[i][j] = MineNum(i,j);
printf("%d ",result[i][j]);
}
printf("\n");
}
}

6. 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)
x++;
if(num[8][8]==10)
x++;
}
else if(j==0)
{
if(num[i][j+1]==10)
x++;
if(num[i+1][j]==10)
x++;
if(num[i-1][j]==10)
x++;
if(num[i-1][j+1]==10)
x++;
if(num[i+1][j+1]==10)
x++;
}
else if(j==9)
{
if(num[i][j-1]==10)
x++;
if(num[i+1][j]==10)
x++;
if(num[i-1][j]==10)
x++;
if(num[i-1][j-1]==10)
x++;
if(num[i+1][j-1]==10)
x++;
}
else if(i==0)
{
if(num[i+1][j]==10)
x++;
if(num[i][j-1]==10)
x++;
if(num[i][j+1]==10)
x++;
if(num[i+1][j-1]==10)
x++;
if(num[i+1][j+1]==10)
x++;
}
else if(i==9)
{
if(num[i-1][j]==10)
x++;
if(num[i][j-1]==10)
x++;
if(num[i][j+1]==10)
x++;
if(num[i-1][j-1]==10)
x++;
if(num[i-1][j+1]==10)
x++;
}
else
{
if(num[i-1][j]==10)
x++;
if(num[i-1][j+1]==10)
x++;
if(num[i][j+1]==10)
x++;
if(num[i+1][j+1]==10)
x++;
if(num[i+1][j]==10)
x++;
if(num[i+1][j-1]==10)
x++;
if(num[i][j-1]==10)
x++;
if(num[i-1][j-1]==10)
x++;
}
return(x);
}
funcheck(int i,int j)/*開始找無雷*/
{
scorenum--;
if(p[i][j]==0&&num[i][j]!=10)
{
setfillstyle(SOLID_FILL,7);/*顯示無雷區*/
bar(200+j*20-7,100+i*20-7,200+j*20+7,100+i*20+7);
num[i][j]=-1;
}
else if(p[i][j]!=0)
{
sprintf(score,"%d",p[i][j]);/*輸出雷數*/
setcolor(RED);
outtextxy(195+j*20,95+i*20,score);
num[i][j]=-1;
return ;
}
if(i!=0&&num[i-1][j]!=-1&&num[i-1][j]!=10)/*第歸開始*/
funcheck(i-1,j);
if(i!=0&&j!=9&&num[i-1][j+1]!=-1&&num[i-1][j+1]!=10)
funcheck(i-1,j+1);
if(j!=9&&num[i][j+1]!=-1&&num[i][j+1]!=10)
funcheck(i,j+1);
if(j!=9&&i!=9&&num[i+1][j+1]!=-1&&num[i+1][j+1]!=10)
funcheck(i+1,j+1);
if(i!=9&&num[i+1][j]!=-1&&num[i+1][j]!=10)
funcheck(i+1,j);
if(i!=9&&j!=0&&num[i+1][j-1]!=-1&&num[i+1][j-1]!=10)
funcheck(i+1,j-1);
if(j!=0&&num[i][j-1]!=-1&&num[i][j-1]!=10)
funcheck(i,j-1);
if(i!=0&&j!=0&&num[i-1][j-1]!=-1&&num[i-1][j-1]!=10)
funcheck(i-1,j-1);
}

playgame()/*游戲過程*/
{int i,j,numx;
for(i=0;i<10;i++)
for(j=0;j<10;j++)
p[i][j]=tongji(i,j);/*把標記有幾個雷的數字都存放起來*/
while(!kbhit())
{
if(LeftPress())/*左鍵盤按下*/
{
MouseGetXY();
if(MouseX>280&&MouseX<300&&MouseY>65&&MouseY<85)/*重新來*/
{
MouseOff();
again=1;
break;
}
if(MouseX>190&&MouseX<390&&MouseY>90&&MouseY<290)/*是否在游戲范圍內*/
{
j=(MouseX-190)/20;/*x坐標*/
i=(MouseY-90)/20;/*y坐標*/
if(num[i][j]!=-1)
{
if(num[i][j]==10)/*中雷*/
{
MouseOff();
gameove();/*失敗*/
break;
}
else/*非中雷*/
{
MouseOff();
numx=tongji(i,j);
if(numx==0)/*周圍沒地雷*/
funcheck(i,j);/*開始找無雷*/
else/*有地雷*/
{
sprintf(score,"%d",numx);/*輸出雷數*/
setcolor(RED);
outtextxy(195+j*20,95+i*20,score);
scorenum--;
}
MouseOn();
num[i][j]=-1;
if(scorenum<1)/*勝利了*/
{
setcolor(11);
settextstyle(0,0,2);
outtextxy(230,30,"YOU WIN!");
break;
}
}
}
}
}
}
}
main()
{int gd=DETECT,gr;
registerbgidriver(EGAVGA_driver);
initgraph(&gd,&gr,"c:\\tc");
loop: begain();
playgame();/*具體游戲*/
if(again)/*游戲中重新開始*/
{
again=0;
goto loop;
}
MouseOn();
while(!kbhit())/*重新來*/
{
if(LeftPress())
{
MouseGetXY();/*失敗後重新來*/
if(MouseX>280&&MouseX<300&&MouseY>65&&MouseY<85)
goto loop;
}
}
MouseOff();
closegraph();
}

本文來自: 中科軟體園(www.4oa.com) 詳細出處參考:http://www.4oa.com/Article/html/6/31/446/2005/15615.html

7. 關於掃雷程序設計

  1. 可以實現:

    (1) 定義一個雷區結構體,存放當前雷區有無雷,周邊有幾個雷區有雷,用戶標識有雷標志;

    踩開標志;

    (2) 定義一個二維 雷區 數組,描述 雷場;

    (3) 定義二個變數,保存當前 排雷的 區域(行,列);其它變數(計時,計分,計雷數等)根據需要定義;

    (4) 初始化,生成雷場;雷區顯示方式為未排雷;

    (5) 循環

    顯示雷場;

    掃描用戶輸入(用KBHIT);

    如果是游標鍵,改變當前排雷區域;如果是回車鍵,設定當前雷場踩開標志;(無雷->踩開同時周邊無雷區域一並踩開,有雷->結束);如果是空格, 標識有雷或取消標識;

    如果未排開雷區數等於總雷數,游戲結束,顯示用戶成績;

    (6)根據用戶選擇,到(4)重新開始 或退出程序。

  2. 如果用圖形界面,初學者可以VB,想一步到位就用VC;裝個Visual Studio 6 或 2010 就行。

8. C++簡易掃雷程序

c++:

#include<iostream>
#include<fstream>
#include<ctime>
usingnamespacestd;
voidlayout(intn){
char**cs=(char**)malloc(sizeof(char*)*n);
srand((unsigned)time(0));
for(inti=0;i<n;++i){
cs[i]=(char*)malloc(sizeof(char)*n);
for(intj=0;j<n;++j){
intr0=rand()%100;
intr1=rand()%100;
if(r1>=r0&&r1>70){//雷
cs[i][j]='*';
}else{
cs[i][j]='';
}
}
}
//計算雷的個數
for(inti=0;i<n;++i){
for(intj=0;j<n;++j){
if(cs[i][j]=='*')
cout<<""<<cs[i][j];
else{
intcount=0;
for(intk=i-1;k<=i+1;k++){
for(intl=j-1;l<=j+1;l++){
if(k>=0&&l>=0&&k<n&&l<n
&&cs[k][l]=='*'){

count++;
}

}
}
cs[i][j]=(char)('0'+count);
cout<<""<<cs[i][j];
}
}
cout<<endl;
}
}
intmain(){
intn=4;
cout<<"請輸入行數:";
cin>>n;
layout(n);
}

9. 掃雷的VB編程

Private Sub Form_Load()Init_FormEnd Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)Dim x1 As Integer, y1 As Integerx1 = Fix((x - x0) / a): y1 = Fix((y - y0) / a)If (x - x0) > ((Col_Num + 1) * a) Or (y - y0) > ((Col_Num + 1) * a) Then Exit SubIf x < x0 Or y < y0 Then Exit SubIf x < x0 + x1 * a + 2 Or _x > x0 + x1 * a + a - 4 Or _y < y0 + y1 * a + 2 Or _y > y0 + y1 * a + a - 4 _Then Exit SubIf Button = 1 ThenIf Map(x1, y1) = 0 ThenCall fan(x1, y1)ElseIf Map(x1, y1) = 1 ThenCall loseEnd IfElseIf Button = 2 ThenCall draw_flg(x1, y1)End IfDim n As Integern = 0Dim i As Integer, j As IntegerFor i = 0 To Col_NumFor j = 0 To Row_NumIf Map(i, j) = -2 Then n = n + 1Next jNext iIf n = (Col_Num + 1) * (Row_Num + 1) - Ant_Num ThenBeepCurrentX = (Col_Num / 2) * a + x0CurrentY = (Row_Num / 2) * a + y0Call sub1a = Form1.FontSizeForm1.FontSize = 80'Form1.ForeColor = vbBlackPrint "you win"Form1.FontSize = aEnd IfEnd Sub

Sub fan(x As Integer, y As Integer)Dim i As Integer, j As IntegerDim n As IntegerFor i = -1 To 1For j = -1 To 1If j * i = 0 And Map(x + i, y + j) = 0 ThenMap(x + i, y + j) = -2n = Counts(x + i, y + j)Form1.Line (x0 + (i + x) * a + 2, y0 + (j + y) * a + 2)-Step(a - 4, a - 4), Form1.BackColor, BF
If n <> 0 ThenCurrentX = (x + i) * a + 2 + x0CurrentY = (y + j) * a + 2 + y0Select Case nCase Is = 1Form1.ForeColor = vbWhiteCase Is = 2Form1.ForeColor = vbYellowCase Is > 2Form1.ForeColor = vbRedEnd SelectPrint nElseIf n = 0 Then
Call fan(x + i, y + j)End IfEnd IfNext jNext iEnd Sub
Function Counts(x As Integer, y As Integer) As IntegerDim i As Integer, j As IntegerFor i = -1 To 1For j = -1 To 1If Map(x + i, y + j) = 1 Then Counts = Counts + 1NextNextEnd FunctionSub lose()Dim i As Integer, j As IntegerFor i = 0 To Row_NumFor j = 0 To Col_NumIf Map(j, i) = 1 ThenForm1.FillColor = vbBlackForm1.FillStyle = 0Form1.Circle (x0 + j * a + a / 2, y0 + i * a + a / 2), a / 3, vbBlack, , , 0.8Form1.Line (x0 + j * a, y0 + i * a)-Step(a, a), vbWhiteForm1.Line (x0 + j * a + a, y0 + i * a)-Step(-a, a), vbWhite
ElseIf Map(j, i) = 0 ThenForm1.Line (x0 + j * a + 2, y0 + i * a + 2)-Step(a - 4, a - 4), Form1.BackColor, BFCurrentX = j * a + x0CurrentY = i * a + y0Print Counts(j, i)End IfNext j
Next iBeepa = Form1.FontSizeForm1.FontSize = 80'Form1.ForeColor = vbBlackPrint "you lose"Form1.FontSize = aEnd SubSub draw_flg(x As Integer, y As Integer)CurrentX = x * a + x0 + 2CurrentY = y * a + y0 + 2Print "?"End Sub
Public Sub Init_Form()
Form1.ClsForm1.ScaleMode = 3Form1.Width = 8000Form1.Height = 6000Form1.BackColor = vbGreenForm1.AutoRedraw = Trueform1.caption="一個簡單掃雷游戲 "Col_Num = 10 '獲取列數Row_Num = 10 '獲取行數a = 20 '單元寬(高)度Ant_Num = 40 '雷的數量ReDim Map(-1 To Col_Num + 1, -1 To Row_Num + 1)Dim i As Integer, j As IntegerFor i = -1 To Row_Num + 1
For j = -1 To Col_Num + 1Form1.Line (x0 + j * a, y0 + i * a)-Step(a, a), 0, BForm1.Line (x0 + j * a + 2, y0 + i * a + 2)-Step(a - 4, a - 4), vbRed, BFMap(j, i) = 0 '初始化位置標記為空格0If i = -1 Or i = Row_Num + 1 Or j = -1 Or j = Row_Num + 1 ThenForm1.Line (x0 + j * a + 1, y0 + i * a + 1)-Step(a - 2, a - 2), RGB(100, 120, 100), BF '畫四周牆體Map(j, i) = -1 '四周位置標記為牆體:-1End IfNext j
Next iDim x As Integer, y As IntegerFor i = 1 To Ant_Num1000Randomizex = Rnd * Col_Numy = Rnd * Row_NumDoEventsIf Map(x, y) <> 0 Then GoTo 1000Map(x, y) = 1NextEnd Sub

Sub sub1()
Dim i As Integer, j As IntegerFor i = 0 To Row_NumFor j = 0 To Col_NumIf Map(j, i) = 1 ThenForm1.FillColor = vbBlackForm1.FillStyle = 0Form1.Circle (x0 + j * a + a / 2, y0 + i * a + a / 2), a / 3, vbBlack, , , 0.8ElseIf Map(j, i) = 0 ThenForm1.Line (x0 + j * a + 2, y0 + i * a + 2)-Step(a - 4, a - 4), Form1.BackColor, BFCurrentX = j * a + x0CurrentY = i * a + y0Print Counts(j, i)End IfNext j
Next iEnd Sub

熱點內容
scratch少兒編程課程 發布:2025-04-16 17:11:44 瀏覽:617
榮耀x10從哪裡設置密碼 發布:2025-04-16 17:11:43 瀏覽:345
java從入門到精通視頻 發布:2025-04-16 17:11:43 瀏覽:60
php微信介面教程 發布:2025-04-16 17:07:30 瀏覽:287
android實現陰影 發布:2025-04-16 16:50:08 瀏覽:779
粉筆直播課緩存 發布:2025-04-16 16:31:21 瀏覽:330
機頂盒都有什麼配置 發布:2025-04-16 16:24:37 瀏覽:193
編寫手游反編譯都需要學習什麼 發布:2025-04-16 16:19:36 瀏覽:781
proteus編譯文件位置 發布:2025-04-16 16:18:44 瀏覽:346
土壓縮的本質 發布:2025-04-16 16:13:21 瀏覽:574