前端之家收集整理的这篇文章主要介绍了
数值模拟,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Public getTili As Boolean
Public buyTili As Boolean
Public cishu As Integer
Public dengji As Integer
Public tili As Integer
Public jingyan As Integer
Public zijin As Long
Public tianshu As Integer
Private Sub Check1_Click()
If Check1.Value = 1 Then
'MsgBox "被选择"
getTili = True
Else
'MsgBox "未被选择"
getTili = False
End If
End Sub
Private Sub Check2_Click()
If Check2.Value = 1 Then
'MsgBox "被选择"
buyTili = True
Else
'MsgBox "未被选择"
buyTili = False
End If
End Sub
Private Sub readButton_Click()
FileNumber = FreeFile
Open "player.txt" For Input As #FileNumber
Do While Not EOF(FileNumber)
Line Input #FileNumber,TextLine
temp = temp + TextLine + vbCrLf
showTxt.Text = temp
Loop
Close #FileNumber
Set re = New RegExp
re.Pattern = "等级:(\d+).*\n当前经验:(\d+).*\n当前体力:(\d+).*\n资金:(\d+).*\n可购买体力次数:(\d+)"
If (re.Test(temp) = True) Then
Set re1 = re.Execute(temp)(0)
cishu = re1.SubMatches(4)
dengji = re1.SubMatches(0)
tili = re1.SubMatches(2)
jingyan = re1.SubMatches(1)
zijin = re1.SubMatches(3)
showMsg
Else
MsgBox "文件错误"
End If
End Sub
Public Sub shuaFB()
Debug.Print "刷副本"
tili = tili - 6
zj = 610 + 10 * Int(dengji / 5)
zijin = zijin + zj
Debug.Print "获得资金:" & zj
jingyan = jingyan + 6
End Sub
Public Sub suanLevel()
Dim a,b As Integer
Set re = New RegExp
re.Pattern = "(\d+)\t(\d+)"
FileNumber = FreeFile
Open "level.txt" For Input As #FileNumber
Do While Not EOF(FileNumber)
Line Input #FileNumber,TextLine
If re.Test(TextLine) = True Then
Set re1 = re.Execute(TextLine)(0)
a = re1.SubMatches(0)
b = re1.SubMatches(1)
If a = dengji And b > jingyan Then
Close #FileNumber
Exit Sub
End If
If a = dengji And b <= jingyan Then
Debug.Print "Level UP"
dengji = dengji + 1
jingyan = jingyan - b
max_tili = dengji + 59
tili = tili + 20
End If
End If
Loop
'Close #FileNumber
End Sub
Public Sub showMsg()
levelTxt(0).Text = dengji
jingyanTxt(2).Text = jingyan
tiliTxt(1).Text = tili
moneyTxt(3).Text = zijin
End Sub
Private Sub runButton_Click()
If (Text1.Text = "") Then
MsgBox "请输入天数"
Else
tianshu = Text1.Text
End If
FileNumber = FreeFile
Open "Log.txt" For Output As #FileNumber
For i = 1 To tianshu
Print #FileNumber,"==== 第" + Str(i) + "天 ===="
temp = temp + "第" + Str(i) + "天:" + vbCrLf
tili = dengji + 59
getTili = True
buyTili = True
n = 0
While tili >= 6
Print #FileNumber,"角色等级:" + Str(dengji) + " 角色体力:" + Str(tili) + " 当前资金:" + Str(zijin)
shuaFB
n = n + 1
suanLevel
If tili < 6 And Check1.Value = 1 And getTili = True Then
tili = tili + 120
getTili = False
Print #FileNumber,"领取免费体力120点"
End If
If tili < 6 And Check2.Value = 1 And buyTili = True Then
tl = 120 * cishu
tili = tili + tl
buyTili = False
Print #FileNumber,"购买体力" + Str(tl) + "点"
End If
Wend
Print #FileNumber,"通关主线次数:" + Str(n)
temp = temp + "当前等级:" + Str(dengji) + " 当前资金:" + Str(zijin) + vbCrLf
temp = temp + "通关主线次数:" + Str(n) + vbCrLf
Next i
showTxt.Text = temp
Print #FileNumber,"角色等级:" + Str(dengji) + " 当前资金:" + Str(zijin)
Close #FileNumber
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then
Exit Sub
End If
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
KeyAscii = 0
MsgBox "只能输入数字"
End If
End Sub
原文链接:https://www.f2er.com/vb/257791.html