请教算法

lzf83616 2004-04-08 07:37:03
扫雷游戏的实现
...全文
45 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
daisy8675 2004-04-24
  • 打赏
  • 举报
回复
掃雷遊戲,已經有人做出來了,隻不過,偶不玩
lzf83616 2004-04-24
  • 打赏
  • 举报
回复
谢谢了
KiteGirl 2004-04-09
  • 打赏
  • 举报
回复
不好意思!我回复错了!非常抱歉!

计算X,Y点雷数的算法:

<如果当前点是雷,则爆炸……>

For XIndex=X-1 To X+1
For YIndex=Y-1 To Y+1
MCount=MCount+(有雷判断(X,Y) And 1)
Next
Nexy
pigpag 2004-04-09
  • 打赏
  • 举报
回复
应该不难的
KiteGirl 2004-04-09
  • 打赏
  • 举报
回复
羊圈里有100只小羊羔依照编号排成一排。小仙妹想把它们一只只抓出来。但被抓的小羊羔不听话向后躲,因此小仙妹抓出的不一定是哪只小羊羔。被捉出一只小羊羔,羊圈里就少了一只。下面就是模拟这个过程的“小仙妹张牙舞爪捉羊羔算法”,简称“捉羊羔算法”。

Private priFold() As Long '羊圈

Private Sub Command1_Click()
If CBool(SheepCount(priFold())) Then '如果羊圈里还有羊的话
Text2.Text = SheepNabByFold(priFold()) '羊圈存栏数量
Text1.Text = SheepCount(priFold()) '被抓住的小羊羔编号
For tIndex = 0 To SheepCount(priFold()) - 1 '显示羊圈里的小羊。
Text1.Text = Text1.Text & " " & priFold(tIndex)
Next
Else
Text1.Text = "没有羊了!你还乱抓什么?"
End If
End Sub

Private Sub Form_Load()
Randomize Timer
ReDim priFold(100)
For tIndex = 0 To 100
priFold(tIndex) = tIndex
Next
End Sub

Function SheepCount(ByRef pFold() As Long) As Long
Dim tOutCount As Long

Dim tSheepIndex_Start As Long
Dim tSheepIndex_End As Long
Dim tSheepIndex_Rnd As Long

Err.Clear
On Error Resume Next

tSheepIndex_End = UBound(pFold): tSheepIndex_Start = LBound(pFold)
If Not CBool(Err.Number) Then
tOutCount = Abs(tSheepIndex_End - tSheepIndex_Start) + 1
End If

SheepCount = tOutCount
End Function

Function SheepNabByFold(ByRef pFold() As Long) As Long
Dim tOutSheep As Long
Dim tSheepIndex As Long
Dim tSheepCount As Long
Dim tSheepIndex_Start As Long
Dim tSheepIndex_End As Long
Dim tSheepIndex_Rnd As Long
Dim tFoldSpace() As Long

tSheepIndex_End = UBound(pFold()): tSheepIndex_Start = LBound(pFold())
tSheepCount = SheepCount(pFold()) '计算当前数组编号。
tSheepIndex_Rnd = Int(Rnd * tSheepCount) + tSheepIndex_Start
'取合法随机编号。

SheepSwap pFold(tSheepIndex_End), pFold(tSheepIndex_Rnd)
'将末尾的元素与第随机个元素交换(注意,随机元素必须在目前存在的编号范围内)。

tOutSheep = pFold(tSheepIndex_End)

If tSheepCount < 2 Then
pFold() = tFoldSpace()
Else
ReDim Preserve pFold(tSheepIndex_End - 1) '缩小数组,保留数值。
End If

SheepNabByFold = tOutSheep
End Function

Sub SheepSwap(ByRef pSheepA As Long, ByRef pSheepB As Long)
Dim tSheep As Long
tSheep = pSheepA: pSheepA = pSheepB: pSheepB = tSheep
End Sub
lzf83616 2004-04-09
  • 打赏
  • 举报
回复
看似简单其实不然,想法正确,但作起来不那么简单
pigpag 2004-04-08
  • 打赏
  • 举报
回复
恩,就是这样,不是什么复杂的算法
supergreenbean 2004-04-08
  • 打赏
  • 举报
回复
一个N x N的数组,数组元素为一个结构,结构里保存着是否有雷,当前状态等信息.
然后程序初始时随机设置数组元素的有雷属性.鼠标点击后设置数组元素当前状态属性,再判断周遭8个区域内的数组元素属性,然后计算出应该显示的雷数......
daisy8675 2004-04-08
  • 打赏
  • 举报
回复
不玩遊戲.

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧